From f3553fa525d3e1b84c39f8533eecbdf22b5716a6 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Fri, 16 Feb 2024 12:29:33 +0100 Subject: [PATCH] use ginkgo CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup controller-runtime’s envtest environment to run e2e tests as it is not being used --- .github/workflows/test.yaml | 1 - Makefile | 38 +++++++++++------ controllers/helper_test.go | 42 +++++++++++++++++-- .../ratelimitpolicy_controller_test.go | 33 --------------- 4 files changed, 64 insertions(+), 50 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4f393183d..397bd80a2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,7 +53,6 @@ jobs: exclude: - istio-type: sail pr-event: true - fail-fast: false runs-on: ubuntu-latest env: KIND_CLUSTER_NAME: kuadrant-test diff --git a/Makefile b/Makefile index 4998ba59f..c66415ec4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ # Setting SHELL to bash allows bash commands to be executed by recipes. -# This is a requirement for 'setup-envtest.sh' in the test target. # Options are set to exit when a recipe line exits non-zero or a piped command fails. SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec @@ -80,12 +79,10 @@ endif # Image URL to use all building/pushing image targets IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG) -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.22 # Directories containing unit & integration test packages UNIT_DIRS := ./pkg/... ./api/... ./controllers/... -INTEGRATION_DIRS := ./controllers... +INTEGRATION_TEST_SUITE_PATHS := ./controllers/... INTEGRATION_COVER_PKGS := ./pkg/...,./controllers/...,./api/... # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) @@ -239,6 +236,17 @@ $(ACT): .PHONY: act act: $(ACT) ## Download act locally if necessary. +GINKGO = $(PROJECT_PATH)/bin/ginkgo +$(GINKGO): + # In order to make sure the version of the ginkgo cli installed + # is the same as the version of go.mod, + # instead of calling go-install-tool, + # running go install from the current module will pick version from current go.mod file. + GOBIN=$(PROJECT_DIR)/bin go install github.com/onsi/ginkgo/v2/ginkgo + +.PHONY: ginkgo +ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. + ##@ Development define patch-config envsubst \ @@ -283,20 +291,28 @@ vet: ## Run go vet against code. .PHONY: clean-cov clean-cov: ## Remove coverage reports - rm -rf coverage + rm -rf $(PROJECT_PATH)/coverage .PHONY: test test: test-unit test-integration ## Run all tests -test-integration: clean-cov generate fmt vet envtest ## Run Integration tests. - mkdir -p coverage/integration - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" go test $(INTEGRATION_DIRS) -coverpkg=$(INTEGRATION_COVER_PKGS) -coverprofile $(PROJECT_PATH)/coverage/integration/cover.out -tags integration -ginkgo.v -ginkgo.progress -v -timeout 0 +test-integration: clean-cov generate fmt vet ginkgo ## Run Integration tests. + mkdir -p $(PROJECT_PATH)/coverage/integration +# Check `ginkgo help run` for command line options. For example to filtering tests. + $(GINKGO) \ + --coverpkg $(INTEGRATION_COVER_PKGS) \ + --output-dir $(PROJECT_PATH)/coverage/integration \ + --coverprofile cover.out \ + -tags integration \ + --fail-fast \ + -v \ + $(INTEGRATION_TEST_SUITE_PATHS) ifdef TEST_NAME test-unit: TEST_PATTERN := --run $(TEST_NAME) endif test-unit: clean-cov generate fmt vet ## Run Unit tests. - mkdir -p coverage/unit + mkdir -p $(PROJECT_PATH)/coverage/unit go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -tags unit -v -timeout 0 $(TEST_PATTERN) .PHONY: namespace @@ -435,10 +451,6 @@ undeploy-catalog: $(KUSTOMIZE) ## Undeploy controller from the K8s cluster speci $(KUSTOMIZE) build config/deploy/olm | kubectl delete -f - -ENVTEST = $(shell pwd)/bin/setup-envtest -envtest: ## Download envtest-setup locally if necessary. - $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) - # go-install-tool will 'go install' any package $2 and install it to $1. PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) define go-install-tool diff --git a/controllers/helper_test.go b/controllers/helper_test.go index 910a5596f..44edfb266 100644 --- a/controllers/helper_test.go +++ b/controllers/helper_test.go @@ -11,11 +11,9 @@ import ( "path/filepath" "time" - kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" - "github.com/kuadrant/kuadrant-operator/pkg/common" - "github.com/google/uuid" . "github.com/onsi/gomega" + istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -30,6 +28,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + + kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" + kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" + "github.com/kuadrant/kuadrant-operator/pkg/common" ) func ApplyKuadrantCR(namespace string) { @@ -293,3 +296,36 @@ func testGatewayIsReady(gateway *gatewayapiv1.Gateway) func() bool { return err == nil && meta.IsStatusConditionTrue(existingGateway.Status.Conditions, common.GatewayProgrammedConditionType) } } + +func testRLPIsAccepted(rlpKey client.ObjectKey) func() bool { + return func() bool { + existingRLP := &kuadrantv1beta2.RateLimitPolicy{} + err := k8sClient.Get(context.Background(), rlpKey, existingRLP) + if err != nil { + return false + } + if !meta.IsStatusConditionTrue(existingRLP.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)) { + return false + } + + return true + } +} + +func testWasmPluginIsAvailable(key client.ObjectKey) func() bool { + return func() bool { + wp := &istioclientgoextensionv1alpha1.WasmPlugin{} + err := k8sClient.Get(context.Background(), key, wp) + if err != nil { + return false + } + + // Unfortunately, WasmPlugin does not have status yet + // Leaving this here for future use + //if !meta.IsStatusConditionTrue(wp.Status.Conditions, "Available") { + // return false + //} + + return true + } +} diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index b6ba8793a..a8b04c8d4 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -752,36 +752,3 @@ var _ = Describe("RateLimitPolicy CEL Validations", func() { }) }) }) - -func testRLPIsAccepted(rlpKey client.ObjectKey) func() bool { - return func() bool { - existingRLP := &kuadrantv1beta2.RateLimitPolicy{} - err := k8sClient.Get(context.Background(), rlpKey, existingRLP) - if err != nil { - return false - } - if !meta.IsStatusConditionTrue(existingRLP.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)) { - return false - } - - return true - } -} - -func testWasmPluginIsAvailable(key client.ObjectKey) func() bool { - return func() bool { - wp := &istioclientgoextensionv1alpha1.WasmPlugin{} - err := k8sClient.Get(context.Background(), key, wp) - if err != nil { - return false - } - - // Unfortunately, WasmPlugin does not have status yet - // Leaving this here for future use - //if !meta.IsStatusConditionTrue(wp.Status.Conditions, "Available") { - // return false - //} - - return true - } -}