github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/builder/dockerfile/builder_test.go (about)

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