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

feat: add acceptance test framework #4301

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions tests/acceptance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.ssh/
config/
/tests/.vscode
/.idea/
/modules/.terraform/
*.terraform*
*.tfstate*
*plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linters-settings:
ignore-generated-header: true
rules:
- name: line-length-limit
arguments: [100]
arguments: [110]
- name: cognitive-complexity
arguments: [10]
- name: empty-lines
Expand All @@ -37,7 +37,6 @@ linters-settings:
- name: blank-imports
- name: confusing-naming
- name: confusing-results
- name: context-as-argument
- name: duplicated-imports
- name: early-return
- name: empty-block
Expand All @@ -46,7 +45,6 @@ linters-settings:
- name: error-strings
- name: errorf
- name: exported
- name: flag-parameter
- name: get-return
- name: if-return
- name: increment-decrement
Expand Down
90 changes: 90 additions & 0 deletions tests/acceptance/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
include ./config.mk

TAGNAME ?= default
test-env-up:
@cd ../.. && docker build . -q -f ./tests/acceptance/scripts/Dockerfile.build -t rke2-automated-${TAGNAME}

.PHONY: test-run
test-run:
@docker run --name rke2-automated-test-${IMGNAME} -t \
-e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
-e AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
-v ${ACCESS_KEY_LOCAL}:/go/src/github.com/rancher/rke2/tests/acceptance/modules/config/.ssh/aws_key.pem \
rke2-automated-${TAGNAME} sh -c 'cd ./tests/acceptance/entrypoint; \
fmoral2 marked this conversation as resolved.
Show resolved Hide resolved
if [ -n "${TESTDIR}" ]; then \
if [ "${TESTDIR}" = "upgradecluster" ]; then \
if [ "${TESTTAG}" = "upgradesuc" ]; then \
go test -timeout=45m -v -tags=upgradesuc ./upgradecluster/... -upgradeVersion "${UPGRADEVERSION}"; \
elif [ "${TESTTAG}" = "upgrademanual" ]; then \
go test -timeout=45m -v -tags=upgrademanual ./upgradecluster/... -installVersionOrCommit "${INSTALLTYPE}"; \
fi; \
elif [ "${TESTDIR}" = "versionbump" ]; then \
go test -timeout=45m -v -tags=versionbump ./versionbump/... -cmd "${CMD}" -expectedValue "${VALUE}" \
-expectedValueUpgrade "${VALUEUPGRADE}" -installVersionOrCommit "${INSTALLTYPE}" -channel "${CHANNEL}" -testCase "${TESTCASE}" \
-deployWorkload "${DEPLOYWORKLOAD}" -workloadName "${WORKLOADNAME}" -description "${DESCRIPTION}"; \
fi; \
elif [ -z "${TESTDIR}" ]; then \
go test -timeout=45m -v ./createcluster/...; \
fi;'


.PHONY: test-logs
test-logs:
@docker logs -f rke2-automated-test-${IMGNAME}


.PHONY: test-env-down
test-env-down:
@echo "Removing containers and images"
@docker stop $$(docker ps -a -q --filter="name=rke2-automated*")
@docker rm $$(docker ps -a -q --filter="name=rke2-automated*")
@docker rmi $$(docker images -q --filter="reference=rke2-automated*")


.PHONY: test-env-clean
test-env-clean:
@./scripts/delete_resources.sh


.PHONY: test-complete
test-complete: test-env-clean test-env-down remove-tf-state test-env-up test-run


.PHONY: remove-tf-state
remove-tf-state:
@rm -rf ./modules/.terraform
@rm -rf ./modules/.terraform.lock.hcl ./modules/terraform.tfstate ./modules/terraform.tfstate.backup


#======================= Run acceptance tests locally =========================#

.PHONY: test-create
test-create:
@go test -timeout=45m -v ./entrypoint/createcluster/...


.PHONY: test-upgrade-suc
test-upgrade-suc:
@go test -timeout=45m -v -tags=upgradesuc ./entrypoint/upgradecluster/... -upgradeVersion ${UPGRADEVERSION}


.PHONY: test-upgrade-manual
test-upgrade-manual:
@go test -timeout=45m -v -tags=upgrademanual ./entrypoint/upgradecluster/... -installVersionOrCommit ${INSTALLTYPE}


.PHONY: test-version-bump
test-version-bump:
go test -timeout=45m -v -tags=versionbump ./entrypoint/versionbump/... \
-cmd "${CMD}" \
-expectedValue ${VALUE} \
-expectedValueUpgrade ${VALUEUPGRADED} \
-installVersionOrCommit ${INSTALLTYPE} -channel ${CHANNEL} \
-testCase "${TESTCASE}" -deployWorkload ${DEPLOYWORKLOAD} -workloadName ${WORKLOADNAME} -description "${DESCRIPTION}"


#========================= TestCode Static Quality Check =========================#
.PHONY: vet-lint ## Run locally only inside Tests package
vet-lint:
@echo "Running go vet and lint"
@go vet ./${TESTDIR} && golangci-lint run --tests
Loading
Loading