@@ -15,6 +15,7 @@ func TestLintMultipleFiles(t *testing.T) {
1515 tests := []struct {
1616 name string
1717 files []string
18+ valuesFiles []string // values files for v1beta3 specs
1819 expectErrors map [string ][]string // filename -> expected error substrings
1920 expectWarnings map [string ][]string // filename -> expected warning substrings
2021 expectPass map [string ]bool // filename -> should pass without errors
@@ -24,21 +25,23 @@ func TestLintMultipleFiles(t *testing.T) {
2425 files : []string {
2526 "helm-builtins-v1beta3.yaml" ,
2627 },
27- expectErrors : map [string ][]string {},
28- expectWarnings : map [string ][]string {
29- "helm-builtins-v1beta3.yaml" : {
30- "Template values that must be provided at runtime: minVersion" ,
31- },
28+ valuesFiles : []string {
29+ "values-helm-builtins.yaml" ,
3230 },
31+ expectErrors : map [string ][]string {},
32+ expectWarnings : map [string ][]string {},
3333 expectPass : map [string ]bool {
34- "helm-builtins-v1beta3.yaml" : false , // has warnings
34+ "helm-builtins-v1beta3.yaml" : true ,
3535 },
3636 },
3737 {
3838 name : "invalid collectors and analyzers" ,
3939 files : []string {
4040 "invalid-collectors-analyzers.yaml" ,
4141 },
42+ valuesFiles : []string {
43+ "values-empty.yaml" ,
44+ },
4245 expectErrors : map [string ][]string {
4346 "invalid-collectors-analyzers.yaml" : {
4447 // The linter may stop early due to structural issues
@@ -57,6 +60,9 @@ func TestLintMultipleFiles(t *testing.T) {
5760 "missing-metadata-v1beta3.yaml" ,
5861 "no-analyzers-v1beta3.yaml" ,
5962 },
63+ valuesFiles : []string {
64+ "values-empty.yaml" ,
65+ },
6066 expectErrors : map [string ][]string {
6167 "missing-apiversion-v1beta3.yaml" : {
6268 "Missing or empty 'apiVersion' field" ,
@@ -95,6 +101,9 @@ func TestLintMultipleFiles(t *testing.T) {
95101 "support-bundle-no-collectors-v1beta3.yaml" ,
96102 "support-bundle-valid-v1beta3.yaml" ,
97103 },
104+ valuesFiles : []string {
105+ "values-empty.yaml" ,
106+ },
98107 expectErrors : map [string ][]string {
99108 "support-bundle-no-collectors-v1beta3.yaml" : {
100109 "SupportBundle spec must contain 'collectors' or 'hostCollectors'" ,
@@ -112,6 +121,9 @@ func TestLintMultipleFiles(t *testing.T) {
112121 "missing-metadata-v1beta3.yaml" ,
113122 "wrong-apiversion-v1beta3.yaml" ,
114123 },
124+ valuesFiles : []string {
125+ "values-empty.yaml" ,
126+ },
115127 expectErrors : map [string ][]string {
116128 "missing-metadata-v1beta3.yaml" : {
117129 "Missing 'metadata' section" ,
@@ -142,11 +154,18 @@ func TestLintMultipleFiles(t *testing.T) {
142154 }
143155 }
144156
157+ // Build values file paths
158+ var valuesFilePaths []string
159+ for _ , vf := range tt .valuesFiles {
160+ valuesFilePaths = append (valuesFilePaths , filepath .Join (testDir , vf ))
161+ }
162+
145163 // Run linter
146164 opts := LintOptions {
147- FilePaths : filePaths ,
148- Fix : false ,
149- Format : "text" ,
165+ FilePaths : filePaths ,
166+ Fix : false ,
167+ Format : "text" ,
168+ ValuesFiles : valuesFilePaths ,
150169 }
151170
152171 results , err := LintFiles (opts )
@@ -246,7 +265,7 @@ spec:
246265 fixedContent : "apiVersion: troubleshoot.sh/v1beta3" ,
247266 },
248267 {
249- name : "fix missing leading dot in template " ,
268+ name : "v1beta3 template syntax error is reported " ,
250269 content : `apiVersion: troubleshoot.sh/v1beta3
251270kind: Preflight
252271metadata:
@@ -258,11 +277,17 @@ spec:
258277 - pass:
259278 when: '>= 1.19.0'
260279 message: OK` ,
261- expectFix : true ,
262- fixedContent : "{{ .Values.name }}" ,
280+ expectFix : false , // Template errors in v1beta3 are not auto-fixable, rendering will fail
281+ fixedContent : "Failed to render v1beta3 template" , // Expect an error message
263282 },
264283 }
265284
285+ // Create empty values file for v1beta3 tests
286+ emptyValuesFile := filepath .Join (tmpDir , "values-empty.yaml" )
287+ if err := os .WriteFile (emptyValuesFile , []byte ("{}" ), 0644 ); err != nil {
288+ t .Fatalf ("Failed to write empty values file: %v" , err )
289+ }
290+
266291 for _ , tt := range tests {
267292 t .Run (tt .name , func (t * testing.T ) {
268293 // Write test content to temp file
@@ -273,9 +298,10 @@ spec:
273298
274299 // Run linter with fix enabled
275300 opts := LintOptions {
276- FilePaths : []string {testFile },
277- Fix : true ,
278- Format : "text" ,
301+ FilePaths : []string {testFile },
302+ Fix : true ,
303+ Format : "text" ,
304+ ValuesFiles : []string {emptyValuesFile },
279305 }
280306
281307 results , err := LintFiles (opts )
@@ -294,12 +320,27 @@ spec:
294320 }
295321 fixedContent := string (fixedBytes )
296322
297- // Check if fix was applied
323+ // Check if fix was applied or error was reported
298324 if tt .expectFix {
299325 if ! strings .Contains (fixedContent , tt .fixedContent ) {
300326 t .Errorf ("Expected fixed content to contain '%s', but got:\n %s" ,
301327 tt .fixedContent , fixedContent )
302328 }
329+ } else {
330+ // For tests that don't expect fix, check for errors
331+ if len (results [0 ].Errors ) > 0 {
332+ errorFound := false
333+ for _ , err := range results [0 ].Errors {
334+ if strings .Contains (err .Message , tt .fixedContent ) {
335+ errorFound = true
336+ break
337+ }
338+ }
339+ if ! errorFound {
340+ t .Errorf ("Expected error containing '%s', but got errors: %v" ,
341+ tt .fixedContent , results [0 ].Errors )
342+ }
343+ }
303344 }
304345 })
305346 }
0 commit comments