|
|
@ -245,44 +245,65 @@ func TestParseErrors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestExecErrors(t *testing.T) {
|
|
|
|
func TestExecErrors(t *testing.T) {
|
|
|
|
vals := chartutil.Values{"Values": map[string]interface{}{}}
|
|
|
|
vals := chartutil.Values{"Values": map[string]interface{}{}}
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
tplsMissingRequired := map[string]renderable{
|
|
|
|
name string
|
|
|
|
|
|
|
|
tpls map[string]renderable
|
|
|
|
|
|
|
|
expected string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "MissingRequired",
|
|
|
|
|
|
|
|
tpls: map[string]renderable{
|
|
|
|
"missing_required": {tpl: `{{required "foo is required" .Values.foo}}`, vals: vals},
|
|
|
|
"missing_required": {tpl: `{{required "foo is required" .Values.foo}}`, vals: vals},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_, err := new(Engine).render(tplsMissingRequired)
|
|
|
|
expected: `execution error at (missing_required:1:2): foo is required`,
|
|
|
|
if err == nil {
|
|
|
|
},
|
|
|
|
t.Fatalf("Expected failures while rendering: %s", err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
name: "MissingRequiredWithColons",
|
|
|
|
expected := `execution error at (missing_required:1:2): foo is required`
|
|
|
|
tpls: map[string]renderable{
|
|
|
|
if err.Error() != expected {
|
|
|
|
|
|
|
|
t.Errorf("Expected '%s', got %q", expected, err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tplsMissingRequired = map[string]renderable{
|
|
|
|
|
|
|
|
"missing_required_with_colons": {tpl: `{{required ":this: message: has many: colons:" .Values.foo}}`, vals: vals},
|
|
|
|
"missing_required_with_colons": {tpl: `{{required ":this: message: has many: colons:" .Values.foo}}`, vals: vals},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_, err = new(Engine).render(tplsMissingRequired)
|
|
|
|
expected: `execution error at (missing_required_with_colons:1:2): :this: message: has many: colons:`,
|
|
|
|
if err == nil {
|
|
|
|
},
|
|
|
|
t.Fatalf("Expected failures while rendering: %s", err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
name: "Issue6044",
|
|
|
|
expected = `execution error at (missing_required_with_colons:1:2): :this: message: has many: colons:`
|
|
|
|
tpls: map[string]renderable{
|
|
|
|
if err.Error() != expected {
|
|
|
|
"issue6044": {
|
|
|
|
t.Errorf("Expected '%s', got %q", expected, err.Error())
|
|
|
|
vals: vals,
|
|
|
|
}
|
|
|
|
tpl: `{{ $someEmptyValue := "" }}
|
|
|
|
|
|
|
|
|
|
|
|
issue6044tpl := `{{ $someEmptyValue := "" }}
|
|
|
|
|
|
|
|
{{ $myvar := "abc" }}
|
|
|
|
{{ $myvar := "abc" }}
|
|
|
|
{{- required (printf "%s: something is missing" $myvar) $someEmptyValue | repeat 0 }}`
|
|
|
|
{{- required (printf "%s: something is missing" $myvar) $someEmptyValue | repeat 0 }}`,
|
|
|
|
tplsMissingRequired = map[string]renderable{
|
|
|
|
},
|
|
|
|
"issue6044": {tpl: issue6044tpl, vals: vals},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `execution error at (issue6044:3:4): abc: something is missing`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "MissingRequiredWithNewlines",
|
|
|
|
|
|
|
|
tpls: map[string]renderable{
|
|
|
|
|
|
|
|
"issue9981": {tpl: `{{required "foo is required\nmore info after the break" .Values.foo}}`, vals: vals},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `execution error at (issue9981:1:2): foo is required
|
|
|
|
|
|
|
|
more info after the break`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "FailWithNewlines",
|
|
|
|
|
|
|
|
tpls: map[string]renderable{
|
|
|
|
|
|
|
|
"issue9981": {tpl: `{{fail "something is wrong\nlinebreak"}}`, vals: vals},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `execution error at (issue9981:1:2): something is wrong
|
|
|
|
|
|
|
|
linebreak`,
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err = new(Engine).render(tplsMissingRequired)
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range cases {
|
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
_, err := new(Engine).render(tt.tpls)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected failures while rendering: %s", err)
|
|
|
|
t.Fatalf("Expected failures while rendering: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expected = `execution error at (issue6044:3:4): abc: something is missing`
|
|
|
|
if err.Error() != tt.expected {
|
|
|
|
if err.Error() != expected {
|
|
|
|
t.Errorf("Expected %q, got %q", tt.expected, err.Error())
|
|
|
|
t.Errorf("Expected '%s', got %q", expected, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|