From d90f42ecf732967630158ed65378e14a6b02d9d6 Mon Sep 17 00:00:00 2001 From: zoumo Date: Wed, 17 Jan 2024 15:35:01 +0800 Subject: [PATCH] fix ut --- Makefile | 4 ++-- cache/cache_test.go | 4 ---- multicluster/manager_test.go | 5 +++-- multicluster/multi_cluster_client.go | 8 ++++---- multicluster/suite_test.go | 16 ++++++---------- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index f3cd1e2..fb8853f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.22.1 +ENVTEST_K8S_VERSION = 1.24.1 .PHONY: fmt fmt: ## Run go fmt against code. @@ -25,4 +25,4 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) - test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest \ No newline at end of file + test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest diff --git a/cache/cache_test.go b/cache/cache_test.go index 8209dff..b4f5592 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -19,7 +19,6 @@ package cache import ( "context" "fmt" - "net/url" "testing" "time" @@ -186,9 +185,6 @@ func TestCache(t *testing.T) { var _ = BeforeSuite(func() { env = &envtest.Environment{} - env.ControlPlane.GetAPIServer().URL = &url.URL{ - Host: "127.0.0.1:65221", - } config, err := env.Start() Expect(err).NotTo(HaveOccurred()) diff --git a/multicluster/manager_test.go b/multicluster/manager_test.go index 0528a54..72c643d 100644 --- a/multicluster/manager_test.go +++ b/multicluster/manager_test.go @@ -183,9 +183,10 @@ var _ = Describe("multicluster with 1 fed and 4 clusters", func() { }) It("multiClusterClient get server groups and resources", func() { - serverGroupsAndResourcesClient, ok := clusterClient.(PartialCachedDiscoveryInterface) + mcdiscovery, ok := clusterClient.(MultiClusterDiscovery) Expect(ok).To(Equal(true)) - apiGroups, apiResourceLists, err := serverGroupsAndResourcesClient.ServerGroupsAndResources() + cachedDiscoveryClient := mcdiscovery.MembersCachedDiscoveryInterface() + apiGroups, apiResourceLists, err := cachedDiscoveryClient.ServerGroupsAndResources() Expect(err).NotTo(HaveOccurred()) groupVersionSets := sets.NewString() diff --git a/multicluster/multi_cluster_client.go b/multicluster/multi_cluster_client.go index 613e4c6..1216c91 100644 --- a/multicluster/multi_cluster_client.go +++ b/multicluster/multi_cluster_client.go @@ -38,8 +38,8 @@ import ( // MultiClusterDiscovery provides fed and member clusters discovery interface type MultiClusterDiscovery interface { - GetFedDiscoveryInterface() discovery.DiscoveryInterface - GetMembersCachedDiscoveryInterface() PartialCachedDiscoveryInterface + FedDiscoveryInterface() discovery.DiscoveryInterface + MembersCachedDiscoveryInterface() PartialCachedDiscoveryInterface } // PartialCachedDiscoveryInterface is a subset of discovery.DiscoveryInterface. @@ -466,11 +466,11 @@ func (mcc *multiClusterClient) getClusterNames(ctx context.Context) (clusters [] return } -func (mcc *multiClusterClient) GetFedDiscoveryInterface() discovery.DiscoveryInterface { +func (mcc *multiClusterClient) FedDiscoveryInterface() discovery.DiscoveryInterface { return mcc.fedDiscovery } -func (mcc *multiClusterClient) GetMembersCachedDiscoveryInterface() PartialCachedDiscoveryInterface { +func (mcc *multiClusterClient) MembersCachedDiscoveryInterface() PartialCachedDiscoveryInterface { return &cachedMultiClusterDiscoveryClient{ delegate: mcc, } diff --git a/multicluster/suite_test.go b/multicluster/suite_test.go index 3db3f0c..62407a6 100644 --- a/multicluster/suite_test.go +++ b/multicluster/suite_test.go @@ -18,7 +18,6 @@ package multicluster import ( "context" - "net/url" "os" "testing" "time" @@ -76,9 +75,8 @@ var _ = BeforeSuite(func() { fedEnv = &envtest.Environment{ Scheme: fedScheme, } - fedEnv.ControlPlane.GetAPIServer().URL = &url.URL{ - Host: "127.0.0.1:10001", - } + fedEnv.ControlPlane.GetAPIServer().SecureServing.Address = "127.0.0.1" + fedEnv.ControlPlane.GetAPIServer().SecureServing.Port = "10001" fedConfig, err := fedEnv.Start() Expect(err).NotTo(HaveOccurred()) Expect(fedConfig).NotTo(BeNil()) @@ -97,9 +95,8 @@ var _ = BeforeSuite(func() { clusterEnv1 = &envtest.Environment{ Scheme: clusterScheme, } - clusterEnv1.ControlPlane.GetAPIServer().URL = &url.URL{ - Host: "127.0.0.1:10002", - } + clusterEnv1.ControlPlane.GetAPIServer().SecureServing.Address = "127.0.0.1" + clusterEnv1.ControlPlane.GetAPIServer().SecureServing.Port = "10002" clusterConfig1, err := clusterEnv1.Start() Expect(err).NotTo(HaveOccurred()) Expect(clusterConfig1).NotTo(BeNil()) @@ -112,9 +109,8 @@ var _ = BeforeSuite(func() { clusterEnv2 = &envtest.Environment{ Scheme: clusterScheme, } - clusterEnv2.ControlPlane.GetAPIServer().URL = &url.URL{ - Host: "127.0.0.1:10003", - } + clusterEnv2.ControlPlane.GetAPIServer().SecureServing.Address = "127.0.0.1" + clusterEnv2.ControlPlane.GetAPIServer().SecureServing.Port = "10003" clusterConfig2, err := clusterEnv2.Start() Expect(err).NotTo(HaveOccurred()) Expect(clusterConfig2).NotTo(BeNil())