diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index aa4a4c4bcd..8dd4ff9b91 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -92,12 +92,12 @@ jobs: # run non-flakes if matrix-id is not 'flakes' - name: Run e2e tests - # calculate the number of chunks as the number of parallel jobs minus 1 (flakes job) + # calculate the number of chunks as the number of parallel jobs # use the split tool to split the test suite into chunks and run the chunk corresponding to the matrix-id # focus on those tests and skip tests marked as FLAKE run: | - E2E_TEST_NUM_CHUNKS=$(( ${{ strategy.job-total }} - 1 )) \ - GINKGO_OPTS="${GINKGO_OPTS} -focus '$(go run ./test/e2e/split/... -chunks $E2E_TEST_NUM_CHUNKS -print-chunk $E2E_TEST_CHUNK ./test/e2e)' -skip '\[FLAKE\]'" \ + E2E_TEST_NUM_CHUNKS=$(( ${{ strategy.job-total }} )) \ + GINKGO_OPTS="${GINKGO_OPTS} -label-filter '$(go run ./test/e2e/split/... -chunks $E2E_TEST_NUM_CHUNKS -print-chunk $E2E_TEST_CHUNK ./test/e2e)' -skip '\[FLAKE\]'" \ make e2e; # archive test results diff --git a/test/e2e/bundle_e2e_test.go b/test/e2e/bundle_e2e_test.go index d52c348edc..9accdbb9c0 100644 --- a/test/e2e/bundle_e2e_test.go +++ b/test/e2e/bundle_e2e_test.go @@ -26,7 +26,7 @@ import ( //go:embed testdata/vpa/crd.yaml var vpaCRDRaw []byte -var _ = Describe("Installing bundles with new object types", func() { +var _ = Describe("Installing bundles with new object types", Label("ObjectTypes"), func() { var ( kubeClient operatorclient.ClientInterface operatorClient versioned.Interface diff --git a/test/e2e/catalog_e2e_test.go b/test/e2e/catalog_e2e_test.go index b22893b48a..39fa0497d7 100644 --- a/test/e2e/catalog_e2e_test.go +++ b/test/e2e/catalog_e2e_test.go @@ -43,7 +43,7 @@ const ( badCSVDir = "bad-csv" ) -var _ = Describe("Starting CatalogSource e2e tests", func() { +var _ = Describe("Starting CatalogSource e2e tests", Label("CatalogSource"), func() { var ( generatedNamespace corev1.Namespace c operatorclient.ClientInterface diff --git a/test/e2e/catalog_exclusion_test.go b/test/e2e/catalog_exclusion_test.go index 741cad1b1f..b646e1351d 100644 --- a/test/e2e/catalog_exclusion_test.go +++ b/test/e2e/catalog_exclusion_test.go @@ -19,7 +19,7 @@ import ( const magicCatalogDir = "magiccatalog" -var _ = Describe("Global Catalog Exclusion", func() { +var _ = Describe("Global Catalog Exclusion", Label("CatalogExclusion"), func() { var ( generatedNamespace corev1.Namespace determinedE2eClient *util.DeterminedE2EClient diff --git a/test/e2e/catsrc_pod_config_e2e_test.go b/test/e2e/catsrc_pod_config_e2e_test.go index a37f8ca69e..50930d5e64 100644 --- a/test/e2e/catsrc_pod_config_e2e_test.go +++ b/test/e2e/catsrc_pod_config_e2e_test.go @@ -18,7 +18,7 @@ const catalogSourceLabel = "olm.catalogSource" var _ = By -var _ = Describe("CatalogSource Grpc Pod Config", func() { +var _ = Describe("CatalogSource Grpc Pod Config", Label("CatalogSourcePodConfig"), func() { var ( generatedNamespace corev1.Namespace diff --git a/test/e2e/crd_e2e_test.go b/test/e2e/crd_e2e_test.go index 79091b6faf..dc1d9c5126 100644 --- a/test/e2e/crd_e2e_test.go +++ b/test/e2e/crd_e2e_test.go @@ -22,7 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -var _ = Describe("CRD Versions", func() { +var _ = Describe("CRD Versions", Label("CRDs"), func() { var ( generatedNamespace corev1.Namespace c operatorclient.ClientInterface diff --git a/test/e2e/csv_e2e_test.go b/test/e2e/csv_e2e_test.go index 7934c339c1..872707e436 100644 --- a/test/e2e/csv_e2e_test.go +++ b/test/e2e/csv_e2e_test.go @@ -34,7 +34,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("ClusterServiceVersion", func() { +var _ = Describe("ClusterServiceVersion", Label("ClusterServiceVersion"), func() { var ( generatedNamespace corev1.Namespace c operatorclient.ClientInterface diff --git a/test/e2e/deprecated_e2e_test.go b/test/e2e/deprecated_e2e_test.go index 49c618e2cb..d11b274c5e 100644 --- a/test/e2e/deprecated_e2e_test.go +++ b/test/e2e/deprecated_e2e_test.go @@ -18,7 +18,7 @@ import ( var missingAPI = `{"apiVersion":"verticalpodautoscalers.autoscaling.k8s.io/v1","kind":"VerticalPodAutoscaler","metadata":{"name":"my.thing","namespace":"foo"}}` -var _ = Describe("Not found APIs", func() { +var _ = Describe("Not found APIs", Label("APIDeprecation"), func() { var generatedNamespace corev1.Namespace BeforeEach(func() { diff --git a/test/e2e/disabling_copied_csv_e2e_test.go b/test/e2e/disabling_copied_csv_e2e_test.go index ddb0a62aa9..7757986beb 100644 --- a/test/e2e/disabling_copied_csv_e2e_test.go +++ b/test/e2e/disabling_copied_csv_e2e_test.go @@ -26,7 +26,7 @@ const ( protectedCopiedCSVNamespacesRuntimeFlag = "--protectedCopiedCSVNamespaces" ) -var _ = Describe("Disabling copied CSVs", func() { +var _ = Describe("Disabling copied CSVs", Label("DisablingCopiedCSVs"), func() { var ( generatedNamespace corev1.Namespace csv operatorsv1alpha1.ClusterServiceVersion diff --git a/test/e2e/dynamic_resource_e2e_test.go b/test/e2e/dynamic_resource_e2e_test.go index cd7e7c92b8..8bd2583057 100644 --- a/test/e2e/dynamic_resource_e2e_test.go +++ b/test/e2e/dynamic_resource_e2e_test.go @@ -20,7 +20,7 @@ import ( // This test was disabled because both of its tests are currently being skipped // We need to understand why and whether this test is even needed: // https://github.com/operator-framework/operator-lifecycle-manager/issues/3402 -var _ = XDescribe("Subscriptions create required objects from Catalogs", func() { +var _ = XDescribe("Subscriptions create required objects from Catalogs", Label("DynamicResource"), func() { var ( crc versioned.Interface generatedNamespace corev1.Namespace diff --git a/test/e2e/fail_forward_e2e_test.go b/test/e2e/fail_forward_e2e_test.go index 76a6462ea4..69f4e329ca 100644 --- a/test/e2e/fail_forward_e2e_test.go +++ b/test/e2e/fail_forward_e2e_test.go @@ -123,7 +123,7 @@ func updateCatalogSource(namespace, name string, packages ...string) (func(), er return deployCatalogSource(namespace, name, packages...) } -var _ = Describe("Fail Forward Upgrades", func() { +var _ = Describe("Fail Forward Upgrades", Label("FailForward"), func() { var ( generatedNamespace corev1.Namespace diff --git a/test/e2e/gc_e2e_test.go b/test/e2e/gc_e2e_test.go index 927844f095..2a9c2bf3c9 100644 --- a/test/e2e/gc_e2e_test.go +++ b/test/e2e/gc_e2e_test.go @@ -23,7 +23,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Garbage collection for dependent resources", func() { +var _ = Describe("Garbage collection for dependent resources", Label("GarbageCollection"), func() { var ( kubeClient operatorclient.ClientInterface operatorClient versioned.Interface diff --git a/test/e2e/installplan_e2e_test.go b/test/e2e/installplan_e2e_test.go index 8110d4e534..4fe1419fd6 100644 --- a/test/e2e/installplan_e2e_test.go +++ b/test/e2e/installplan_e2e_test.go @@ -50,7 +50,7 @@ const ( deprecatedCRDDir = "deprecated-crd" ) -var _ = Describe("Install Plan", func() { +var _ = Describe("Install Plan", Label("InstallPlan"), func() { var ( c operatorclient.ClientInterface crc versioned.Interface diff --git a/test/e2e/magic_catalog_test.go b/test/e2e/magic_catalog_test.go index 9e583b8ed3..c437d67a4f 100644 --- a/test/e2e/magic_catalog_test.go +++ b/test/e2e/magic_catalog_test.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var _ = Describe("MagicCatalog", func() { +var _ = Describe("MagicCatalog", Label("MagicCatalog"), func() { var ( generatedNamespace corev1.Namespace c client.Client diff --git a/test/e2e/metrics_e2e_test.go b/test/e2e/metrics_e2e_test.go index 7a98593a41..fecefd7334 100644 --- a/test/e2e/metrics_e2e_test.go +++ b/test/e2e/metrics_e2e_test.go @@ -27,7 +27,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Metrics are generated for OLM managed resources", func() { +var _ = Describe("Metrics are generated for OLM managed resources", Label("Metrics"), func() { var ( c operatorclient.ClientInterface crc versioned.Interface diff --git a/test/e2e/operator_condition_e2e_test.go b/test/e2e/operator_condition_e2e_test.go index bc53ca2acd..f4c7857347 100644 --- a/test/e2e/operator_condition_e2e_test.go +++ b/test/e2e/operator_condition_e2e_test.go @@ -19,7 +19,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Operator Condition", func() { +var _ = Describe("Operator Condition", Label("OperatorCondition"), func() { var ( generatedNamespace corev1.Namespace ) diff --git a/test/e2e/operator_groups_e2e_test.go b/test/e2e/operator_groups_e2e_test.go index e32f44b1f0..a8739f58db 100644 --- a/test/e2e/operator_groups_e2e_test.go +++ b/test/e2e/operator_groups_e2e_test.go @@ -35,7 +35,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Operator Group", func() { +var _ = Describe("Operator Group", Label("OperatorGroup"), func() { var ( c operatorclient.ClientInterface crc versioned.Interface diff --git a/test/e2e/operator_test.go b/test/e2e/operator_test.go index 90caea0f1f..e1ff314ec0 100644 --- a/test/e2e/operator_test.go +++ b/test/e2e/operator_test.go @@ -31,7 +31,7 @@ import ( ) // Describes test specs for the Operator resource. -var _ = Describe("Operator API", func() { +var _ = Describe("Operator API", Label("Operator"), func() { var ( clientCtx context.Context scheme *runtime.Scheme diff --git a/test/e2e/packagemanifest_e2e_test.go b/test/e2e/packagemanifest_e2e_test.go index d3a9cf971f..5e3e5a7cc1 100644 --- a/test/e2e/packagemanifest_e2e_test.go +++ b/test/e2e/packagemanifest_e2e_test.go @@ -23,7 +23,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Package Manifest API lists available Operators from Catalog Sources", func() { +var _ = Describe("Package Manifest API lists available Operators from Catalog Sources", Label("PackageManifest"), func() { var ( crc versioned.Interface pmc pmversioned.Interface diff --git a/test/e2e/resource_manager_test.go b/test/e2e/resource_manager_test.go index 702aaaecf2..234fe0164f 100644 --- a/test/e2e/resource_manager_test.go +++ b/test/e2e/resource_manager_test.go @@ -14,7 +14,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("ResourceManager", func() { +var _ = Describe("ResourceManager", Label("ResourceManager"), func() { var generatedNamespace corev1.Namespace BeforeEach(func() { diff --git a/test/e2e/scoped_client_test.go b/test/e2e/scoped_client_test.go index 3b201d3c67..5800055fda 100644 --- a/test/e2e/scoped_client_test.go +++ b/test/e2e/scoped_client_test.go @@ -18,7 +18,7 @@ import ( "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" ) -var _ = Describe("Scoped Client bound to a service account can be used to make API calls", func() { +var _ = Describe("Scoped Client bound to a service account can be used to make API calls", Label("ScopedClient"), func() { // TestScopedClient ensures that we can create a scoped client bound to a // service account and then we can use the scoped client to make API calls. var ( diff --git a/test/e2e/split/integration_test.sh b/test/e2e/split/integration_test.sh index 1c4b315433..1d2d17b061 100755 --- a/test/e2e/split/integration_test.sh +++ b/test/e2e/split/integration_test.sh @@ -5,8 +5,8 @@ function get_total_specs() { } unfocused_specs=$(get_total_specs) -regexp=$(go run ./test/e2e/split/... -chunks 1 -print-chunk 0 ./test/e2e) -focused_specs=$(get_total_specs -focus "$regexp") +label_filter=$(go run ./test/e2e/split/... -chunks 1 -print-chunk 0 ./test/e2e) +focused_specs=$(get_total_specs -label-filter "$label_filter") if ! [ $unfocused_specs -eq $focused_specs ]; then echo "expected number of unfocused specs $unfocused_specs to equal focus specs $focused_specs" diff --git a/test/e2e/split/main.go b/test/e2e/split/main.go index 1637fdb567..fdaf90eec9 100644 --- a/test/e2e/split/main.go +++ b/test/e2e/split/main.go @@ -3,18 +3,27 @@ package main import ( "flag" "fmt" + "go/ast" + "go/parser" + "go/token" "io" "log" "math" "os" "path/filepath" - "regexp" "sort" "strings" "github.com/sirupsen/logrus" ) +const ( + ginkgoDescribeFunctionName = "Describe" + ginkgoLabelFunctionName = "Label" +) + +var logger = logrus.New() + type options struct { numChunks int printChunk int @@ -34,54 +43,57 @@ func main() { flag.Parse() if opts.printChunk >= opts.numChunks { - exitIfErr(fmt.Errorf("the chunk to print (%d) must be a smaller number than the number of chunks (%d)", opts.printChunk, opts.numChunks)) + log.Fatal(fmt.Errorf("the chunk to print (%d) must be a smaller number than the number of chunks (%d)", opts.printChunk, opts.numChunks)) } dir := flag.Arg(0) if dir == "" { - exitIfErr(fmt.Errorf("test directory required as the argument")) + log.Fatal(fmt.Errorf("test directory required as the argument")) } - // Clean dir. var err error - dir, err = filepath.Abs(dir) - exitIfErr(err) - wd, err := os.Getwd() - exitIfErr(err) - dir, err = filepath.Rel(wd, dir) - exitIfErr(err) - - exitIfErr(opts.run(dir)) -} + level, err := logrus.ParseLevel(opts.logLevel) + if err != nil { + log.Fatal(err) + } + logger.SetLevel(level) -func exitIfErr(err error) { + dir, err = getPathRelativeToCwd(dir) if err != nil { log.Fatal(err) } + + if err := opts.run(dir); err != nil { + log.Fatal(err) + } } -func (opts options) run(dir string) error { - level, err := logrus.ParseLevel(opts.logLevel) +func getPathRelativeToCwd(path string) (string, error) { + path, err := filepath.Abs(path) if err != nil { - return fmt.Errorf("failed to parse the %s log level: %v", opts.logLevel, err) + return "", err } - logger := logrus.New() - logger.SetLevel(level) - describes, err := findDescribes(logger, dir) + wd, err := os.Getwd() if err != nil { - return err + return "", err } + return filepath.Rel(wd, path) +} - // Find minimal prefixes for all spec strings so no spec runs are duplicated across chunks. - prefixes := findMinimalWordPrefixes(describes) - sort.Strings(prefixes) +func (opts options) run(dir string) error { + // Get all test labels + labels, err := findLabels(dir) + if err != nil { + return err + } + sort.Strings(labels) var out string if opts.printDebug { - out = strings.Join(prefixes, "\n") + out = strings.Join(labels, "\n") } else { - out, err = createChunkRegexp(opts.numChunks, opts.printChunk, prefixes) + out, err = createFilterLabelChunk(opts.numChunks, opts.printChunk, labels) if err != nil { return err } @@ -91,52 +103,53 @@ func (opts options) run(dir string) error { return nil } -// TODO: this is hacky because top-level tests may be defined elsewise. -// A better strategy would be to use the output of `ginkgo -noColor -dryRun` -// like https://github.com/operator-framework/operator-lifecycle-manager/pull/1476 does. -var topDescribeRE = regexp.MustCompile(`var _ = Describe\("(.+)", func\(.*`) - -func findDescribes(logger logrus.FieldLogger, dir string) ([]string, error) { - // Find all Ginkgo specs in dir's test files. - // These can be grouped independently. - describeTable := make(map[string]struct{}) +func findLabels(dir string) ([]string, error) { + var labels []string + logger.Infof("Finding labels for ginkgo tests in path: %s", dir) matches, err := filepath.Glob(filepath.Join(dir, "*_test.go")) if err != nil { return nil, err } for _, match := range matches { - b, err := os.ReadFile(match) - if err != nil { - return nil, err - } - specNames := topDescribeRE.FindAllSubmatch(b, -1) - if len(specNames) == 0 { - logger.Warnf("%s: found no top level describes, skipping", match) - continue - } - for _, possibleNames := range specNames { - if len(possibleNames) != 2 { - logger.Debugf("%s: expected to find 2 submatch, found %d:", match, len(possibleNames)) - for _, name := range possibleNames { - logger.Debugf("\t%s\n", string(name)) + labels = append(labels, extractLabelsFromFile(match)...) + } + return labels, nil +} + +func extractLabelsFromFile(filename string) []string { + var labels []string + + // Create a Go source file set + fs := token.NewFileSet() + node, err := parser.ParseFile(fs, filename, nil, parser.AllErrors) + if err != nil { + fmt.Printf("Error parsing file %s: %v\n", filename, err) + return labels + } + + ast.Inspect(node, func(n ast.Node) bool { + if callExpr, ok := n.(*ast.CallExpr); ok { + if fun, ok := callExpr.Fun.(*ast.Ident); ok && fun.Name == ginkgoDescribeFunctionName { + for _, arg := range callExpr.Args { + if ce, ok := arg.(*ast.CallExpr); ok { + if labelFunc, ok := ce.Fun.(*ast.Ident); ok && labelFunc.Name == ginkgoLabelFunctionName { + for _, arg := range ce.Args { + if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING { + labels = append(labels, strings.Trim(lit.Value, "\"")) + } + } + } + } } - continue } - describe := strings.TrimSpace(string(possibleNames[1])) - describeTable[describe] = struct{}{} } - } + return true + }) - describes := make([]string, len(describeTable)) - i := 0 - for describeKey := range describeTable { - describes[i] = describeKey - i++ - } - return describes, nil + return labels } -func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error) { +func createFilterLabelChunk(numChunks, printChunk int, specs []string) (string, error) { numSpecs := len(specs) if numSpecs < numChunks { return "", fmt.Errorf("have more desired chunks (%d) than specs (%d)", numChunks, numSpecs) @@ -162,72 +175,16 @@ func createChunkRegexp(numChunks, printChunk int, specs []string) (string, error // Write out the regexp to focus chunk specs via `ginkgo -focus `. var reStr string if len(chunk) == 1 { - reStr = fmt.Sprintf("%s .*", chunk[0]) + reStr = fmt.Sprintf("%s", chunk[0]) } else { sb := strings.Builder{} sb.WriteString(chunk[0]) for _, test := range chunk[1:] { - sb.WriteString("|") + sb.WriteString(" || ") sb.WriteString(test) } - reStr = fmt.Sprintf("(%s) .*", sb.String()) + reStr = fmt.Sprintf("%s", sb.String()) } return reStr, nil } - -func findMinimalWordPrefixes(specs []string) (prefixes []string) { - // Create a word trie of all spec strings. - t := make(wordTrie) - for _, spec := range specs { - t.push(spec) - } - - // Now find the first branch point for each path in the trie by DFS. - for word, node := range t { - var prefixElements []string - next: - if word != "" { - prefixElements = append(prefixElements, word) - } - if len(node.children) == 1 { - for nextWord, nextNode := range node.children { - word, node = nextWord, nextNode - } - goto next - } - // TODO: this might need to be joined by "\s+" - // in case multiple spaces were used in the spec name. - prefixes = append(prefixes, strings.Join(prefixElements, " ")) - } - - return prefixes -} - -// wordTrie is a trie of word nodes, instead of individual characters. -type wordTrie map[string]*wordTrieNode - -type wordTrieNode struct { - word string - children map[string]*wordTrieNode -} - -// push creates s branch of the trie from each word in s. -func (t wordTrie) push(s string) { - split := strings.Split(s, " ") - - curr := &wordTrieNode{word: "", children: t} - for _, sp := range split { - if sp = strings.TrimSpace(sp); sp == "" { - continue - } - next, hasNext := curr.children[sp] - if !hasNext { - next = &wordTrieNode{word: sp, children: make(map[string]*wordTrieNode)} - curr.children[sp] = next - } - curr = next - } - // Add termination node so "foo" and "foo bar" have a branching point of "foo". - curr.children[""] = &wordTrieNode{} -} diff --git a/test/e2e/split/main_test.go b/test/e2e/split/main_test.go index ec2a5410fa..2c95a13b54 100644 --- a/test/e2e/split/main_test.go +++ b/test/e2e/split/main_test.go @@ -3,12 +3,14 @@ package main import ( "os" "os/exec" + "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/require" ) -func TestMain(t *testing.T) { +func TestCmd(t *testing.T) { // This test makes sure that every spec gets run. cmd := exec.Command("./test/e2e/split/integration_test.sh") @@ -19,7 +21,7 @@ func TestMain(t *testing.T) { require.NoError(t, err) } -func TestCreateChunkRegexp(t *testing.T) { +func TestCreateFilterLabelChunk(t *testing.T) { type spec struct { name string numChunks int @@ -34,25 +36,25 @@ func TestCreateChunkRegexp(t *testing.T) { name: "singlePrefix1", numChunks: 1, printChunk: 0, specs: []string{"foo"}, - expRE: "foo .*", + expRE: "foo", }, { name: "multiplePrefixes1", numChunks: 1, printChunk: 0, specs: []string{"bar foo", "baz", "foo"}, - expRE: "(bar foo|baz|foo) .*", + expRE: "bar foo || baz || foo", }, { name: "multiplePrefixes2", numChunks: 3, printChunk: 0, specs: []string{"bar foo", "baz", "foo"}, - expRE: "bar foo .*", + expRE: "bar foo", }, { name: "multiplePrefixes3", numChunks: 3, printChunk: 2, specs: []string{"bar foo", "baz", "foo"}, - expRE: "foo .*", + expRE: "foo", }, { name: "empty", @@ -76,7 +78,7 @@ func TestCreateChunkRegexp(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { - re, err := createChunkRegexp(c.numChunks, c.printChunk, c.specs) + re, err := createFilterLabelChunk(c.numChunks, c.printChunk, c.specs) if c.expError != "" { require.EqualError(t, err, c.expError) } else { @@ -87,55 +89,17 @@ func TestCreateChunkRegexp(t *testing.T) { } } -func TestFindMinimalWordPrefixes(t *testing.T) { - type spec struct { - name string - specs []string - expPrefixes []string - } - - cases := []spec{ - { - name: "empty", - specs: nil, - expPrefixes: nil, - }, - { - name: "singleSpec", - specs: []string{"foo"}, - expPrefixes: []string{"foo"}, - }, - { - name: "twoSpecsSingleWordPrefix", - specs: []string{"foo", "foo bar"}, - expPrefixes: []string{"foo"}, - }, - { - name: "twoMultiWordSpecsSingleWordPrefix", - specs: []string{"foo bar", "foo baz"}, - expPrefixes: []string{"foo"}, - }, - { - name: "twoMultiWordSpecsLongPrefix", - specs: []string{"foo bar", "foo bar baz"}, - expPrefixes: []string{"foo bar"}, - }, - { - name: "threeSpecsSingleWordPrefix", - specs: []string{"foo", "foo bar", "foo baz"}, - expPrefixes: []string{"foo"}, - }, - { - name: "multiplePrefixes", - specs: []string{"foo", "foo bar", "foo bar baz", "bar foo", "baz buf", "baz bar foo"}, - expPrefixes: []string{"foo", "bar foo", "baz"}, - }, +func TestExtractLabels(t *testing.T) { + // Determine the directory of this test file + _, filename, _, ok := runtime.Caller(0) + if !ok { + t.Fatalf("Unable to determine the current file location") } + testDir := filepath.Join(filepath.Dir(filename), "testdata") + relPath, err := getPathRelativeToCwd(testDir) + require.NoError(t, err) - for _, c := range cases { - t.Run(c.name, func(t *testing.T) { - prefixes := findMinimalWordPrefixes(c.specs) - require.ElementsMatch(t, c.expPrefixes, prefixes) - }) - } + labels, err := findLabels(relPath) + require.NoError(t, err) + require.ElementsMatch(t, labels, []string{"SomeTest", "SomeOtherTest", "AlsoThis"}) } diff --git a/test/e2e/split/testdata/some_other_test.go b/test/e2e/split/testdata/some_other_test.go new file mode 100644 index 0000000000..ab151f2e00 --- /dev/null +++ b/test/e2e/split/testdata/some_other_test.go @@ -0,0 +1,11 @@ +package testdata + +import ( + . "github.com/onsi/ginkgo/v2" +) + +var _ = Describe("some other test", Label("SomeOtherTest", "AlsoThis"), func() { + It("should be ok", func() { + + }) +}) diff --git a/test/e2e/split/testdata/some_test.go b/test/e2e/split/testdata/some_test.go new file mode 100644 index 0000000000..604322ab67 --- /dev/null +++ b/test/e2e/split/testdata/some_test.go @@ -0,0 +1,7 @@ +package testdata + +import ( + . "github.com/onsi/ginkgo/v2" +) + +var _ = Describe("some test", Label("SomeTest"), func() {}) diff --git a/test/e2e/subscription_e2e_test.go b/test/e2e/subscription_e2e_test.go index a2372592c9..d8fa6f023d 100644 --- a/test/e2e/subscription_e2e_test.go +++ b/test/e2e/subscription_e2e_test.go @@ -55,7 +55,7 @@ const ( subscriptionTestDataBaseDir = "subscription/" ) -var _ = Describe("Subscription", func() { +var _ = Describe("Subscription", Label("Subscription"), func() { var ( generatedNamespace corev1.Namespace operatorGroup operatorsv1.OperatorGroup diff --git a/test/e2e/user_defined_sa_test.go b/test/e2e/user_defined_sa_test.go index d0558f11a0..c9a1a3d938 100644 --- a/test/e2e/user_defined_sa_test.go +++ b/test/e2e/user_defined_sa_test.go @@ -24,7 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -var _ = Describe("User defined service account", func() { +var _ = Describe("User defined service account", Label("UserDefinedServiceAccount"), func() { var ( generatedNamespace corev1.Namespace c operatorclient.ClientInterface diff --git a/test/e2e/webhook_e2e_test.go b/test/e2e/webhook_e2e_test.go index f2d4b87c73..ed99d46ef4 100644 --- a/test/e2e/webhook_e2e_test.go +++ b/test/e2e/webhook_e2e_test.go @@ -38,7 +38,7 @@ const ( webhookName = "webhook.test.com" ) -var _ = Describe("CSVs with a Webhook", func() { +var _ = Describe("CSVs with a Webhook", Label("Webhooks"), func() { var ( generatedNamespace corev1.Namespace c operatorclient.ClientInterface