builder_test.go 757 B

12345678910111213141516171819202122232425262728293031323334
  1. package dockerfile
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/docker/docker/builder/dockerfile/parser"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestAddNodesForLabelOption(t *testing.T) {
  9. dockerfile := "FROM scratch"
  10. result, err := parser.Parse(strings.NewReader(dockerfile))
  11. assert.NoError(t, err)
  12. labels := map[string]string{
  13. "org.e": "cli-e",
  14. "org.d": "cli-d",
  15. "org.c": "cli-c",
  16. "org.b": "cli-b",
  17. "org.a": "cli-a",
  18. }
  19. nodes := result.AST
  20. addNodesForLabelOption(nodes, labels)
  21. expected := []string{
  22. "FROM scratch",
  23. `LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`,
  24. }
  25. assert.Len(t, nodes.Children, 2)
  26. for i, v := range nodes.Children {
  27. assert.Equal(t, expected[i], v.Original)
  28. }
  29. }