Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the ImagePolicy tests. #156

Merged
merged 1 commit into from
Dec 13, 2023
Merged
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 @@ -46,7 +46,7 @@ help: ## Display this help.
##@ Development

.PHONY: manifests
manifests: api-docs controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked for me after rm bin/gen-crd-api-reference-docs from the gs path.

But not sure why/what happened.

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
Loading