diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go new file mode 100644 index 000000000..f5f467395 --- /dev/null +++ b/cmd/helm/lint_test.go @@ -0,0 +1,38 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "fmt" + "testing" +) + +func TestLintCmd(t *testing.T) { + chart := "testdata/testcharts/chart-with-schema-negative" + tests := []cmdTestCase{ + { + name: "check fails without value option flags", + cmd: fmt.Sprintf("lint %s", chart), + wantError: true, + }, + { + name: "check passes with value option flags", + cmd: fmt.Sprintf("lint %s --set age=25,employmentInfo.salary=100000", chart), + }, + } + runTestCmd(t, tests) +} diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index d47951671..d6d59f3ce 100644 --- a/pkg/lint/lint.go +++ b/pkg/lint/lint.go @@ -30,7 +30,7 @@ func All(basedir string, values map[string]interface{}, namespace string, strict linter := support.Linter{ChartDir: chartDir} rules.Chartfile(&linter) - rules.Values(&linter) + rules.Values(&linter, values) rules.Templates(&linter, values, namespace, strict) return linter } diff --git a/pkg/lint/rules/values.go b/pkg/lint/rules/values.go index 0f202f475..80940a43d 100644 --- a/pkg/lint/rules/values.go +++ b/pkg/lint/rules/values.go @@ -28,7 +28,7 @@ import ( ) // Values lints a chart's values.yaml file. -func Values(linter *support.Linter) { +func Values(linter *support.Linter, values map[string]interface{}) { file := "values.yaml" vf := filepath.Join(linter.ChartDir, file) fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf)) @@ -37,7 +37,7 @@ func Values(linter *support.Linter) { return } - linter.RunLinterRule(support.ErrorSev, file, validateValuesFile(vf)) + linter.RunLinterRule(support.ErrorSev, file, validateValues(vf, values)) } func validateValuesFileExistence(valuesPath string) error { @@ -48,8 +48,8 @@ func validateValuesFileExistence(valuesPath string) error { return nil } -func validateValuesFile(valuesPath string) error { - values, err := chartutil.ReadValuesFile(valuesPath) +func validateValues(valuesPath string, values map[string]interface{}) error { + fv, err := chartutil.ReadValuesFile(valuesPath) if err != nil { return errors.Wrap(err, "unable to parse YAML") } @@ -63,5 +63,5 @@ func validateValuesFile(valuesPath string) error { if err != nil { return err } - return chartutil.ValidateAgainstSingleSchema(values, schema) + return chartutil.ValidateAgainstSingleSchema(chartutil.CoalesceTables(values, fv), schema) }