Skip to content

Commit 1bd6544

Browse files
author
Per Goncalves da Silva
committed
Add uninstall feature test
Signed-off-by: Per G. da Silva <pegoncal@redhat.com>
1 parent 8167ff8 commit 1bd6544

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Uninstall ClusterExtension
2+
3+
As an OLM user I would like to uninstall a cluster extension.
4+
5+
Background:
6+
Given OLM is available
7+
And ClusterCatalog "test" serves bundles
8+
And ServiceAccount "olm-sa" with needed permissions is available in ${TEST_NAMESPACE}
9+
And ClusterExtension is applied
10+
"""
11+
apiVersion: olm.operatorframework.io/v1
12+
kind: ClusterExtension
13+
metadata:
14+
name: ${NAME}
15+
spec:
16+
namespace: ${TEST_NAMESPACE}
17+
serviceAccount:
18+
name: olm-sa
19+
source:
20+
sourceType: Catalog
21+
catalog:
22+
packageName: test
23+
selector:
24+
matchLabels:
25+
"olm.operatorframework.io/metadata.name": test-catalog
26+
"""
27+
And bundle "test-operator.1.2.0" is installed in version "1.2.0"
28+
29+
Scenario: Uninstall ClusterExtension
30+
When resource "clusterextension/${NAME}" is removed
31+
Then resource "networkpolicy/test-operator-network-policy" is eventually not found
32+
And resource "configmap/test-configmap" is eventually not found
33+
And resource "deployment/test-operator" is eventually not found
34+
And resource "clusterrole/testoperator.v1.2.-37mym6pni2xxmai9n7fmhtbn9i348lx7o619rmf3ypio" is eventually not found
35+
And resource "clusterrole/testoperator.v1.2.0-t88i5epjh8oxp4klplhjyrsekwcp92b27w03ayr1ku5" is eventually not found
36+
And resource "clusterrolebinding/testoperator.v1.2.-37mym6pni2xxmai9n7fmhtbn9i348lx7o619rmf3ypio" is eventually not found
37+
And resource "clusterrolebinding/testoperator.v1.2.0-t88i5epjh8oxp4klplhjyrsekwcp92b27w03ayr1ku5" is eventually not found

test/e2e/steps/steps.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func RegisterSteps(sc *godog.ScenarioContext) {
6868
sc.Step(`^(?i)resource "([^"]+)" is installed$`, ResourceAvailable)
6969
sc.Step(`^(?i)resource "([^"]+)" is available$`, ResourceAvailable)
7070
sc.Step(`^(?i)resource "([^"]+)" is removed$`, ResourceRemoved)
71+
sc.Step(`^(?i)resource "([^"]+)" is eventually not found$`, ResourceEventuallyNotFound)
7172
sc.Step(`^(?i)resource "([^"]+)" exists$`, ResourceAvailable)
7273
sc.Step(`^(?i)resource is applied$`, ResourceIsApplied)
7374
sc.Step(`^(?i)resource "deployment/test-operator" reports as (not ready|ready)$`, MarkTestOperatorNotReady)
@@ -411,6 +412,7 @@ func ResourceAvailable(ctx context.Context, resource string) error {
411412

412413
func ResourceRemoved(ctx context.Context, resource string) error {
413414
sc := scenarioCtx(ctx)
415+
resource = substituteScenarioVars(resource, sc)
414416
rtype, name, found := strings.Cut(resource, "/")
415417
if !found {
416418
return fmt.Errorf("resource %s is not in the format <type>/<name>", resource)
@@ -428,6 +430,21 @@ func ResourceRemoved(ctx context.Context, resource string) error {
428430
return err
429431
}
430432

433+
func ResourceEventuallyNotFound(ctx context.Context, resource string) error {
434+
sc := scenarioCtx(ctx)
435+
resource = substituteScenarioVars(resource, sc)
436+
rtype, name, found := strings.Cut(resource, "/")
437+
if !found {
438+
return fmt.Errorf("resource %s is not in the format <type>/<name>", resource)
439+
}
440+
441+
require.Eventually(godog.T(ctx), func() bool {
442+
obj, err := k8sClient("get", rtype, name, "-n", sc.namespace, "--ignore-not-found", "-o", "yaml")
443+
return err == nil && obj == ""
444+
}, timeout, tick)
445+
return nil
446+
}
447+
431448
func ResourceMatches(ctx context.Context, resource string, requiredContentTemplate *godog.DocString) error {
432449
sc := scenarioCtx(ctx)
433450
resource = substituteScenarioVars(resource, sc)
@@ -468,6 +485,7 @@ func ResourceMatches(ctx context.Context, resource string, requiredContentTempla
468485

469486
func ResourceRestored(ctx context.Context, resource string) error {
470487
sc := scenarioCtx(ctx)
488+
resource = substituteScenarioVars(resource, sc)
471489
rtype, name, found := strings.Cut(resource, "/")
472490
if !found {
473491
return fmt.Errorf("resource %s is not in the format <type>/<name>", resource)

0 commit comments

Comments
 (0)