Skip to content

Commit 317333c

Browse files
authored
Merge pull request #156 from weaveworks/fix-image-policy-tests
Improve the ImagePolicy tests.
2 parents 8957456 + 5e83a83 commit 317333c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ help: ## Display this help.
4646
##@ Development
4747

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

5252
.PHONY: generate

tests/e2e/gitopsset_controller_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sort"
88
"testing"
99

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

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

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

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

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

822823
return cm.Data
823824
}, timeout).Should(gomega.Equal(want))
824825
}
825826

827+
func waitForResource[T client.Object](t *testing.T, k8sClient client.Client, obj T) T {
828+
g := gomega.NewWithT(t)
829+
g.Eventually(func() error {
830+
return k8sClient.Get(ctx, client.ObjectKeyFromObject(obj), obj)
831+
}, timeout).Should(gomega.BeNil())
832+
833+
return obj
834+
}
835+
826836
func waitForGitOpsSetInventory(t *testing.T, k8sClient client.Client, gs *templatesv1.GitOpsSet, objs ...runtime.Object) {
827837
t.Helper()
828838
g := gomega.NewWithT(t)

0 commit comments

Comments
 (0)