Files
docker-cli/components/engine/builder/dockerfile/parser/line_parsers_test.go
T
Daniel Nephin cb1f6242ed Post migration assertion fixes
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit c9e52bd0da0461e605a3678b85702f83081504a7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-04-17 17:29:22 -07:00

78 lines
1.8 KiB
Go

package parser // import "github.com/docker/docker/builder/dockerfile/parser"
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
func TestParseNameValOldFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo bar", "LABEL", &directive)
assert.Check(t, err)
expected := &Node{
Value: "foo",
Next: &Node{Value: "bar"},
}
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
var cmpNodeOpt = cmp.AllowUnexported(Node{})
func TestParseNameValNewFormat(t *testing.T) {
directive := Directive{}
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
assert.Check(t, err)
expected := &Node{
Value: "foo",
Next: &Node{
Value: "bar",
Next: &Node{
Value: "thing",
Next: &Node{
Value: "star",
},
},
},
}
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
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, expected, node, cmpNodeOpt)
}
func TestParseNameValWithoutVal(t *testing.T) {
directive := Directive{}
// In Config.Env, a variable without `=` is removed from the environment. (#31634)
// However, in Dockerfile, we don't allow "unsetting" an environment variable. (#11922)
_, err := parseNameVal("foo", "ENV", &directive)
assert.Check(t, is.ErrorContains(err, ""), "ENV must have two arguments")
}