builder_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dockerfile
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/builder/dockerfile/parser"
  8. "github.com/docker/docker/pkg/testutil/assert"
  9. )
  10. func TestBuildProcessLabels(t *testing.T) {
  11. dockerfile := "FROM scratch"
  12. d := parser.Directive{}
  13. parser.SetEscapeToken(parser.DefaultEscapeToken, &d)
  14. n, err := parser.Parse(strings.NewReader(dockerfile), &d)
  15. assert.NilError(t, err)
  16. options := &types.ImageBuildOptions{
  17. Labels: map[string]string{
  18. "org.e": "cli-e",
  19. "org.d": "cli-d",
  20. "org.c": "cli-c",
  21. "org.b": "cli-b",
  22. "org.a": "cli-a",
  23. },
  24. }
  25. b := &Builder{
  26. runConfig: &container.Config{},
  27. options: options,
  28. directive: d,
  29. dockerfile: n,
  30. }
  31. b.processLabels()
  32. expected := []string{
  33. "FROM scratch",
  34. `LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`,
  35. }
  36. assert.Equal(t, len(b.dockerfile.Children), 2)
  37. for i, v := range b.dockerfile.Children {
  38. assert.Equal(t, v.Original, expected[i])
  39. }
  40. }