Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#1204 from justinsb/run_by_service
Browse files Browse the repository at this point in the history
tests: run tests grouped by GVK group
  • Loading branch information
google-oss-prow[bot] authored Feb 6, 2024
2 parents 6d8cd9e + fbc6f75 commit e4fb31a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/test/resourcefixture/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,46 @@ package resourcefixture
import (
"context"
"fmt"
"strings"
"testing"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
testconstants "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/constants"
"k8s.io/apimachinery/pkg/util/sets"
)

type ShouldRunFunc func(fixture ResourceFixture) bool
type TestCaseFunc func(ctx context.Context, t *testing.T, fixture ResourceFixture)

func RunTests(ctx context.Context, t *testing.T, shouldRun ShouldRunFunc, testCaseFunc TestCaseFunc) {
testCases := Load(t)

var filtered []ResourceFixture
for _, tc := range testCases {
if !shouldRun(tc) {
continue
}
runTestCase(ctx, t, tc, testCaseFunc)
filtered = append(filtered, tc)
}

// Run tests grouped by the group of the GVK
groups := sets.NewString()
for _, tc := range filtered {
groups.Insert(tc.GVK.Group)
}

for _, group := range groups.List() {
group := group
groupTestName := strings.TrimSuffix(group, ".cnrm.cloud.google.com")
t.Run(groupTestName, func(t *testing.T) {
t.Parallel()
for _, tc := range filtered {
if tc.GVK.Group != group {
continue
}
runTestCase(ctx, t, tc, testCaseFunc)
}
})
}
}

Expand Down

0 comments on commit e4fb31a

Please sign in to comment.