From b1c88947320b7faf39488be468272b8aa8b632b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20=28Sonny=29=20K=C3=B6hler?= Date: Fri, 16 Nov 2018 07:30:10 -0500 Subject: [PATCH] fixes bug inside of LintChart() (#55) ValidateMaintainers() should only be called when the respective config element is set to true. Signed-off-by: Sonny Garcia --- pkg/chart/chart.go | 8 ++++--- pkg/chart/chart_test.go | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index a490cba..0b606b6 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -296,9 +296,11 @@ func (t *Testing) LintChart(chart string, valuesFiles []string) TestResult { return result } - if err := t.ValidateMaintainers(chart); err != nil { - result.Error = err - return result + if t.config.ValidateMaintainers { + if err := t.ValidateMaintainers(chart); err != nil { + result.Error = err + return result + } } if len(valuesFiles) > 0 { diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index a9be042..15954ca 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -94,6 +94,22 @@ func (v fakeAccountValidator) Validate(repoDomain string, account string) error return errors.New(fmt.Sprintf("Error validating account: %s", account)) } +type fakeLinter struct{} + +func (l fakeLinter) YamlLint(yamlFile, configFile string) error { return nil } +func (l fakeLinter) Yamale(yamlFile, schemaFile string) error { return nil } + +type fakeHelm struct{} + +func (h fakeHelm) Init() error { return nil } +func (h fakeHelm) AddRepo(name, url string) error { return nil } +func (h fakeHelm) BuildDependencies(chart string) error { return nil } +func (h fakeHelm) Lint(chart string) error { return nil } +func (h fakeHelm) LintWithValues(chart string, valuesFile string) error { return nil } +func (h fakeHelm) Install(chart string, namespace string, release string) error { return nil } +func (h fakeHelm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error { return nil } +func (h fakeHelm) DeleteRelease(release string) {} + var ct Testing func init() { @@ -107,6 +123,8 @@ func init() { git: fakeGit{}, chartUtils: fakeChartUtils{}, accountValidator: fakeAccountValidator{}, + linter: fakeLinter{}, + helm: fakeHelm{}, } } @@ -145,3 +163,37 @@ func TestValidateMaintainers(t *testing.T) { }) } } + +func TestLintChartMaintainerValidation(t *testing.T) { + type testData struct { + name string + chartDir string + expected bool + } + + runTests := func(validate bool) { + ct.config.ValidateMaintainers = validate + + var suffix string + if validate { + suffix = "with-validation" + } else { + suffix = "without-validation" + } + + testCases := []testData { + {fmt.Sprintf("maintainers-%s", suffix), "testdata/valid_maintainers", true}, + {fmt.Sprintf("no-maintainers-%s", suffix), "testdata/no_maintainers", !validate}, + } + + for _, testData := range testCases { + t.Run(testData.name, func(t *testing.T) { + result := ct.LintChart(testData.chartDir, []string{}) + assert.Equal(t, testData.expected, result.Error == nil) + }) + } + } + + runTests(true) + runTests(false) +}