Skip to content

Commit c191b1d

Browse files
authored
Ignore files with no tests when searching for test files (#7541)
* chore: ignore files with no tests when searching for test files * chore: updated tests
1 parent 7c51a03 commit c191b1d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cmd/build_test_matrix/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func getGithubActionMatrixForTests(e2eRootDirectory, testName string, suite stri
112112

113113
suiteNameForFile, testCases, err := extractSuiteAndTestNames(f)
114114
if err != nil {
115-
return fmt.Errorf("failed extracting test suite name and test cases: %s", err)
115+
return nil
116116
}
117117

118118
if testName != "" && contains(testName, testCases) {
@@ -145,6 +145,11 @@ func getGithubActionMatrixForTests(e2eRootDirectory, testName string, suite stri
145145
})
146146
}
147147
}
148+
149+
if len(gh.Include) == 0 {
150+
return GithubActionTestMatrix{}, fmt.Errorf("no test cases found")
151+
}
152+
148153
// Sort the test cases by name so that the order is consistent.
149154
sort.SliceStable(gh.Include, func(i, j int) bool {
150155
return gh.Include[i].Test < gh.Include[j].Test

cmd/build_test_matrix/main_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const (
1717
)
1818

1919
func TestGetGithubActionMatrixForTests(t *testing.T) {
20-
t.Run("empty dir does not fail", func(t *testing.T) {
20+
t.Run("empty dir with no test cases fails", func(t *testing.T) {
2121
testingDir := t.TempDir()
2222
_, err := getGithubActionMatrixForTests(testingDir, "", "", nil)
23-
assert.NoError(t, err)
23+
assert.Error(t, err)
2424
})
2525

2626
t.Run("only test functions are picked up", func(t *testing.T) {
@@ -105,12 +105,12 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
105105
assert.Error(t, err)
106106
})
107107

108-
t.Run("non test files are not picked up", func(t *testing.T) {
108+
t.Run("non test files are skipped", func(t *testing.T) {
109109
testingDir := t.TempDir()
110110
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, nonTestFile)
111111

112112
gh, err := getGithubActionMatrixForTests(testingDir, "", "", nil)
113-
assert.NoError(t, err)
113+
assert.Error(t, err)
114114
assert.Empty(t, gh.Include)
115115
})
116116

0 commit comments

Comments
 (0)