Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding packages other than controllers to the code coverage report from the integration tests #425

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions .github/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,16 @@ ignore:
- api/external/** # ignoring external vendor code
- "**/*.deepcopy.go" # ignore controller-gen generated code

flag_management:
individual_flags:
- name: unit
paths:
- pkg/**
- api/**
carryforward: true
- name: integration
paths:
- controllers/**
carryforward: true

component_management:
individual_components:
- component_id: api-v1beta1
name: api/v1beta1 (u)
paths:
- api/v1beta1
- component_id: api-v1beta2
name: api/v1beta2 (u)
paths:
- api/v1beta2
- component_id: common
name: pkg/common (u)
paths:
Expand All @@ -69,4 +61,3 @@ component_management:
name: controllers (i)
paths:
- controllers

5 changes: 2 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
make test-unit
- name: Upload unit-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unit
Expand All @@ -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 Expand Up @@ -92,7 +91,7 @@ jobs:
run: |
make test-integration
- name: Upload integration-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: integration
Expand Down
41 changes: 27 additions & 14 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,11 @@ 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)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -238,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 @@ -282,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)" USE_EXISTING_CLUSTER=true go test $(INTEGRATION_DIRS) -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)
Copy link
Member

@mikenairn mikenairn Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to using ginkgo cli


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 @@ -415,7 +432,7 @@ install-metallb: kustomize yq ## Installs the metallb load balancer allowing use
./utils/docker-network-ipaddresspool.sh kind $(YQ) | kubectl apply -n metallb-system -f -

.PHONY: uninstall-metallb
uninstall-metallb: $(KUSTOMIZE)
uninstall-metallb: $(KUSTOMIZE)
$(KUSTOMIZE) build config/metallb | kubectl delete -f -

.PHONY: install-olm
Expand All @@ -434,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
}
}
1 change: 1 addition & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var _ = BeforeSuite(func() {
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
UseExistingCluster: &[]bool{true}[0],
}

cfg, err := testEnv.Start()
Expand Down
Loading