1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00

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 <sonnygarcia@icloud.com>
This commit is contained in:
Bernhard (Sonny) Köhler
2018-11-16 07:30:10 -05:00
committed by Reinhard Nägele
parent 73f35d7fcb
commit b1c8894732
2 changed files with 57 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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)
}