Skip to content

Commit

Permalink
tests: move the integration tests to a new dir
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavendra Talur <raghavendra.talur@gmail.com>
  • Loading branch information
raghavendra-talur committed Nov 10, 2023
1 parent 2e43da2 commit 46e90ec
Show file tree
Hide file tree
Showing 28 changed files with 451 additions and 423 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,22 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Run unit tests
run: make test
run: make unit-test

integration-test:
name: Integration tests
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Run integration tests
run: make integration-test

drenv-test:
name: drenv tests
Expand Down
66 changes: 41 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,27 @@ ifeq ($(GOHOSTOS),darwin)
endif
endif

GO_TEST_GINKGO_ARGS ?= -test.v

DOCKERCMD ?= podman

ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
# Define to override the path to envtest executables.
KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST_ASSETS_DIR)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) --print path)
# Integration test variables
# We use the ifeq version of comparison and assignment of the variables
# because we need conditional assignment and also *simple* expansion.
# The ?= operator does not work with simple expansion.
ifeq ($(origin ENVTEST_K8S_VERSION), undefined)
ENVTEST_K8S_VERSION := 1.25.0
endif

ifeq ($(origin ENVTEST_ASSETS_DIR), undefined)
ENVTEST_ASSETS_DIR := $(shell pwd)/testbin
endif

ifeq ($(origin KUBEBUILDER_ASSETS), undefined)
KUBEBUILDER_ASSETS := $(shell $(ENVTEST_ASSETS_DIR)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) --print path)
endif

# export KUBEBUILDER_ASSETS so that its picked by the go test commands
export KUBEBUILDER_ASSETS

all: build

Expand Down Expand Up @@ -133,54 +146,57 @@ lint: golangci-bin ## Run configured golangci-lint and pre-commit.sh linters aga
testbin/golangci-lint run ./... --config=./.golangci.yaml
hack/pre-commit.sh

.PHONY: envtest
envtest:
mkdir -p $(ENVTEST_ASSETS_DIR)
test -s $(ENVTEST_ASSETS_DIR)/setup-envtest || GOBIN=$(ENVTEST_ASSETS_DIR) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

test: generate manifests envtest ## Run tests.
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
test: unit-test integration-test

GO_UNIT_TEST_ARGS ?= -test.v -coverprofile unit_coverage.out
unit-test:
go test ./controllers/... $(GO_UNIT_TEST_ARGS)

GO_INTEGRATION_TEST_ARGS ?= -test.v -coverprofile integration_coverage.out
integration-test: generate manifests envtest
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS)

test-pvrgl: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus ProtectedVolumeReplicationGroupList
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus ProtectedVolumeReplicationGroupList

test-obj: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus FakeObjectStorer

test-vs: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/volsync -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus FakeObjectStorer

test-vrg: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroup
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VolumeReplicationGroup

test-vrg-pvc: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupPVC
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VolumeReplicationGroupPVC

test-vrg-vr: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupVolRep
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VolumeReplicationGroupVolRep

test-vrg-vs: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupVolSync
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VolumeReplicationGroupVolSync

test-vrg-recipe: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupRecipe
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VolumeReplicationGroupRecipe

test-vrg-kubeobjects: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VRG_KubeObjectProtection
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus VRG_KubeObjectProtection

test-drpc: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus DRPlacementControl
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus DRPlacementControl

test-drcluster: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus DRClusterController

test-util: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/util -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus DRClusterController

test-util-pvc: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/util -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus PVCS_Util
go test ./integration_tests/... $(GO_INTEGRATION_TEST_ARGS) -ginkgo.focus PVCS_Util

coverage:
go tool cover -html=cover.out
go tool cover -html=unit_coverage.out
go tool cover -html=integration_coverage.out

.PHONY: venv
venv:
Expand Down
Loading

0 comments on commit 46e90ec

Please sign in to comment.