diff --git a/cmd/build_test_matrix/main.go b/cmd/build_test_matrix/main.go index c2bee6d7050..052328dc5f4 100644 --- a/cmd/build_test_matrix/main.go +++ b/cmd/build_test_matrix/main.go @@ -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) { @@ -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 diff --git a/cmd/build_test_matrix/main_test.go b/cmd/build_test_matrix/main_test.go index 67a8fde26f8..280a4f620be 100644 --- a/cmd/build_test_matrix/main_test.go +++ b/cmd/build_test_matrix/main_test.go @@ -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) { @@ -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) })