Skip to content

Commit ffcaf3a

Browse files
authored
chore: sync upstream e2e tests to downstream (#1104)
Signed-off-by: Jonathan West <jgwest@gmail.com>
1 parent 853f0f4 commit ffcaf3a

9 files changed

Lines changed: 1026 additions & 24 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ build: generate fmt vet ## Build manager binary.
211211

212212
.PHONY: run
213213
run: manifests generate fmt vet ## Run a controller from your host.
214-
CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES="openshift-gitops, argocd-e2e-cluster-config, argocd-test-impersonation-1-046, argocd-agent-principal-1-051, argocd-agent-agent-1-052, appset-argocd, appset-old-ns, appset-new-ns, ns-hosting-principal, ns-hosting-managed-agent, ns-hosting-autonomous-agent" REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go
214+
CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES="openshift-gitops, argocd-e2e-cluster-config, argocd-test-impersonation-1-046, argocd-agent-principal-1-051, argocd-agent-agent-1-052, appset-argocd, appset-old-ns, appset-new-ns, ns-hosting-principal, ns-hosting-managed-agent, ns-hosting-autonomous-agent, appset-argocd-clusterrole" REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go
215215

216216
.PHONY: docker-build
217217
docker-build: test ## Build container image with the manager.

test/openshift/e2e/ginkgo/fixture/application/fixture.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package application
22

33
import (
4+
"fmt"
5+
"regexp"
6+
47
. "github.com/onsi/gomega"
58
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
69
"k8s.io/client-go/util/retry"
@@ -83,6 +86,40 @@ func HaveSyncStatusCode(expected appv1alpha1.SyncStatusCode) matcher.GomegaMatch
8386

8487
}
8588

89+
func HaveNoConditions() matcher.GomegaMatcher {
90+
return expectedCondition(func(app *appv1alpha1.Application) bool {
91+
count := len(app.Status.Conditions)
92+
if count == 0 {
93+
return true
94+
}
95+
96+
GinkgoWriter.Printf("HaveNoConditions - have: %+v\n", app.Status.Conditions)
97+
return false
98+
})
99+
}
100+
101+
func HaveConditionMatching(conditionType appv1alpha1.ApplicationConditionType, messagePattern string) matcher.GomegaMatcher {
102+
pattern := regexp.MustCompile(messagePattern)
103+
104+
return expectedCondition(func(app *appv1alpha1.Application) bool {
105+
conditions := app.Status.Conditions
106+
var found []string
107+
for _, condition := range conditions {
108+
found = append(found, fmt.Sprintf(" - %s/%s", condition.Type, condition.Message))
109+
110+
if condition.Type == conditionType && pattern.MatchString(condition.Message) {
111+
return true
112+
}
113+
}
114+
115+
GinkgoWriter.Printf("HaveConditionMatching - expected: %s/%s; current(%d):\n", conditionType, messagePattern, len(conditions))
116+
for _, f := range found {
117+
GinkgoWriter.Println(f)
118+
}
119+
return false
120+
})
121+
}
122+
86123
// Update will keep trying to update object until it succeeds, or times out.
87124
func Update(obj *appv1alpha1.Application, modify func(*appv1alpha1.Application)) {
88125
k8sClient, _ := utils.GetE2ETestKubeClient()

test/openshift/e2e/ginkgo/fixture/argocd/fixture.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,32 +191,33 @@ func HaveExternalAuthenticationCondition(expected metav1.Condition) matcher.Gome
191191
func HaveCondition(condition metav1.Condition) matcher.GomegaMatcher {
192192
return fetchArgoCD(func(argocd *argov1beta1api.ArgoCD) bool {
193193

194-
if len(argocd.Status.Conditions) != 1 {
195-
GinkgoWriter.Println("HaveCondition: length is zero")
194+
length := len(argocd.Status.Conditions)
195+
if length != 1 {
196+
GinkgoWriter.Printf("HaveCondition: length is %d\n", length)
196197
return false
197198
}
198199

199200
instanceCondition := argocd.Status.Conditions[0]
200201

201-
GinkgoWriter.Println("HaveCondition - Message:", instanceCondition.Message, condition.Message)
202+
GinkgoWriter.Printf("HaveCondition - Message: '%s' / actual: '%s'\n", condition.Message, instanceCondition.Message)
202203
if instanceCondition.Message != condition.Message {
203204
GinkgoWriter.Println("HaveCondition: message does not match")
204205
return false
205206
}
206207

207-
GinkgoWriter.Println("HaveCondition - Reason:", instanceCondition.Reason, condition.Reason)
208+
GinkgoWriter.Printf("HaveCondition - Reason: '%s' / actual: '%s'\n", condition.Reason, instanceCondition.Reason)
208209
if instanceCondition.Reason != condition.Reason {
209210
GinkgoWriter.Println("HaveCondition: reason does not match")
210211
return false
211212
}
212213

213-
GinkgoWriter.Println("HaveCondition - Status:", instanceCondition.Status, condition.Status)
214+
GinkgoWriter.Printf("HaveCondition - Status: '%s' / actual: '%s'\n", condition.Status, instanceCondition.Status)
214215
if instanceCondition.Status != condition.Status {
215216
GinkgoWriter.Println("HaveCondition: status does not match")
216217
return false
217218
}
218219

219-
GinkgoWriter.Println("HaveCondition - Type:", instanceCondition.Type, condition.Type)
220+
GinkgoWriter.Printf("HaveCondition - Type: '%s' / actual: '%s'\n", condition.Type, instanceCondition.Type)
220221
if instanceCondition.Type != condition.Type {
221222
GinkgoWriter.Println("HaveCondition: type does not match")
222223
return false

test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package clusterrole
22

33
import (
44
"context"
5+
"reflect"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
@@ -32,6 +33,13 @@ func Update(obj *rbacv1.ClusterRole, modify func(*rbacv1.ClusterRole)) {
3233

3334
}
3435

36+
func HaveRules(expectedRules []rbacv1.PolicyRule) matcher.GomegaMatcher {
37+
return fetchRole(func(cr *rbacv1.ClusterRole) bool {
38+
GinkgoWriter.Println("HaveRules - Expected:", expectedRules, "/ Actual:", cr.Rules)
39+
return reflect.DeepEqual(expectedRules, cr.Rules)
40+
})
41+
}
42+
3543
// This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that.
3644
//
3745
//nolint:unused

test/openshift/e2e/ginkgo/fixture/k8s/fixture.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,23 @@ func NotHaveLabelWithValue(key string, value string) matcher.GomegaMatcher {
9898
// ExistByName checks if the given k8s resource exists, when retrieving it by name/namespace.
9999
// - It does NOT check if the resource content matches. It only checks that a resource of that type and name exists.
100100
func ExistByName() matcher.GomegaMatcher {
101+
return ExistByNameWithClient(nil)
102+
}
101103

102-
return WithTransform(func(k8sObject client.Object) bool {
103-
k8sClient, _, err := utils.GetE2ETestKubeClientWithError()
104-
if err != nil {
105-
GinkgoWriter.Println(err)
106-
return false
107-
}
104+
// ExistByNameWithClient checks if the given k8s resource exists, when retrieving it by name/namespace.
105+
// - It does NOT check if the resource content matches. It only checks that a resource of that type and name exists.
106+
//
107+
// NOTE: you probably want to instead use ExistByName()
108+
func ExistByNameWithClient(k8sClient client.Client) matcher.GomegaMatcher {
109+
if k8sClient == nil {
110+
var err error
111+
k8sClient, _, err = utils.GetE2ETestKubeClientWithError()
112+
Expect(err).ToNot(HaveOccurred())
113+
Expect(k8sClient).ShouldNot(BeNil())
114+
}
108115

109-
err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
116+
return WithTransform(func(k8sObject client.Object) bool {
117+
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
110118
if err != nil {
111119
GinkgoWriter.Println("Object does not exists in ExistByName:", k8sObject.GetName(), err)
112120
} else {

0 commit comments

Comments
 (0)