Skip to content

Commit

Permalink
fix(test): makes DSCI-dependent tests self-contained (opendatahub-io#…
Browse files Browse the repository at this point in the history
…1235)

Ensures each tests uses different DSCI instance as a test fixture.
Without this tests are failing (as they do in latest incubation commit),
as opendatahub-io#1222 introduced validation check to ensure AppNamespace is
immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint.

With this change each test uses dedicated DSCI.

(cherry picked from commit df1add0)
  • Loading branch information
bartoszmajsak authored and VaishnaviHire committed Sep 16, 2024
1 parent ce46787 commit 371af7f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/envtestutil/name_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func AppendRandomNameTo(base string) string {
if len(base) > maxGeneratedNameLength {
base = base[:maxGeneratedNameLength]
}
return fmt.Sprintf("%s%s", base, utilrand.String(randomLength))
return fmt.Sprintf("%s-%s", base, utilrand.String(randomLength))
}
18 changes: 13 additions & 5 deletions tests/integration/features/cleanup_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ var _ = Describe("feature cleanup", func() {
)

var (
dsci *dsciv1.DSCInitialization
namespace string
testFeature *feature.Feature
dsci *dsciv1.DSCInitialization
namespace string
testFeature *feature.Feature
objectCleaner *envtestutil.Cleaner
)

BeforeEach(func(ctx context.Context) {
objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval)
namespace = envtestutil.AppendRandomNameTo("test-secret-ownership")
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace)
dsciName := envtestutil.AppendRandomNameTo("secret-dsci")
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace)
var errSecretCreation error
testFeature, errSecretCreation = feature.Define(featureName).
TargetNamespace(dsci.Spec.ApplicationsNamespace).
Expand All @@ -54,6 +57,10 @@ var _ = Describe("feature cleanup", func() {

})

AfterEach(func(ctx context.Context) {
objectCleaner.DeleteAll(ctx, dsci)
})

