Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ func (t *Testing) LintChart(chart *Chart) TestResult {
}

if t.config.ValidateYaml {
yamlFiles := append([]string{chartYaml, valuesYaml}, valuesFiles...)
yamlFiles := []string{chartYaml}
// Only include values.yaml if it exists
if _, err := os.Stat(valuesYaml); err == nil {
yamlFiles = append(yamlFiles, valuesYaml)
}
yamlFiles = append(yamlFiles, valuesFiles...)
for _, yamlFile := range yamlFiles {
if err := t.linter.YamlLint(yamlFile, t.config.LintConf); err != nil {
result.Error = err
Expand Down
48 changes: 48 additions & 0 deletions pkg/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,54 @@ func TestLintYamlValidation(t *testing.T) {
runTests(false, 0, 0)
}

func TestLintYamlValidationWithoutValuesYaml(t *testing.T) {
testCases := []struct {
name string
chartDir string
validateYaml bool
callsYamlLint int
}{
{
name: "no values.yaml without validation",
chartDir: "testdata/no_values_yaml",
validateYaml: false,
callsYamlLint: 0,
},
{
name: "no values.yaml with validation",
chartDir: "testdata/no_values_yaml",
validateYaml: true,
callsYamlLint: 1, // Only Chart.yaml
},
{
name: "with values.yaml with validation",
chartDir: "testdata/test_lints",
validateYaml: true,
callsYamlLint: 2, // Chart.yaml and values.yaml
},
}

for _, testData := range testCases {
t.Run(testData.name, func(t *testing.T) {
fakeMockLinter := new(fakeLinter)
fakeMockLinter.On("Yamale", mock.Anything, mock.Anything).Return(true)
fakeMockLinter.On("YamlLint", mock.Anything, mock.Anything).Return(true)

ct.linter = fakeMockLinter
ct.config.ValidateYaml = testData.validateYaml
ct.config.ValidateChartSchema = false
ct.config.ValidateMaintainers = false

chart, err := NewChart(testData.chartDir)
assert.Nil(t, err)
result := ct.LintChart(chart)
assert.Nil(t, result.Error)
fakeMockLinter.AssertNumberOfCalls(t, "Yamale", 0)
fakeMockLinter.AssertNumberOfCalls(t, "YamlLint", testData.callsYamlLint)
})
}
}

func TestLintDependencyExtraArgs(t *testing.T) {
chart := "testdata/test_lints"
args := []string{"--skip-refresh"}
Expand Down
9 changes: 9 additions & 0 deletions pkg/chart/testdata/no_values_yaml/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: no-values-yaml-test
description: A test chart without values.yaml
type: application
version: 0.1.0
appVersion: "1.16.0"
maintainers:
- name: validuser
email: [email protected]