diff --git a/pkg/extension/extensiontests/spec.go b/pkg/extension/extensiontests/spec.go index 1b36354..4e77842 100644 --- a/pkg/extension/extensiontests/spec.go +++ b/pkg/extension/extensiontests/spec.go @@ -107,18 +107,32 @@ func (specs ExtensionTestSpecs) MustSelectAll(selectFns []SelectFunction) (Exten return filtered, nil } -// ModuleTestsOnly ensures that ginkgo tests from vendored sources aren't selected, -// except for the Origin extended util packages, that may contain Ginkgo nodes but -// should not cause a test exclusion. +// ModuleTestsOnly ensures that ginkgo tests from vendored sources aren't selected. Unfortunately, making +// use of kubernetes test helpers results in the entire Ginkgo suite being initialized (ginkgo loves global state), +// so we need to be careful about which tests we select. +// +// A test is excluded if ALL of its code locations with full paths are external (vendored or from external test +// suites). If at least one code location with a full path is from the local module, the test is included, because +// local tests may legitimately call helper functions from vendored test frameworks. func ModuleTestsOnly() SelectFunction { return func(spec *ExtensionTestSpec) bool { + hasLocalCode := false + for _, cl := range spec.CodeLocations { - if strings.Contains(cl, "/vendor/") && !strings.Contains(cl, "github.com/openshift/origin/test/extended/util") { - return false + // Short-form code locations (e.g., "set up framework | framework.go:200") are ignored in this determination. + if !strings.Contains(cl, "/") { + continue + } + + // If this code location is not external (vendored or k8s test), it's local code + if !(strings.Contains(cl, "/vendor/") || strings.HasPrefix(cl, "k8s.io/kubernetes")) { + hasLocalCode = true + break } } - return true + // Include the test only if it has at least one local code location + return hasLocalCode } } diff --git a/pkg/extension/extensiontests/spec_test.go b/pkg/extension/extensiontests/spec_test.go index 27ec8fe..a0171d1 100644 --- a/pkg/extension/extensiontests/spec_test.go +++ b/pkg/extension/extensiontests/spec_test.go @@ -1207,6 +1207,67 @@ func TestExtensionTestSpecs_Run_LifecycleFailures(t *testing.T) { } } +func TestModuleTestsOnly(t *testing.T) { + testCases := []struct { + name string + spec *ExtensionTestSpec + want bool + }{ + { + name: "excluded - all k8s.io/kubernetes/test code locations", + spec: &ExtensionTestSpec{ + Name: "[sig-cli] Kubectl rollout undo undo should rollback and update deployment env", + CodeLocations: []string{ + "k8s.io/kubernetes@v1.33.3/test/e2e/kubectl/rollout.go:40", + "set up framework | framework.go:200", + "k8s.io/kubernetes@v1.33.3/test/e2e/framework/node/init/init.go:33", + "k8s.io/kubernetes@v1.33.3/test/e2e/framework/debug/init/init.go:60", + "k8s.io/kubernetes@v1.33.3/test/e2e/framework/metrics/init/init.go:33", + "k8s.io/kubernetes@v1.33.3/test/e2e/kubectl/rollout.go:48", + "k8s.io/kubernetes@v1.33.3/test/e2e/kubectl/rollout.go:54", + "k8s.io/kubernetes@v1.33.3/test/e2e/kubectl/rollout.go:55", + "k8s.io/kubernetes@v1.33.3/test/e2e/kubectl/rollout.go:58", + }, + }, + want: false, + }, + { + name: "included - has local code locations, in module format", + spec: &ExtensionTestSpec{ + Name: "[sig-cluster-lifecycle][OCPFeatureGate:VSphereHostVMGroupZonal][platform:vsphere] A Machine in a managed cluster should be placed in the correct vm-host group", + CodeLocations: []string{ + "github.com/openshift/machine-api-operator@v0.0.0/test/e2e/vsphere/hostzonal.go:32", + "github.com/openshift/machine-api-operator@v0.0.0/test/e2e/vsphere/hostzonal.go:46", + "github.com/openshift/machine-api-operator@v0.0.0/test/e2e/vsphere/hostzonal.go:72", + }, + }, + want: true, + }, + { + name: "included - has local relative path code locations", + spec: &ExtensionTestSpec{ + Name: "[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiNetworks][platform:vsphere] Managed cluster should new machines should pass multi network tests", + CodeLocations: []string{ + "test/e2e/vsphere/multi-nic.go:152", + "test/e2e/vsphere/multi-nic.go:171", + "test/e2e/vsphere/multi-nic.go:238", + }, + }, + want: true, + }, + } + + selectFn := ModuleTestsOnly() + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + result := selectFn(tc.spec) + if result != tc.want { + t.Errorf("ModuleTestsOnly() returned %v, want %v", result, tc.want) + } + }) + } +} + // equateErrorMessage reports errors to be equal if both are nil // or both have the same message. var equateErrorMessage = cmp.FilterValues(func(x, y interface{}) bool {