Skip to content

Commit

Permalink
Merge pull request #156 from weaveworks/fix-image-policy-tests
Browse files Browse the repository at this point in the history
Improve the ImagePolicy tests.
  • Loading branch information
bigkevmcd authored Dec 13, 2023
2 parents 8957456 + 5e83a83 commit 317333c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ help: ## Display this help.
##@ Development

.PHONY: manifests
manifests: api-docs controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
Expand Down
16 changes: 13 additions & 3 deletions tests/e2e/gitopsset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"testing"

imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
Expand Down Expand Up @@ -306,7 +307,7 @@ func TestReconcilingUpdatingImagePolicy(t *testing.T) {
test.AssertNoError(t, testEnv.Create(ctx, test.ToUnstructured(t, ip)))
defer deleteObject(t, testEnv, ip)

test.AssertNoError(t, testEnv.Get(ctx, client.ObjectKeyFromObject(ip), ip))
ip = waitForResource[*imagev1.ImagePolicy](t, testEnv, ip)
ip.Status.LatestImage = "testing/test:v0.30.0"
test.AssertNoError(t, testEnv.Status().Update(ctx, ip))

Expand Down Expand Up @@ -342,7 +343,7 @@ func TestReconcilingUpdatingImagePolicy(t *testing.T) {
test.AssertNoError(t, testEnv.Create(ctx, gs))
defer deleteGitOpsSetAndWaitForNotFound(t, testEnv, gs)

test.AssertNoError(t, testEnv.Get(ctx, client.ObjectKeyFromObject(ip), ip))
ip = waitForResource[*imagev1.ImagePolicy](t, testEnv, ip)
ip.Status.LatestImage = "testing/test:v0.31.0"
test.AssertNoError(t, testEnv.Status().Update(ctx, ip))

Expand Down Expand Up @@ -815,14 +816,23 @@ func waitForConfigMap(t *testing.T, k8sClient client.Client, src client.ObjectKe
g := gomega.NewWithT(t)
g.Eventually(func() map[string]string {
var cm corev1.ConfigMap
if err := testEnv.Get(ctx, src, &cm); err != nil {
if err := k8sClient.Get(ctx, src, &cm); err != nil {
return nil
}

return cm.Data
}, timeout).Should(gomega.Equal(want))
}

func waitForResource[T client.Object](t *testing.T, k8sClient client.Client, obj T) T {
g := gomega.NewWithT(t)
g.Eventually(func() error {
return k8sClient.Get(ctx, client.ObjectKeyFromObject(obj), obj)
}, timeout).Should(gomega.BeNil())

return obj
}

func waitForGitOpsSetInventory(t *testing.T, k8sClient client.Client, gs *templatesv1.GitOpsSet, objs ...runtime.Object) {
t.Helper()
g := gomega.NewWithT(t)
Expand Down

0 comments on commit 317333c

Please sign in to comment.