2017-03-10 17:07:12 -05:00
|
|
|
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",
|
2017-03-13 17:25:37 -04:00
|
|
|
"weird": "first' second",
|
2017-03-10 17:07:12 -05:00
|
|
|
}
|
|
|
|
expected := &Node{
|
|
|
|
Value: "label",
|
2017-03-13 17:25:37 -04:00
|
|
|
Original: `LABEL "foo"='bar' "weird"='first' second'`,
|
2017-03-10 17:07:12 -05:00
|
|
|
Next: &Node{
|
|
|
|
Value: "foo",
|
|
|
|
Next: &Node{
|
2017-03-13 17:25:37 -04:00
|
|
|
Value: "'bar'",
|
2017-03-10 17:07:12 -05:00
|
|
|
Next: &Node{
|
|
|
|
Value: "weird",
|
|
|
|
Next: &Node{
|
2017-03-13 17:25:37 -04:00
|
|
|
Value: "'first' second'",
|
2017-03-10 17:07:12 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
node := NodeFromLabels(labels)
|
|
|
|
assert.DeepEqual(t, node, expected)
|
|
|
|
|
|
|
|
}
|