Skip to content

Commit

Permalink
Ignore files with no tests when searching for test files (#7541)
Browse files Browse the repository at this point in the history
* chore: ignore files with no tests when searching for test files

* chore: updated tests
  • Loading branch information
chatton authored Nov 7, 2024
1 parent 7c51a03 commit c191b1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cmd/build_test_matrix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func getGithubActionMatrixForTests(e2eRootDirectory, testName string, suite stri

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

if testName != "" && contains(testName, testCases) {
Expand Down Expand Up @@ -145,6 +145,11 @@ func getGithubActionMatrixForTests(e2eRootDirectory, testName string, suite stri
})
}
}

if len(gh.Include) == 0 {
return GithubActionTestMatrix{}, fmt.Errorf("no test cases found")
}

// Sort the test cases by name so that the order is consistent.
sort.SliceStable(gh.Include, func(i, j int) bool {
return gh.Include[i].Test < gh.Include[j].Test
Expand Down
8 changes: 4 additions & 4 deletions cmd/build_test_matrix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (
)

func TestGetGithubActionMatrixForTests(t *testing.T) {
t.Run("empty dir does not fail", func(t *testing.T) {
t.Run("empty dir with no test cases fails", func(t *testing.T) {
testingDir := t.TempDir()
_, err := getGithubActionMatrixForTests(testingDir, "", "", nil)
assert.NoError(t, err)
assert.Error(t, err)
})

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

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

gh, err := getGithubActionMatrixForTests(testingDir, "", "", nil)
assert.NoError(t, err)
assert.Error(t, err)
assert.Empty(t, gh.Include)
})

Expand Down

0 comments on commit c191b1d

Please sign in to comment.