Skip to content

Commit 33414a7

Browse files
committed
Fix testCatalogName conflict in parallel e2e tests
1 parent b23e124 commit 33414a7

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

test/e2e/cluster_extension_install_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"slices"
78
"testing"
89
"time"
910

@@ -197,7 +198,8 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
197198
t.Log("When a cluster extension is installed from a catalog")
198199

199200
clusterExtension, extensionCatalog, sa, ns := TestInit(t)
200-
extraCatalog, err := CreateTestCatalog(context.Background(), "extra-test-catalog", os.Getenv(testCatalogRefEnvVar))
201+
extraCatalogName := fmt.Sprintf("extra-test-catalog-%s", rand.String(8))
202+
extraCatalog, err := CreateTestCatalog(context.Background(), extraCatalogName, os.Getenv(testCatalogRefEnvVar))
201203
require.NoError(t, err)
202204

203205
defer TestCleanup(t, extensionCatalog, clusterExtension, sa, ns)
@@ -238,7 +240,11 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
238240
require.NotNil(ct, cond)
239241
require.Equal(ct, metav1.ConditionTrue, cond.Status)
240242
require.Equal(ct, ocv1.ReasonRetrying, cond.Reason)
241-
require.Contains(ct, cond.Message, "in multiple catalogs with the same priority [extra-test-catalog test-catalog]")
243+
// Catalog names are sorted alphabetically in the error message
244+
catalogs := []string{extensionCatalog.Name, extraCatalog.Name}
245+
slices.Sort(catalogs)
246+
expectedMessage := fmt.Sprintf("in multiple catalogs with the same priority %v", catalogs)
247+
require.Contains(ct, cond.Message, expectedMessage)
242248
}, pollDuration, pollInterval)
243249
}
244250

@@ -441,7 +447,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
441447
// patch imageRef tag on test-catalog image with v2 image
442448
t.Log("By patching the catalog ImageRef to point to the v2 catalog")
443449
updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("CLUSTER_REGISTRY_HOST"))
444-
err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage)
450+
err := patchTestCatalog(context.Background(), extensionCatalog.Name, updatedCatalogImage)
445451
require.NoError(t, err)
446452
require.EventuallyWithT(t, func(ct *assert.CollectT) {
447453
require.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog))
@@ -474,8 +480,9 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
474480
require.NoError(t, err)
475481

476482
// create a test-catalog with latest image tag
483+
catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8))
477484
latestCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:latest", os.Getenv("CLUSTER_REGISTRY_HOST"))
478-
extensionCatalog, err := CreateTestCatalog(context.Background(), testCatalogName, latestCatalogImage)
485+
extensionCatalog, err := CreateTestCatalog(context.Background(), catalogName, latestCatalogImage)
479486
require.NoError(t, err)
480487
clusterExtensionName := fmt.Sprintf("clusterextension-%s", rand.String(8))
481488
clusterExtension := &ocv1.ClusterExtension{

test/helpers/helpers.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,18 @@ func TestInit(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog, *core
218218

219219
func TestInitClusterExtensionClusterCatalog(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog) {
220220
ceName := fmt.Sprintf("clusterextension-%s", rand.String(8))
221+
catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8))
221222

222223
ce := &ocv1.ClusterExtension{
223224
ObjectMeta: metav1.ObjectMeta{
224225
Name: ceName,
225226
},
226227
}
227228

228-
cc, err := CreateTestCatalog(context.Background(), testCatalogName, os.Getenv(testCatalogRefEnvVar))
229+
cc, err := CreateTestCatalog(context.Background(), catalogName, os.Getenv(testCatalogRefEnvVar))
229230
require.NoError(t, err)
230231

231-
ValidateCatalogUnpack(t)
232+
ValidateCatalogUnpackWithName(t, catalogName)
232233

233234
return ce, cc
234235
}
@@ -250,11 +251,18 @@ func TestInitServiceAccountNamespace(t *testing.T, clusterExtensionName string)
250251
return sa, ns
251252
}
252253

254+
// ValidateCatalogUnpack validates that the test catalog with the default name has unpacked successfully.
255+
// Deprecated: Use ValidateCatalogUnpackWithName for tests that use unique catalog names.
253256
func ValidateCatalogUnpack(t *testing.T) {
257+
ValidateCatalogUnpackWithName(t, testCatalogName)
258+
}
259+
260+
// ValidateCatalogUnpackWithName validates that a catalog with the given name has unpacked successfully.
261+
func ValidateCatalogUnpackWithName(t *testing.T, catalogName string) {
254262
catalog := &ocv1.ClusterCatalog{}
255263
t.Log("Ensuring ClusterCatalog has Status.Condition of Progressing with a status == True and reason == Succeeded")
256264
require.EventuallyWithT(t, func(ct *assert.CollectT) {
257-
err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog)
265+
err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog)
258266
require.NoError(ct, err)
259267
cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeProgressing)
260268
require.NotNil(ct, cond)
@@ -265,11 +273,11 @@ func ValidateCatalogUnpack(t *testing.T) {
265273
t.Log("Checking that catalog has the expected metadata label")
266274
require.NotNil(t, catalog.Labels)
267275
require.Contains(t, catalog.Labels, "olm.operatorframework.io/metadata.name")
268-
require.Equal(t, testCatalogName, catalog.Labels["olm.operatorframework.io/metadata.name"])
276+
require.Equal(t, catalogName, catalog.Labels["olm.operatorframework.io/metadata.name"])
269277

270278
t.Log("Ensuring ClusterCatalog has Status.Condition of Type = Serving with status == True")
271279
require.EventuallyWithT(t, func(ct *assert.CollectT) {
272-
err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog)
280+
err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog)
273281
require.NoError(ct, err)
274282
cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeServing)
275283
require.NotNil(ct, cond)

0 commit comments

Comments
 (0)