From d1fe406478f1554fba42f0945be1b68d80529e42 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Fri, 24 Jun 2016 12:21:44 -0700 Subject: [PATCH] Adding squote test case and generic message --- pkg/lint/rules/template.go | 4 ++-- pkg/lint/rules/template_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 0f2848efb..47140eba8 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -129,7 +129,7 @@ func validateQuotes(templateName string, templateContent string) (lintError supp for _, str := range functions { if match, _ := regexp.MatchString("quote", str); !match { result := strings.Replace(str, "}}", " | quote }}", -1) - lintError = fmt.Errorf("templates: \"%s\". add \"| quote\" to your substitution functions: %s -> %s", templateName, str, result) + lintError = fmt.Errorf("templates: \"%s\". Wrap your substitution functions in quotes or use the sprig \"quote\" function: %s -> %s", templateName, str, result) return } } @@ -140,7 +140,7 @@ func validateQuotes(templateName string, templateContent string) (lintError supp for _, str := range functions { result := strings.Replace(str, str, fmt.Sprintf("\"%s\"", str), -1) - lintError = fmt.Errorf("templates: \"%s\". wrap your substitution functions in double quotes: %s -> %s", templateName, str, result) + lintError = fmt.Errorf("templates: \"%s\". Wrap your substitution functions in quotes: %s -> %s", templateName, str, result) return } return diff --git a/pkg/lint/rules/template_test.go b/pkg/lint/rules/template_test.go index e4e6e2ce6..8dc7e6dad 100644 --- a/pkg/lint/rules/template_test.go +++ b/pkg/lint/rules/template_test.go @@ -47,12 +47,12 @@ func TestValidateQuotes(t *testing.T) { for _, test := range failTest { err := validateQuotes("testTemplate.yaml", test) - if err == nil || !strings.Contains(err.Error(), "add \"| quote\" to your substitution functions") { - t.Errorf("validateQuotes('%s') to return \"add | quote error\", got no error", test) + if err == nil || !strings.Contains(err.Error(), "use the sprig \"quote\" function") { + t.Errorf("validateQuotes('%s') to return \"use the sprig \"quote\" function:\", got no error.", test) } } - var successTest = []string{"foo: {{.Release.Service | quote }}", "foo: {{.Release.Service | quote }}", "- {{.Release.Service | quote }}", "foo: {{default 'Never' .restart_policy | quote }}", "foo: \"{{ .Release.Service }}\"", "foo: \"{{ .Release.Service }} {{ .Foo.Bar }}\"", "foo: \"{{ default 'Never' .Release.Service }} {{ .Foo.Bar }}\""} + var successTest = []string{"foo: {{.Release.Service | quote }}", "foo: {{.Release.Service | quote }}", "- {{.Release.Service | quote }}", "foo: {{default 'Never' .restart_policy | quote }}", "foo: \"{{ .Release.Service }}\"", "foo: \"{{ .Release.Service }} {{ .Foo.Bar }}\"", "foo: \"{{ default 'Never' .Release.Service }} {{ .Foo.Bar }}\"", "foo: {{.Release.Service | squote }}"} for _, test := range successTest { err := validateQuotes("testTemplate.yaml", test) @@ -66,8 +66,8 @@ func TestValidateQuotes(t *testing.T) { for _, test := range failTest { err := validateQuotes("testTemplate.yaml", test) - if err == nil || !strings.Contains(err.Error(), "wrap your substitution functions in double quotes") { - t.Errorf("validateQuotes('%s') to return \"wrap your substitution functions in double quotes\", got no error %s", test, err.Error()) + if err == nil || !strings.Contains(err.Error(), "Wrap your substitution functions in quotes") { + t.Errorf("validateQuotes('%s') to return \"Wrap your substitution functions in quotes\", got no error", test) } }