From faf812a0ce85ced2a672530522e9f540b18a1242 Mon Sep 17 00:00:00 2001 From: Luigi Operoso <40476330+brokenpip3@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:27:17 +0200 Subject: [PATCH] feat: add matrix tests for bats and replace the old devoptics plugin in tests (#1102) --- .github/workflows/auto-tests-bats.yaml | 9 +++++--- Makefile | 16 +++++++++---- kind-cluster.yaml | 4 +++- test/bats/1-deploy.bats | 32 ++++++++++++-------------- test/e2e/jenkins_test.go | 2 +- test/e2e/test_utility.go | 2 +- 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/auto-tests-bats.yaml b/.github/workflows/auto-tests-bats.yaml index 2b76ece3..1e9fc169 100644 --- a/.github/workflows/auto-tests-bats.yaml +++ b/.github/workflows/auto-tests-bats.yaml @@ -19,12 +19,15 @@ on: - 'backup/**' - '*.md' -#TODO: create a matrix per earch bats file jobs: run-tests: if: github.event.pull_request.draft == false - name: BATS Run tests + name: BATS test ${{ matrix.test-file }} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + test-file: ["1-deploy", "2-deploy-with-more-options", "3-deploy-with-webhook"] steps: - name: Check out code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 @@ -61,4 +64,4 @@ jobs: - name: Jenkins Operator - bats tests env: BATS_LIB_PATH: "${{ github.workspace }}/.bats" - run: make bats-tests + run: BATS_TEST_PATH=${{matrix.test-file}}.bats make bats-tests diff --git a/Makefile b/Makefile index 9d37a041..7d4570a9 100644 --- a/Makefile +++ b/Makefile @@ -93,11 +93,17 @@ test: ## Runs the go tests @RUNNING_TESTS=1 go test -tags "$(BUILDTAGS) cgo" $(PACKAGES_FOR_UNIT_TESTS) .PHONY: e2e -e2e: deepcopy-gen manifests backup-kind-load ## Runs e2e tests, you can use EXTRA_ARGS +e2e: deepcopy-gen manifests backup-kind-load jenkins-kind-load ## Runs e2e tests, you can use EXTRA_ARGS @echo "+ $@" RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -ginkgo.v -tags "$(BUILDTAGS) cgo" -v -timeout 60m -run "$(E2E_TEST_SELECTOR)" \ -jenkins-api-hostname=$(JENKINS_API_HOSTNAME) -jenkins-api-port=$(JENKINS_API_PORT) -jenkins-api-use-nodeport=$(JENKINS_API_USE_NODEPORT) $(E2E_TEST_ARGS) +.PHONY: jenkins-kind-load +jenkins-kind-load: ## Load the jenkins lts version in kind to speed up tests + @echo "+ $@" + docker pull jenkins/jenkins:$(LATEST_LTS_VERSION) + kind load docker-image jenkins/jenkins:$(LATEST_LTS_VERSION) --name $(KIND_CLUSTER_NAME) + ## Backup Section .PHONY: backup-kind-load @@ -383,21 +389,21 @@ kind-clean: ## Delete kind cluster kind delete cluster --name $(KIND_CLUSTER_NAME) .PHONY: kind-revamp -kind-revamp: kind-clean kind-setup## Delete and recreate kind cluster +kind-revamp: kind-clean kind-setup ## Delete and recreate kind cluster @echo "+ $@" -.PHONY: bats-tests +.PHONY: bats-tests ## Run bats tests IMAGE_NAME := quay.io/$(QUAY_ORGANIZATION)/$(QUAY_REGISTRY):$(GITCOMMIT)-amd64 BUILD_PRESENT := $(shell docker images |grep -q ${IMAGE_NAME}) ifndef BUILD_PRESENT bats-tests: backup-kind-load container-runtime-build-amd64 ## Run bats tests @echo "+ $@" kind load docker-image ${IMAGE_NAME} --name $(KIND_CLUSTER_NAME) - OPERATOR_IMAGE="${IMAGE_NAME}" TERM=xterm bats -T -p test/bats + OPERATOR_IMAGE="${IMAGE_NAME}" TERM=xterm bats -T -p test/bats$(if $(BATS_TEST_PATH),/${BATS_TEST_PATH}) else bats-tests: backup-kind-load @echo "+ $@" - OPERATOR_IMAGE="${IMAGE_NAME}" TERM=xterm bats -T -p test/bats + OPERATOR_IMAGE="${IMAGE_NAME}" TERM=xterm bats -T -p test/bats$(if $(BATS_TEST_PATH),/${BATS_TEST_PATH}) endif .PHONY: crc-start diff --git a/kind-cluster.yaml b/kind-cluster.yaml index 726f6137..13407a21 100644 --- a/kind-cluster.yaml +++ b/kind-cluster.yaml @@ -1,9 +1,11 @@ apiVersion: kind.x-k8s.io/v1alpha4 kind: Cluster +networking: + dnsSearch: [] nodes: - role: control-plane extraPortMappings: - containerPort: 30303 hostPort: 30303 listenAddress: "0.0.0.0" - protocol: tcp \ No newline at end of file + protocol: tcp diff --git a/test/bats/1-deploy.bats b/test/bats/1-deploy.bats index f6365b5c..f31fa567 100644 --- a/test/bats/1-deploy.bats +++ b/test/bats/1-deploy.bats @@ -68,8 +68,12 @@ diag() { run try "at most 20 times every 10s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"jenkins-master\")].ready' is 'true'" assert_success - run try "at most 20 times every 5s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"jenkins-master\")].ready' is 'true'" + run try "at most 20 times every 5s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"backup\")].ready' is 'true'" assert_success + + run ${KUBECTL} logs -l jenkins-cr=jenkins --tail=-1 + assert_success + assert_output --partial 'Jenkins is fully up and running' } #bats test_tags=phase:helm,scenario:vanilla @@ -161,6 +165,9 @@ diag() { chart/jenkins-operator --wait assert_success assert ${HELM} status default + + # Additional sleep to wait for the upgrade to start deploy a new version + sleep 15 } #bats test_tags=phase:helm,scenario:vanilla @@ -177,30 +184,21 @@ diag() { } #bats test_tags=phase:helm,scenario:vanilla -@test "1.13 Helm: check Jenkins operator pods status" { - [[ ! -f "chart/jenkins-operator/deploy.tmp" ]] && skip "Jenkins helm chart have not been deployed correctly" - run verify "there is 1 deployment named 'default-jenkins-operator'" - assert_success - - run verify "there is 1 pod named 'default-jenkins-operator-'" - assert_success - - run try "at most 20 times every 10s to get pods named 'default-jenkins-operator-' and verify that '.status.containerStatuses[?(@.name==\"jenkins-operator\")].ready' is 'true'" - assert_success -} - -#bats test_tags=phase:helm,scenario:vanilla -@test "1.14 Helm: check Jenkins Pod status" { +@test "1.13 Helm: check Jenkins Pod status" { [[ ! -f "chart/jenkins-operator/deploy.tmp" ]] && skip "Jenkins helm chart have not been deployed correctly" run try "at most 20 times every 10s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"jenkins-master\")].ready' is 'true'" assert_success - run try "at most 20 times every 5s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"jenkins-master\")].ready' is 'true'" + run try "at most 20 times every 5s to get pods named 'jenkins-jenkins' and verify that '.status.containerStatuses[?(@.name==\"backup\")].ready' is 'true'" assert_success + + run ${KUBECTL} logs -l jenkins-cr=jenkins --tail=-1 + assert_success + assert_output --partial 'Jenkins is fully up and running' } #bats test_tags=phase:helm,scenario:vanilla -@test "1.15 Helm: clean" { +@test "1.14 Helm: clean" { run ${HELM} uninstall default --wait assert_success # Wait for the complete removal diff --git a/test/e2e/jenkins_test.go b/test/e2e/jenkins_test.go index d2572d76..858c43ed 100644 --- a/test/e2e/jenkins_test.go +++ b/test/e2e/jenkins_test.go @@ -128,7 +128,7 @@ func createJenkinsCRSafeRestart(name, namespace string, seedJob *[]v1alpha2.Seed {Name: "audit-trail", Version: "361.v82cde86c784e"}, {Name: "simple-theme-plugin", Version: "176.v39740c03a_a_f5"}, {Name: "github", Version: "1.38.0"}, - {Name: "devoptics", Version: "2.0", DownloadURL: "https://jenkins-updates.cloudbees.com/download/plugins/devoptics/2.0/devoptics.hpi"}, + {Name: "cloudbees-disk-usage-simple", Version: "239.v6a_f1a_c1c8046", DownloadURL: "https://jenkins-updates.cloudbees.com/download/plugins/cloudbees-disk-usage-simple/239.v6a_f1a_c1c8046/cloudbees-disk-usage-simple.hpi"}, }, PriorityClassName: priorityClassName, NodeSelector: map[string]string{"kubernetes.io/os": "linux"}, diff --git a/test/e2e/test_utility.go b/test/e2e/test_utility.go index c046f704..f4005e9a 100644 --- a/test/e2e/test_utility.go +++ b/test/e2e/test_utility.go @@ -151,7 +151,7 @@ func RenderJenkinsCR(name, namespace string, seedJob *[]v1alpha2.SeedJob, groovy {Name: "audit-trail", Version: "361.v82cde86c784e"}, {Name: "simple-theme-plugin", Version: "176.v39740c03a_a_f5"}, {Name: "github", Version: "1.38.0"}, - {Name: "devoptics", Version: "2.0", DownloadURL: "https://jenkins-updates.cloudbees.com/download/plugins/devoptics/2.0/devoptics.hpi"}, + {Name: "cloudbees-disk-usage-simple", Version: "239.v6a_f1a_c1c8046", DownloadURL: "https://jenkins-updates.cloudbees.com/download/plugins/cloudbees-disk-usage-simple/239.v6a_f1a_c1c8046/cloudbees-disk-usage-simple.hpi"}, }, PriorityClassName: priorityClassName, NodeSelector: map[string]string{"kubernetes.io/os": "linux"},