From 3fcd0496e9a7803a243cb7e3f42ab2af51e8b781 Mon Sep 17 00:00:00 2001 From: Bhargav Ravuri Date: Tue, 5 Mar 2024 13:15:41 +0530 Subject: [PATCH] tests(integration): Move integration tests to `tests/` Signed-off-by: Bhargav Ravuri --- Makefile | 25 ++++-- ...gister_unit_test.go => deregister_test.go} | 87 +++++-------------- ...nciler_unit_test.go => reconciler_test.go} | 4 +- ..._unit_test.go => slice_controller_test.go} | 0 ...nciler_unit_test.go => reconciler_test.go} | 2 + pkg/manifest/manifest_suite_test.go | 31 ------- pkg/webhook/pod/pod_suite_test.go | 31 ------- test.Dockerfile | 2 +- .../hub}/cluster/cluster_controller_test.go | 0 .../hub}/cluster/cluster_suite_test.go | 5 +- .../crds/hub.kubeslice.io_clusters.yaml | 0 ...ntroller.kubeslice.io_vpnkeyrotations.yaml | 0 .../hub}/vpnkeyrotation/crds/crd-ns.yaml | 0 .../hub}/vpnkeyrotation/crds/crd-nse.yaml | 0 .../crds/crd-workerslicegwrecycler.yaml | 0 ...networking.kubeslice.io_slicegateways.yaml | 0 .../crds/networking.kubeslice.io_slices.yaml | 0 .../vpnrotation_controller_test.go | 9 +- .../vpnkeyrotation/vpnrotation_suite_test.go | 5 +- .../manifests/manifest_test.go | 7 ++ .../webhook/pod/pod_test.go | 14 ++- 21 files changed, 73 insertions(+), 149 deletions(-) rename pkg/hub/controllers/cluster/{deregister_unit_test.go => deregister_test.go} (92%) rename pkg/hub/controllers/cluster/{reconciler_unit_test.go => reconciler_test.go} (98%) rename pkg/hub/controllers/{slice_controller_unit_test.go => slice_controller_test.go} (100%) rename pkg/hub/controllers/vpnkeyrotation/{reconciler_unit_test.go => reconciler_test.go} (99%) delete mode 100644 pkg/manifest/manifest_suite_test.go delete mode 100644 pkg/webhook/pod/pod_suite_test.go rename {pkg/hub/controllers => tests/hub}/cluster/cluster_controller_test.go (100%) rename {pkg/hub/controllers => tests/hub}/cluster/cluster_suite_test.go (96%) rename {pkg/hub/controllers => tests/hub}/cluster/crds/hub.kubeslice.io_clusters.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/crd-ns.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/crd-nse.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml (100%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml (100%) rename pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go => tests/hub/vpnkeyrotation/vpnrotation_controller_test.go (98%) rename {pkg/hub/controllers => tests/hub}/vpnkeyrotation/vpnrotation_suite_test.go (97%) rename pkg/manifest/file_test.go => tests/manifests/manifest_test.go (92%) rename pkg/webhook/pod/webhook_test.go => tests/webhook/pod/pod_test.go (97%) diff --git a/Makefile b/Makefile index 5ab0d27b8..ada02fdbb 100644 --- a/Makefile +++ b/Makefile @@ -83,24 +83,33 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +##@ Test + .PHONY: fmt -fmt: ## Run go fmt against code. +fmt: ## Run go fmt against code. go fmt ./... .PHONY: vet -vet: ## Run go vet against code. +vet: ## Run go vet against code. go vet ./... -.PHONY: test -test: fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -coverprofile=coverage.out -coverpkg ./... ./... +.PHONY: test-unit +test-unit: ## Run unit tests. + go test -v -coverprofile=coverage.out `go list ./controllers/... ./pkg/... | grep -v ./pkg/mocks` -.PHONY: unit-test-coverage -unit-test-coverage: test +.PHONY: test-coverage +test-coverage: test-unit ## Run unit tests and print code coverage. go tool cover -func coverage.out +.PHONY: test-integration +test-integration: ## Run integration tests. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -tags=integration ./... + +.PHONY: test +test: fmt vet envtest test-unit test-integration ## Run all tests (fmt, vet, envtest, unit & integration). + .PHONY: test-docker -test-docker: +test-docker: ## Run all tests (fmt, vet, envtest, unit & integration) inside a Docker container. docker build -t test -f test.Dockerfile . && docker run test ##@ Build diff --git a/pkg/hub/controllers/cluster/deregister_unit_test.go b/pkg/hub/controllers/cluster/deregister_test.go similarity index 92% rename from pkg/hub/controllers/cluster/deregister_unit_test.go rename to pkg/hub/controllers/cluster/deregister_test.go index dde36f003..fac642a4b 100644 --- a/pkg/hub/controllers/cluster/deregister_unit_test.go +++ b/pkg/hub/controllers/cluster/deregister_test.go @@ -3,8 +3,6 @@ package cluster import ( "context" "errors" - "reflect" - "runtime/debug" "testing" hubv1alpha1 "github.com/kubeslice/apis/pkg/controller/v1alpha1" @@ -12,6 +10,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" utilmock "github.com/kubeslice/worker-operator/pkg/mocks" "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -87,9 +86,7 @@ func TestGetOperatorClusterRole(t *testing.T) { mock.IsType(&rbacv1.ClusterRole{}), ).Return(nil) _, err := reconciler.getOperatorClusterRole(ctx) - if expected.err != err { - t.Error("Expected error:", expected.err, " but got ", err) - } + assert.ErrorIs(t, expected.err, err) } func TestCreateDeregisterJobPositiveScenarios(t *testing.T) { @@ -194,9 +191,7 @@ func TestCreateDeregisterJobPositiveScenarios(t *testing.T) { mock.IsType([]k8sclient.CreateOption(nil)), ).Return(nil) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.err != err { - t.Error("Expected error:", expected.err, " but got ", err) - } + assert.ErrorIs(t, expected.err, err) } func TestReconcilerFailToUpdateClusterRegistrationStatus(t *testing.T) { @@ -237,9 +232,7 @@ func TestReconcilerFailToUpdateClusterRegistrationStatus(t *testing.T) { ).Return(errors.New("error updating status of deregistration on the controller")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateServiceAccount(t *testing.T) { @@ -295,9 +288,7 @@ func TestReconcilerFailToCreateServiceAccount(t *testing.T) { ).Return(errors.New("unable to create service account")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToFetchOperatorClusterRole(t *testing.T) { @@ -363,9 +354,7 @@ func TestReconcilerFailToFetchOperatorClusterRole(t *testing.T) { ).Return(errors.New("unable to fetch operator clusterrole")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateClusterRole(t *testing.T) { @@ -441,9 +430,7 @@ func TestReconcilerFailToCreateClusterRole(t *testing.T) { ).Return(errors.New("unable to create cluster role")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateClusterRoleBinding(t *testing.T) { @@ -524,9 +511,7 @@ func TestReconcilerFailToCreateClusterRoleBinding(t *testing.T) { ).Return(errors.New("unable to create cluster rolebinding")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateConfigmap(t *testing.T) { @@ -621,9 +606,7 @@ func TestReconcilerFailToCreateConfigmap(t *testing.T) { mock.IsType([]k8sclient.CreateOption(nil)), ).Return(errors.New("Unable to create configmap")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToDeleteJob(t *testing.T) { @@ -729,9 +712,7 @@ func TestReconcilerFailToDeleteJob(t *testing.T) { ).Return(errors.New("Unable to delete deregister job")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateDeregisterJob(t *testing.T) { @@ -842,64 +823,42 @@ func TestReconcilerFailToCreateDeregisterJob(t *testing.T) { ).Return(errors.New("Unable to create deregister job")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestGetConfigmapScriptData(t *testing.T) { data, err := getCleanupScript() - AssertNoError(t, err) - if len(data) == 0 { - t.Fatalf("unable to get configmap data") - } + assert.NoError(t, err) + assert.NotZero(t, len(data), "unable to get configmap data") } func TestConstructJobForClusterDeregister(t *testing.T) { job := constructJobForClusterDeregister() - AssertEqual(t, job.Name, deregisterJobName) - AssertEqual(t, job.Namespace, ControlPlaneNamespace) + assert.Equal(t, job.Name, deregisterJobName) + assert.Equal(t, job.Namespace, ControlPlaneNamespace) } func TestConstructServiceAccount(t *testing.T) { sa := constructServiceAccount() - AssertEqual(t, sa.Name, serviceAccountName) - AssertEqual(t, sa.Namespace, ControlPlaneNamespace) + assert.Equal(t, sa.Name, serviceAccountName) + assert.Equal(t, sa.Namespace, ControlPlaneNamespace) } func TestConstructClusterRole(t *testing.T) { cr := constructClusterRole(testOperatorClusterRole, "random-uid") - isEqual := reflect.DeepEqual(cr.Rules, testOperatorClusterRole.Rules) - if !isEqual { - t.Fatalf("got invalid data in clusterrole Rules: got -- %q want -- %q", &cr.Rules[0], &testOperatorClusterRole.Rules[0]) - } + assert.Equal(t, cr.Rules, testOperatorClusterRole.Rules) } func TestConstructClusterRoleBinding(t *testing.T) { crb := constructClusterRoleBinding("random-uid") - AssertEqual(t, crb.Name, clusterRoleBindingName) - AssertEqual(t, crb.RoleRef, testClusterRoleRef) - AssertEqual(t, len(crb.Subjects), 1) - AssertEqual(t, crb.Subjects[0], testClusterRoleBindingSubject[0]) + assert.Equal(t, crb.Name, clusterRoleBindingName) + assert.Equal(t, crb.RoleRef, testClusterRoleRef) + assert.Len(t, crb.Subjects, 1) + assert.Equal(t, crb.Subjects[0], testClusterRoleBindingSubject[0]) } func TestConstructConfigMap(t *testing.T) { data := "this is the data." cm := constructConfigMap(data) - AssertEqual(t, cm.Data["kubeslice-cleanup.sh"], data) -} - -func AssertEqual(t *testing.T, actual interface{}, expected interface{}) { - t.Helper() - if actual != expected { - t.Log("expected --", expected, "actual --", actual) - t.Fail() - } -} - -func AssertNoError(t *testing.T, err error) { - t.Helper() - if err != nil { - t.Errorf("Expected No Error but got %s, Stack:\n%s", err, string(debug.Stack())) - } + assert.Equal(t, cm.Data["kubeslice-cleanup.sh"], data) } diff --git a/pkg/hub/controllers/cluster/reconciler_unit_test.go b/pkg/hub/controllers/cluster/reconciler_test.go similarity index 98% rename from pkg/hub/controllers/cluster/reconciler_unit_test.go rename to pkg/hub/controllers/cluster/reconciler_test.go index 6a98a5371..0d6a454f9 100644 --- a/pkg/hub/controllers/cluster/reconciler_unit_test.go +++ b/pkg/hub/controllers/cluster/reconciler_test.go @@ -178,7 +178,7 @@ func TestReconcilerHandleExternalDependency(t *testing.T) { client.StatusMock.On("Update", mock.IsType(ctx), mock.IsType(&hubv1alpha1.Cluster{}), - mock.IsType([]k8sclient.UpdateOption(nil)), + mock.IsType([]k8sclient.SubResourceUpdateOption(nil)), ).Return(nil) client.On("List", mock.IsType(ctx), @@ -295,7 +295,7 @@ func TestReconcilerToFailWhileCallingCreateDeregisterJob(t *testing.T) { client.StatusMock.On("Update", mock.IsType(ctx), mock.IsType(&hubv1alpha1.Cluster{}), - mock.IsType([]k8sclient.UpdateOption(nil)), + mock.IsType([]k8sclient.SubResourceUpdateOption(nil)), ).Return(errors.New("error updating status of deregistration on the controller")) client.On("Create", mock.IsType(ctx), diff --git a/pkg/hub/controllers/slice_controller_unit_test.go b/pkg/hub/controllers/slice_controller_test.go similarity index 100% rename from pkg/hub/controllers/slice_controller_unit_test.go rename to pkg/hub/controllers/slice_controller_test.go diff --git a/pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go b/pkg/hub/controllers/vpnkeyrotation/reconciler_test.go similarity index 99% rename from pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go rename to pkg/hub/controllers/vpnkeyrotation/reconciler_test.go index 7006041b0..ab5b11ac2 100644 --- a/pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go +++ b/pkg/hub/controllers/vpnkeyrotation/reconciler_test.go @@ -40,6 +40,8 @@ var ( testWorkerNamespace = "kubeslice-system" ) +var k8sClient k8sclient.Client + var testVPNKeyRotationObject = &hubv1alpha1.VpnKeyRotation{ ObjectMeta: metav1.ObjectMeta{ Name: testVPNKeyRotationName, diff --git a/pkg/manifest/manifest_suite_test.go b/pkg/manifest/manifest_suite_test.go deleted file mode 100644 index d710609d0..000000000 --- a/pkg/manifest/manifest_suite_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Avesha, Inc. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package manifest_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestManifest(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Manifest Suite") -} diff --git a/pkg/webhook/pod/pod_suite_test.go b/pkg/webhook/pod/pod_suite_test.go deleted file mode 100644 index bfac1c2eb..000000000 --- a/pkg/webhook/pod/pod_suite_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Avesha, Inc. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package pod_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestDeploy(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Deploy Webhook Suite") -} diff --git a/test.Dockerfile b/test.Dockerfile index ea3819758..749fac02e 100644 --- a/test.Dockerfile +++ b/test.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20 as builder +FROM golang:1.21 as builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/pkg/hub/controllers/cluster/cluster_controller_test.go b/tests/hub/cluster/cluster_controller_test.go similarity index 100% rename from pkg/hub/controllers/cluster/cluster_controller_test.go rename to tests/hub/cluster/cluster_controller_test.go diff --git a/pkg/hub/controllers/cluster/cluster_suite_test.go b/tests/hub/cluster/cluster_suite_test.go similarity index 96% rename from pkg/hub/controllers/cluster/cluster_suite_test.go rename to tests/hub/cluster/cluster_suite_test.go index c7b140b06..921df5640 100644 --- a/pkg/hub/controllers/cluster/cluster_suite_test.go +++ b/tests/hub/cluster/cluster_suite_test.go @@ -28,6 +28,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" ossEvents "github.com/kubeslice/worker-operator/events" "github.com/kubeslice/worker-operator/pkg/hub/controllers" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/cluster" "github.com/prometheus/client_golang/prometheus" ) @@ -54,7 +55,7 @@ var _ = BeforeSuite(func() { By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ - filepath.Join("../../../..", "config", "crd", "bases"), + filepath.Join("../../../", "config", "crd", "bases"), filepath.Join("./crds"), }, ErrorIfCRDPathMissing: true, @@ -127,7 +128,7 @@ var _ = BeforeSuite(func() { Component: "worker-operator", Namespace: CONTROL_PLANE_NS, }) - clusterReconciler := NewReconciler( + clusterReconciler := cluster.NewReconciler( k8sClient, k8sClient, &spokeClusterEventRecorder, diff --git a/pkg/hub/controllers/cluster/crds/hub.kubeslice.io_clusters.yaml b/tests/hub/cluster/crds/hub.kubeslice.io_clusters.yaml similarity index 100% rename from pkg/hub/controllers/cluster/crds/hub.kubeslice.io_clusters.yaml rename to tests/hub/cluster/crds/hub.kubeslice.io_clusters.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml b/tests/hub/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml rename to tests/hub/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-ns.yaml b/tests/hub/vpnkeyrotation/crds/crd-ns.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-ns.yaml rename to tests/hub/vpnkeyrotation/crds/crd-ns.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-nse.yaml b/tests/hub/vpnkeyrotation/crds/crd-nse.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-nse.yaml rename to tests/hub/vpnkeyrotation/crds/crd-nse.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml b/tests/hub/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml rename to tests/hub/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml b/tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml rename to tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml b/tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml rename to tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go b/tests/hub/vpnkeyrotation/vpnrotation_controller_test.go similarity index 98% rename from pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go rename to tests/hub/vpnkeyrotation/vpnrotation_controller_test.go index febd85290..5ada19d6d 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go +++ b/tests/hub/vpnkeyrotation/vpnrotation_controller_test.go @@ -11,6 +11,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" ossEvents "github.com/kubeslice/worker-operator/events" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/vpnkeyrotation" nsmv1 "github.com/networkservicemesh/sdk-k8s/pkg/tools/k8s/apis/networkservicemesh.io/v1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -75,7 +76,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } @@ -178,7 +179,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: gws, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -517,7 +518,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -745,7 +746,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ "worker-1": gws, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go b/tests/hub/vpnkeyrotation/vpnrotation_suite_test.go similarity index 97% rename from pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go rename to tests/hub/vpnkeyrotation/vpnrotation_suite_test.go index 45a027314..355a806f9 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go +++ b/tests/hub/vpnkeyrotation/vpnrotation_suite_test.go @@ -33,6 +33,7 @@ import ( "github.com/kubeslice/worker-operator/controllers/slicegateway" ossEvents "github.com/kubeslice/worker-operator/events" "github.com/kubeslice/worker-operator/pkg/hub/controllers" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/vpnkeyrotation" hub "github.com/kubeslice/worker-operator/pkg/hub/hubclient" hce "github.com/kubeslice/worker-operator/tests/emulator/hubclient" workernetop "github.com/kubeslice/worker-operator/tests/emulator/workerclient/netop" @@ -152,7 +153,7 @@ var _ = BeforeSuite(func() { if err != nil { os.Exit(1) } - rotationReconciler := NewReconciler( + rotationReconciler := vpnkeyrotation.NewReconciler( k8sClient, &hub.HubClientConfig{ Client: k8sClient, @@ -222,7 +223,7 @@ var _ = AfterSuite(func() { func shouldProcessVpnKeyRotation(object client.Object) bool { vpn := object.(*hubv1alpha1.VpnKeyRotation) for _, v := range vpn.Spec.Clusters { - if v == ClusterName { + if v == vpnkeyrotation.ClusterName { return true } } diff --git a/pkg/manifest/file_test.go b/tests/manifests/manifest_test.go similarity index 92% rename from pkg/manifest/file_test.go rename to tests/manifests/manifest_test.go index dd57865c8..a1d712a10 100644 --- a/pkg/manifest/file_test.go +++ b/tests/manifests/manifest_test.go @@ -19,6 +19,8 @@ package manifest_test import ( + "testing" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -26,6 +28,11 @@ import ( appsv1 "k8s.io/api/apps/v1" ) +func TestManifest(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Manifest Suite") +} + var _ = Describe("Manifest File", func() { Context("With k8s deployment manifest", func() { diff --git a/pkg/webhook/pod/webhook_test.go b/tests/webhook/pod/pod_test.go similarity index 97% rename from pkg/webhook/pod/webhook_test.go rename to tests/webhook/pod/pod_test.go index 081de286a..013af4d0b 100644 --- a/pkg/webhook/pod/webhook_test.go +++ b/tests/webhook/pod/pod_test.go @@ -20,16 +20,22 @@ package pod_test import ( "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/client" + "testing" "github.com/kubeslice/worker-operator/controllers" "github.com/kubeslice/worker-operator/pkg/webhook/pod" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) +func TestDeploy(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Deploy Webhook Suite") +} + type fakeWebhookClient struct{} func (f fakeWebhookClient) UpdateSliceApplicationNamespaces(ctx context.Context, slice string, namespace string) error {