It("should successfully create resource and associated feature tracker", func(ctx context.Context) {
// when
Expect(testFeature.Apply(ctx)).Should(Succeed())
Expand Down Expand Up @@ -95,7 +102,8 @@ var _ = Describe("feature cleanup", func() {

BeforeAll(func(ctx context.Context) {
namespace = envtestutil.AppendRandomNameTo("test-conditional-cleanup")
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace)
dsciName := envtestutil.AppendRandomNameTo("cleanup-dsci")
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace)
})

It("should create feature, apply resource and create feature tracker", func(ctx context.Context) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/features/fixtures/cluster_test_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ func GetFeatureTracker(ctx context.Context, cli client.Client, appNamespace, fea
return tracker, err
}

func NewDSCInitialization(ctx context.Context, cli client.Client, ns string) *dsciv1.DSCInitialization {
func NewDSCInitialization(ctx context.Context, cli client.Client, dsciName, ns string) *dsciv1.DSCInitialization {
dsci := &dsciv1.DSCInitialization{
TypeMeta: metav1.TypeMeta{
APIVersion: gvk.DSCInitialization.Version,
Kind: gvk.DSCInitialization.Kind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "default-dsci",
Name: dsciName,
},
}

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/features/manifests_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ var _ = Describe("Applying resources", func() {

BeforeEach(func(ctx context.Context) {
objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval)
nsName := envtestutil.AppendRandomNameTo("smcp-ns")
nsName := envtestutil.AppendRandomNameTo("ns-smcp")
dsciName := envtestutil.AppendRandomNameTo("dsci-smcp")

var err error
namespace, err = cluster.CreateNamespace(ctx, envTestClient, nsName)
Expect(err).ToNot(HaveOccurred())

dsci = fixtures.NewDSCInitialization(ctx, envTestClient, nsName)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, nsName)
dsci.Spec.ServiceMesh.ControlPlane.Namespace = namespace.Name
})

AfterEach(func(ctx context.Context) {
objectCleaner.DeleteAll(ctx, namespace)
objectCleaner.DeleteAll(ctx, namespace, dsci)
})

It("should be able to process an embedded YAML file", func(ctx context.Context) {
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/features/preconditions_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ var _ = Describe("feature preconditions", func() {

testFeatureName := "test-ns-creation"
namespace = envtestutil.AppendRandomNameTo(testFeatureName)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace)
dsciName := envtestutil.AppendRandomNameTo(testFeatureName)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace)
})

AfterEach(func(ctx context.Context) {
objectCleaner.DeleteAll(ctx, dsci)
})

It("should create namespace if it does not exist", func(ctx context.Context) {
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/features/resources_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ var _ = Describe("Applying and updating resources", func() {
objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval)

testNamespace = envtestutil.AppendRandomNameTo("test-namespace")
dsciName := envtestutil.AppendRandomNameTo("test-dsci")

var err error
namespace, err = cluster.CreateNamespace(ctx, envTestClient, testNamespace)
Expect(err).ToNot(HaveOccurred())

dsci = fixtures.NewDSCInitialization(ctx, envTestClient, testNamespace)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, testNamespace)
dsci.Spec.ServiceMesh.ControlPlane.Namespace = namespace.Name
})

AfterEach(func(ctx context.Context) {
objectCleaner.DeleteAll(ctx, namespace)
objectCleaner.DeleteAll(ctx, namespace, dsci)
})

When("a feature is managed", func() {
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/features/serverless_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ var _ = Describe("Serverless feature", func() {
Expect(err).ToNot(HaveOccurred())
objectCleaner = envtestutil.CreateCleaner(c, envTest.Config, fixtures.Timeout, fixtures.Interval)

dsci = fixtures.NewDSCInitialization(ctx, envTestClient, "default")
namespace := envtestutil.AppendRandomNameTo("ns-serverless")
dsciName := envtestutil.AppendRandomNameTo("dsci-serverless")
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace)
kserveComponent = &kserve.Kserve{}
})

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/features/servicemesh_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ var _ = Describe("Service Mesh setup", func() {
objectCleaner = envtestutil.CreateCleaner(c, envTest.Config, fixtures.Timeout, fixtures.Interval)

namespace := envtestutil.AppendRandomNameTo("service-mesh-settings")
dsciName := envtestutil.AppendRandomNameTo("service-mesh-settings")

dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace)

Expect(err).ToNot(HaveOccurred())
})
Expand Down Expand Up @@ -172,7 +173,7 @@ var _ = Describe("Service Mesh setup", func() {
BeforeEach(func(ctx context.Context) {
smcpCrdObj = installServiceMeshCRD(ctx)
objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, envtestutil.AppendRandomNameTo(namespace), namespace)

serviceMeshSpec = dsci.Spec.ServiceMesh

Expand Down
14 changes: 8 additions & 6 deletions tests/integration/features/tracker_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/tests/envtestutil"
"github.com/opendatahub-io/opendatahub-operator/v2/tests/integration/features/fixtures"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -20,14 +21,15 @@ import (

var _ = Describe("Feature tracking capability", func() {

const appNamespace = "default"

var (
dsci *dsciv1.DSCInitialization
appNamespace string
dsci *dsciv1.DSCInitialization
)

BeforeEach(func(ctx context.Context) {
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, "default")
appNamespace = envtestutil.AppendRandomNameTo("app-namespace")
dsciName := envtestutil.AppendRandomNameTo("dsci-" + appNamespace)
dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, appNamespace)
})

Context("Reporting progress when applying Feature", func() {
Expand Down Expand Up @@ -138,7 +140,7 @@ var _ = Describe("Feature tracking capability", func() {
Expect(err).ToNot(HaveOccurred())
Expect(featureTracker.Spec.Source).To(
MatchFields(IgnoreExtras, Fields{
"Name": Equal("default-dsci"),
"Name": Equal(dsci.Name),
"Type": Equal(featurev1.DSCIType),
}),
)
Expand All @@ -160,7 +162,7 @@ var _ = Describe("Feature tracking capability", func() {
// then
featureTracker, err := fixtures.GetFeatureTracker(ctx, envTestClient, appNamespace, "empty-feature")
Expect(err).ToNot(HaveOccurred())
Expect(featureTracker.Spec.AppNamespace).To(Equal("default"))
Expect(featureTracker.Spec.AppNamespace).To(Equal(dsci.Spec.ApplicationsNamespace))
})

})
Expand Down

0 comments on commit 371af7f

Please sign in to comment.