Skip to content

Commit

Permalink
Fix some unit test failing with Flux 2.3 (#4226)
Browse files Browse the repository at this point in the history
* ci(test): bump Ginkgo and envTest versions

* test: migrate TestUpdateNamespaces to Flux 2.3

* test: migrate TestGetObjectSessionObjects to Flux 2.3
  • Loading branch information
erikgb authored Nov 22, 2024
1 parent 9955cbb commit c2e7f34
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ TEST_TO_RUN?=./...
TEST_V?=-v
##@ Test
unit-tests: ## Run unit tests
@go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.3
@go install github.com/onsi/ginkgo/v2/ginkgo@v2.19.0
# This tool doesn't have releases - it also is only a shim
@go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
KUBEBUILDER_ASSETS=$$(setup-envtest use -p path 1.24.2) CGO_ENABLED=0 ginkgo $(TEST_V) -tags unittest $(TEST_TO_RUN)
KUBEBUILDER_ASSETS=$$(setup-envtest use -p path 1.31.0) CGO_ENABLED=0 ginkgo $(TEST_V) -tags unittest $(TEST_TO_RUN)

local-kind-cluster-with-registry:
./tools/kind-with-registry.sh
Expand Down
7 changes: 5 additions & 2 deletions core/clustersmngr/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ func TestUpdateNamespaces(t *testing.T) {
clustersFetcher.FetchReturns([]cluster.Cluster{c1, c2, c3}, nil)

g.Expect(clustersManager.UpdateClusters(ctx)).To(Succeed())
g.Expect(clustersManager.UpdateNamespaces(ctx)).To(MatchError(MatchRegexp("failed creating server client to pool.*cluster: %s.*", clusterName3)))
g.Expect(clustersManager.UpdateNamespaces(ctx)).To(MatchError(MatchRegexp("Failed to list resource on cluster=\"%s\".*", clusterName3)))
contents := clustersManager.GetClustersNamespaces()

g.Expect(contents).To(HaveLen(2))
// TODO(Flux 2.3 migration): Apparently a change in behavior. Check if more needs to be updated.
g.Expect(contents).To(HaveLen(3))
g.Expect(contents).To(HaveKeyWithValue(clusterName3, BeNil()))
// g.Expect(contents).To(HaveLen(2))
g.Expect(contents).To(HaveKey(clusterName1))
g.Expect(contents).To(HaveKey(clusterName2))
})
Expand Down
8 changes: 3 additions & 5 deletions core/server/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"encoding/json"
"testing"

sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"

helmv2 "github.com/fluxcd/helm-controller/api/v2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
Expand Down Expand Up @@ -929,12 +927,12 @@ func TestGetObjectSessionObjects(t *testing.T) {
Spec: helmv2.HelmReleaseSpec{},
}

bucket := &sourcev1b2.Bucket{
bucket := &sourcev1.Bucket{
ObjectMeta: metav1.ObjectMeta{
Name: constants.RunDevBucketName,
Namespace: testNS,
},
Spec: sourcev1b2.BucketSpec{},
Spec: sourcev1.BucketSpec{},
}

fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(ns, kust, helm, bucket).Build()
Expand Down Expand Up @@ -966,7 +964,7 @@ func TestGetObjectSessionObjects(t *testing.T) {
res, err = c.GetObject(ctx, &pb.GetObjectRequest{
Name: constants.RunDevBucketName,
Namespace: testNS,
Kind: sourcev1b2.BucketKind,
Kind: sourcev1.BucketKind,
ClusterName: testCluster,
})

Expand Down

0 comments on commit c2e7f34

Please sign in to comment.