@@ -352,7 +352,8 @@ func main() {
352352 fmt .Println (p )
353353 }
354354 case "suites" :
355- // Determine impacted suites by dependency mapping, then print exact test names for those suites.
355+ // Determine impacted suites by dependency mapping and direct e2e test changes,
356+ // then print exact test names for those suites.
356357 preflightRoot := "github.com/replicatedhq/troubleshoot/cmd/preflight"
357358 supportRoot := "github.com/replicatedhq/troubleshoot/cmd/troubleshoot"
358359
@@ -369,6 +370,54 @@ func main() {
369370
370371 preflightHit := false
371372 supportHit := false
373+
374+ // Track whether e2e test files were directly changed per suite and collect specific test names
375+ changedPreflightTests := make (map [string ]struct {})
376+ changedSupportTests := make (map [string ]struct {})
377+ preflightE2EChangedNonGo := false
378+ supportE2EChangedNonGo := false
379+ for _ , f := range files {
380+ if strings .HasPrefix (f , "test/e2e/preflight/" ) {
381+ if strings .HasSuffix (f , "_test.go" ) {
382+ // Extract test names from just this file
383+ b , err := os .ReadFile (f )
384+ if err == nil { // ignore read errors; they will be caught later if needed
385+ scanner := bufio .NewScanner (bytes .NewReader (b ))
386+ re := regexp .MustCompile (`^func\s+(Test[\w\d_]+)\s*\(` )
387+ for scanner .Scan () {
388+ line := strings .TrimSpace (scanner .Text ())
389+ if m := re .FindStringSubmatch (line ); m != nil {
390+ changedPreflightTests [m [1 ]] = struct {}{}
391+ }
392+ }
393+ }
394+ preflightHit = true
395+ } else {
396+ // Non-go change under preflight e2e; run whole suite
397+ preflightE2EChangedNonGo = true
398+ preflightHit = true
399+ }
400+ }
401+ if strings .HasPrefix (f , "test/e2e/support-bundle/" ) {
402+ if strings .HasSuffix (f , "_test.go" ) {
403+ b , err := os .ReadFile (f )
404+ if err == nil {
405+ scanner := bufio .NewScanner (bytes .NewReader (b ))
406+ re := regexp .MustCompile (`^func\s+(Test[\w\d_]+)\s*\(` )
407+ for scanner .Scan () {
408+ line := strings .TrimSpace (scanner .Text ())
409+ if m := re .FindStringSubmatch (line ); m != nil {
410+ changedSupportTests [m [1 ]] = struct {}{}
411+ }
412+ }
413+ }
414+ supportHit = true
415+ } else {
416+ supportE2EChangedNonGo = true
417+ supportHit = true
418+ }
419+ }
420+ }
372421 for changed := range directPkgs {
373422 if ! preflightHit {
374423 if _ , ok := preflightDeps [changed ]; ok {
@@ -414,22 +463,53 @@ func main() {
414463 // Collect tests for impacted suites and print as `<suite>:<TestName>`
415464 if preflightHit || supportHit {
416465 if preflightHit {
417- preTests , err := listTestFunctions ("test/e2e/preflight" )
418- if err != nil {
419- fmt .Fprintln (os .Stderr , err )
420- os .Exit (2 )
466+ toPrint := make (map [string ]struct {})
467+ if preflightE2EChangedNonGo || len (changedPreflightTests ) == 0 {
468+ // Run full suite if e2e non-go assets changed or no specific test names collected
469+ preTests , err := listTestFunctions ("test/e2e/preflight" )
470+ if err != nil {
471+ fmt .Fprintln (os .Stderr , err )
472+ os .Exit (2 )
473+ }
474+ for _ , t := range preTests {
475+ toPrint [t ] = struct {}{}
476+ }
477+ } else {
478+ for t := range changedPreflightTests {
479+ toPrint [t ] = struct {}{}
480+ }
481+ }
482+ var list []string
483+ for t := range toPrint {
484+ list = append (list , t )
421485 }
422- for _ , tname := range preTests {
486+ sort .Strings (list )
487+ for _ , tname := range list {
423488 fmt .Printf ("preflight:%s\n " , tname )
424489 }
425490 }
426491 if supportHit {
427- sbTests , err := listTestFunctions ("test/e2e/support-bundle" )
428- if err != nil {
429- fmt .Fprintln (os .Stderr , err )
430- os .Exit (2 )
492+ toPrint := make (map [string ]struct {})
493+ if supportE2EChangedNonGo || len (changedSupportTests ) == 0 {
494+ sbTests , err := listTestFunctions ("test/e2e/support-bundle" )
495+ if err != nil {
496+ fmt .Fprintln (os .Stderr , err )
497+ os .Exit (2 )
498+ }
499+ for _ , t := range sbTests {
500+ toPrint [t ] = struct {}{}
501+ }
502+ } else {
503+ for t := range changedSupportTests {
504+ toPrint [t ] = struct {}{}
505+ }
506+ }
507+ var list []string
508+ for t := range toPrint {
509+ list = append (list , t )
431510 }
432- for _ , tname := range sbTests {
511+ sort .Strings (list )
512+ for _ , tname := range list {
433513 fmt .Printf ("support-bundle:%s\n " , tname )
434514 }
435515 }
0 commit comments