Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ build: generate fmt vet ## Build manager binary.

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
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
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

.PHONY: docker-build
docker-build: test ## Build container image with the manager.
Expand Down
37 changes: 37 additions & 0 deletions test/openshift/e2e/ginkgo/fixture/application/fixture.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package application

import (
"fmt"
"regexp"

. "github.com/onsi/gomega"
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -83,6 +86,40 @@ func HaveSyncStatusCode(expected appv1alpha1.SyncStatusCode) matcher.GomegaMatch

}

func HaveNoConditions() matcher.GomegaMatcher {
return expectedCondition(func(app *appv1alpha1.Application) bool {
count := len(app.Status.Conditions)
if count == 0 {
return true
}

GinkgoWriter.Printf("HaveNoConditions - have: %+v\n", app.Status.Conditions)
return false
})
}

func HaveConditionMatching(conditionType appv1alpha1.ApplicationConditionType, messagePattern string) matcher.GomegaMatcher {
pattern := regexp.MustCompile(messagePattern)

return expectedCondition(func(app *appv1alpha1.Application) bool {
conditions := app.Status.Conditions
var found []string
for _, condition := range conditions {
found = append(found, fmt.Sprintf(" - %s/%s", condition.Type, condition.Message))

if condition.Type == conditionType && pattern.MatchString(condition.Message) {
return true
}
}

GinkgoWriter.Printf("HaveConditionMatching - expected: %s/%s; current(%d):\n", conditionType, messagePattern, len(conditions))
for _, f := range found {
GinkgoWriter.Println(f)
}
return false
})
}

// Update will keep trying to update object until it succeeds, or times out.
func Update(obj *appv1alpha1.Application, modify func(*appv1alpha1.Application)) {
k8sClient, _ := utils.GetE2ETestKubeClient()
Expand Down
13 changes: 7 additions & 6 deletions test/openshift/e2e/ginkgo/fixture/argocd/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,33 @@ func HaveExternalAuthenticationCondition(expected metav1.Condition) matcher.Gome
func HaveCondition(condition metav1.Condition) matcher.GomegaMatcher {
return fetchArgoCD(func(argocd *argov1beta1api.ArgoCD) bool {

if len(argocd.Status.Conditions) != 1 {
GinkgoWriter.Println("HaveCondition: length is zero")
length := len(argocd.Status.Conditions)
if length != 1 {
GinkgoWriter.Printf("HaveCondition: length is %d\n", length)
return false
}

instanceCondition := argocd.Status.Conditions[0]

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

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

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

GinkgoWriter.Println("HaveCondition - Type:", instanceCondition.Type, condition.Type)
GinkgoWriter.Printf("HaveCondition - Type: '%s' / actual: '%s'\n", condition.Type, instanceCondition.Type)
if instanceCondition.Type != condition.Type {
GinkgoWriter.Println("HaveCondition: type does not match")
return false
Expand Down
8 changes: 8 additions & 0 deletions test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clusterrole

import (
"context"
"reflect"

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

}

func HaveRules(expectedRules []rbacv1.PolicyRule) matcher.GomegaMatcher {
return fetchRole(func(cr *rbacv1.ClusterRole) bool {
GinkgoWriter.Println("HaveRules - Expected:", expectedRules, "/ Actual:", cr.Rules)
return reflect.DeepEqual(expectedRules, cr.Rules)
})
}

// This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that.
//
//nolint:unused
Expand Down
22 changes: 15 additions & 7 deletions test/openshift/e2e/ginkgo/fixture/k8s/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ func NotHaveLabelWithValue(key string, value string) matcher.GomegaMatcher {
// ExistByName checks if the given k8s resource exists, when retrieving it by name/namespace.
// - It does NOT check if the resource content matches. It only checks that a resource of that type and name exists.
func ExistByName() matcher.GomegaMatcher {
return ExistByNameWithClient(nil)
}

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

err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
return WithTransform(func(k8sObject client.Object) bool {
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
if err != nil {
GinkgoWriter.Println("Object does not exists in ExistByName:", k8sObject.GetName(), err)
} else {
Expand Down
Loading
Loading