Skip to content

Commit

Permalink
test: add more negative test
Browse files Browse the repository at this point in the history
- when CRD does not exist
- when service does not exist

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Nov 11, 2024
1 parent 1f564f0 commit 652e06b
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions tests/integration/features/servicemesh_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ var _ = Describe("Service Mesh setup", func() {

Context("operator setup", func() {

When("operator is not installed", func() {
Context("operator is not installed", Ordered, func() {

It("should fail using precondition check", func(ctx context.Context) {
var smcpCrdObj *apiextensionsv1.CustomResourceDefinition

It("should fail using precondition subscription check", func(ctx context.Context) {
// given
featuresHandler := feature.ClusterFeaturesHandler(dsci, func(registry feature.FeaturesRegistry) error {
errFeatureAdd := registry.Add(feature.Define("no-service-mesh-operator-check").
Expand All @@ -70,6 +72,53 @@ var _ = Describe("Service Mesh setup", func() {
// then
Expect(applyErr).To(MatchError(ContainSubstring("failed to find the pre-requisite operator subscription \"servicemeshoperator\"")))
})

It("should fail using precondition CRD check", func(ctx context.Context) {
// given
err := fixtures.CreateSubscription(ctx, envTestClient, "openshift-operators", fixtures.OssmSubscription)
Expect(err).ToNot(HaveOccurred())

featuresHandler := feature.ClusterFeaturesHandler(dsci, func(registry feature.FeaturesRegistry) error {
errFeatureAdd := registry.Add(feature.Define("no-service-mesh-crd-check").
PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled),
)

Expect(errFeatureAdd).ToNot(HaveOccurred())

return nil
})

// when
applyErr := featuresHandler.Apply(ctx, envTestClient)

// then
Expect(applyErr).To(MatchError(ContainSubstring("failed to find the Service Mesh Control Plane CRD")))
})

It("should fail using precondition service check", func(ctx context.Context) {
// given
smcpCrdObj = installServiceMeshCRD(ctx)

featuresHandler := feature.ClusterFeaturesHandler(dsci, func(registry feature.FeaturesRegistry) error {
errFeatureAdd := registry.Add(feature.Define("no-service-mesh-service-check").
PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled),
)

Expect(errFeatureAdd).ToNot(HaveOccurred())

return nil
})

// when
applyErr := featuresHandler.Apply(ctx, envTestClient)

// then
Expect(applyErr).To(MatchError(ContainSubstring("failed to find the Service Mesh VWC service")))
})

AfterAll(func(ctx context.Context) {
objectCleaner.DeleteAll(ctx, smcpCrdObj)
})
})

When("operator is installed", func() {
Expand All @@ -79,6 +128,7 @@ var _ = Describe("Service Mesh setup", func() {
BeforeEach(func(ctx context.Context) {
err := fixtures.CreateSubscription(ctx, envTestClient, "openshift-operators", fixtures.OssmSubscription)
Expect(err).ToNot(HaveOccurred())

smcpCrdObj = installServiceMeshCRD(ctx)

svc, err = fixtures.CreateService(ctx, envTestClient, "openshift-operators", "istio-operator-service")
Expand Down

0 comments on commit 652e06b

Please sign in to comment.