Skip to content

Commit 18931ab

Browse files
committed
fix testCatalogName conflict
1 parent 4355cde commit 18931ab

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

internal/shared/util/testutils/artifacts.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stretchr/testify/require"
1414
appsv1 "k8s.io/api/apps/v1"
1515
corev1 "k8s.io/api/core/v1"
16+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1617
kubeclient "k8s.io/client-go/kubernetes"
1718
"k8s.io/client-go/rest"
1819
"k8s.io/utils/env"
@@ -71,9 +72,13 @@ func CollectTestArtifacts(t *testing.T, artifactName string, c client.Client, cf
7172
}
7273

7374
// get all cluster extension revisions save them to the artifact path.
75+
// Note: ClusterExtensionRevision is an experimental API and may not be available in all environments.
7476
clusterExtensionRevisions := ocv1.ClusterExtensionRevisionList{}
7577
if err := c.List(context.Background(), &clusterExtensionRevisions); err != nil {
76-
fmt.Printf("Failed to list cluster extensions: %v", err)
78+
// If the CRD doesn't exist (e.g., in non-experimental environments), skip this step silently
79+
if !apierrors.IsNotFound(err) && !strings.Contains(err.Error(), "no matches for kind") {
80+
fmt.Printf("Failed to list cluster extension revisions: %v\n", err)
81+
}
7782
}
7883
for _, cer := range clusterExtensionRevisions.Items {
7984
// Save cluster extension to artifact path

test/e2e/cluster_extension_install_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
197197
t.Log("When a cluster extension is installed from a catalog")
198198

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

203204
defer TestCleanup(t, extensionCatalog, clusterExtension, sa, ns)
@@ -238,7 +239,9 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
238239
require.NotNil(ct, cond)
239240
require.Equal(ct, metav1.ConditionTrue, cond.Status)
240241
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]")
242+
require.Contains(ct, cond.Message, "in multiple catalogs with the same priority")
243+
require.Contains(ct, cond.Message, extensionCatalog.Name)
244+
require.Contains(ct, cond.Message, extraCatalog.Name)
242245
}, pollDuration, pollInterval)
243246
}
244247

@@ -441,7 +444,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
441444
// patch imageRef tag on test-catalog image with v2 image
442445
t.Log("By patching the catalog ImageRef to point to the v2 catalog")
443446
updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("CLUSTER_REGISTRY_HOST"))
444-
err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage)
447+
err := patchTestCatalog(context.Background(), extensionCatalog.Name, updatedCatalogImage)
445448
require.NoError(t, err)
446449
require.EventuallyWithT(t, func(ct *assert.CollectT) {
447450
require.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog))
@@ -474,8 +477,9 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
474477
require.NoError(t, err)
475478

476479
// create a test-catalog with latest image tag
480+
catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8))
477481
latestCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:latest", os.Getenv("CLUSTER_REGISTRY_HOST"))
478-
extensionCatalog, err := CreateTestCatalog(context.Background(), testCatalogName, latestCatalogImage)
482+
extensionCatalog, err := CreateTestCatalog(context.Background(), catalogName, latestCatalogImage)
479483
require.NoError(t, err)
480484
clusterExtensionName := fmt.Sprintf("clusterextension-%s", rand.String(8))
481485
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)