1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/builder/dockerfile/parser/line_parsers_test.go
Daniel Nephin 726fb269cf Fix --label on docker build when a single quote is used in the value
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2017-03-24 12:29:14 -04:00

65 lines
1.2 KiB
Go

package parser
import (
"github.com/docker/docker/pkg/testutil/assert"
"testing"
)
func TestParseNameValOldFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo bar", "LABEL", &directive)
assert.NilError(t, err)
expected := &Node{
Value: "foo",
Next: &Node{Value: "bar"},
}
assert.DeepEqual(t, node, expected)
}
func TestParseNameValNewFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
assert.NilError(t, err)
expected := &Node{
Value: "foo",
Next: &Node{
Value: "bar",
Next: &Node{
Value: "thing",
Next: &Node{
Value: "star",
},
},
},
}
assert.DeepEqual(t, node, expected)
}
func TestNodeFromLabels(t *testing.T) {
labels := map[string]string{
"foo": "bar",
"weird": "'first second'",
}
expected := &Node{
Value: "label",
Original: `LABEL "foo"='bar' "weird"=''first second''`,
Next: &Node{
Value: "foo",
Next: &Node{
Value: "bar",
Next: &Node{
Value: "weird",
Next: &Node{
Value: "'first second'",
},
},
},
},
}
node := NodeFromLabels(labels)
assert.DeepEqual(t, node, expected)
}