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

Add automated integration and unit tests #129

Closed
Kidswiss opened this issue Oct 30, 2020 · 3 comments
Closed

Add automated integration and unit tests #129

Kidswiss opened this issue Oct 30, 2020 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@Kidswiss
Copy link
Contributor

Kidswiss commented Oct 30, 2020

Summary

As K8up developer
I want automated whitebox tests of K8up internals
So that I can contribute tested features and changes to ensure quality and avoid accidental breaking changes

Context

Currently it's unclear if there's a distinction between integration tests and unit tests.
A potential distinction could be:

  • Integration tests: all tests that require a K8s Api server (envtest)
  • Unit tests: function tests that can run without API server, to test microfunctions in code.

But in all honesty, it doesn't really make a difference. However, some IDEs may have difficulties to debug tests when envtest is running if those only run in Makefile.

Out of Scope

  • Implement e2e tests
  • Implement tests that are part of (w)restic itself
  • Achieve a certain code coverage threshold. code coverage as metric doesn't say much about actual quality.

Further links

Acceptance criteria

Given a K8up PR
When I push code into a feature branch
Then GitHub should run automated tests and indicate to code authors and reviewers of passing or failing tests

Implementation Ideas

  • The Operator-SDK scaffolds tests with envtest, a library that runs a minimal Kubernetes API server in memory where we get full support for Kubernetes client operations
@ccremer ccremer linked a pull request Nov 25, 2020 that will close this issue
@ccremer
Copy link
Contributor

ccremer commented Nov 25, 2020

#152 sets the foundation for this case, at least locally (not in GH action yet). I was already able to run it:

$ make integration_test
/home/chris/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
/home/chris/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
2020/11/25 13:27:40 Reading file config/crd/bases/backup.appuio.ch_prebackuppods.yaml
2020/11/25 13:27:40 Removed 'protocol' in line 1275
2020/11/25 13:27:40 Removed 'protocol' in line 3593
2020/11/25 13:27:40 Writing new file to config/crd/bases/backup.appuio.ch_prebackuppods.yaml
test -f /home/chris/Documents/source/vshn/k8up/testbin/setup-envtest.sh || curl -sSLo /home/chris/Documents/source/vshn/k8up/testbin/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
source /home/chris/Documents/source/vshn/k8up/testbin/setup-envtest.sh; fetch_envtest_tools /home/chris/Documents/source/vshn/k8up/testbin; setup_envtest_env /home/chris/Documents/source/vshn/k8up/testbin; go test -tags=integration -v ./... -coverprofile cover.out
Using cached envtest tools from /home/chris/Documents/source/vshn/k8up/testbin
setting up env vars
?   	github.com/vshn/k8up	[no test files]
?   	github.com/vshn/k8up/api/v1alpha1	[no test files]
?   	github.com/vshn/k8up/constants	[no test files]
=== RUN   TestAPIs
Running Suite: Controller Suite
===============================
Random Seed: 1606307262
Will run 0 of 0 specs



Ran 0 of 0 Specs in 7.326 seconds
SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestAPIs (7.33s)
PASS
coverage: 0.0% of statements
ok  	github.com/vshn/k8up/controllers	7.337s	coverage: 0.0% of statements
=== RUN   TestExecutor
Running Suite: Executor Suite
=============================
Random Seed: 1606307262
Will run 3 of 3 specs

•••
Ran 3 of 3 Specs in 0.001 seconds
SUCCESS! -- 3 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestExecutor (0.00s)
PASS
coverage: 17.2% of statements
ok  	github.com/vshn/k8up/executor	0.014s	coverage: 17.2% of statements
?   	github.com/vshn/k8up/handler	[no test files]
?   	github.com/vshn/k8up/job	[no test files]
?   	github.com/vshn/k8up/observer	[no test files]
?   	github.com/vshn/k8up/prebackup	[no test files]
?   	github.com/vshn/k8up/queue	[no test files]
?   	github.com/vshn/k8up/scheduler	[no test files]

@ccremer ccremer removed a link to a pull request Nov 25, 2020
@ccremer ccremer changed the title Add integration tests to the rewrite Add integration tests Dec 1, 2020
@ccremer
Copy link
Contributor

ccremer commented Dec 1, 2020

@Kidswiss I have refined this issue. Please review

@ccremer ccremer added the enhancement New feature or request label Dec 1, 2020
@ccremer ccremer changed the title Add integration tests Add automated integration and unit tests Dec 4, 2020
@ccremer ccremer modified the milestones: v1.0.0-rc2, v1.0.0-rc3 Dec 29, 2020
@tobru
Copy link
Contributor

tobru commented Jan 4, 2021

As discussed in today's Tarazed sync we'll close this issue in favor of the outcome of the discussion in #231. We'll create appropriate individual issues to increase test coverage.

@tobru tobru closed this as completed Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants