Skip to content

Commit

Permalink
use ginkgo CLI
Browse files Browse the repository at this point in the history
Cleanup controller-runtime’s envtest environment to run e2e tests as it is not being used
  • Loading branch information
eguzki committed Feb 16, 2024
1 parent e202afd commit c0fa2a2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 50 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 25 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 39 additions & 3 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
}
33 changes: 0 additions & 33 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit c0fa2a2

Please sign in to comment.