-
Notifications
You must be signed in to change notification settings - Fork 31
CLOUDP-332943: Refactor unit test execution #288
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
base: master
Are you sure you want to change the base?
Conversation
f3cd1b8 to
80c4de1
Compare
MCK 1.6.1 Release NotesBug Fixes
Other Changes
|
d3f907a to
f4e132b
Compare
bf880c6 to
24e9157
Compare
d95212e to
481f562
Compare
481f562 to
23c4209
Compare
71839e7 to
b051325
Compare
89163da to
75962dc
Compare
| func init() { | ||
| logger, _ := zap.NewDevelopment() | ||
| zap.ReplaceGlobals(logger) | ||
| os.Clearenv() // nolint:forbidigo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this (and similar additions in other pkgs) is allowing for consistent exec of tests that runs reconcile code across all contexts. The biggest offender was static architecture env which caused different reconcile behavior if tests were executed with different contexts.
Unit tests should never rely on env vars set outside. If those are needed then should be specified in the test itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in theory - the proper way is to fix all those tests which are using global env to t.setEnv() instead, right?
Have you considered doing this instead? Or is that too much of a change?
| } | ||
|
|
||
| check_backup_daemon_alive | ||
| check_backup_daemon_alive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| check_backup_daemon_alive | |
| check_backup_daemon_alive | |
| pkg/client/ | ||
| docker/mongodb-kubernetes-tests | ||
| scripts/ | ||
| # scripts/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just remove this, or commenting it ok?
| pkg/client/ | ||
| docker/mongodb-kubernetes-tests | ||
| scripts/ | ||
| # scripts/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: on purpose?
| func init() { | ||
| logger, _ := zap.NewDevelopment() | ||
| zap.ReplaceGlobals(logger) | ||
| os.Clearenv() // nolint:forbidigo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in theory - the proper way is to fix all those tests which are using global env to t.setEnv() instead, right?
Have you considered doing this instead? Or is that too much of a change?
Summary
This PR simplifies unit tests execution to allow a simple
go test ./...to always correctly execute all golang unit tests without running community e2e tests.Additionally we use gotestsum wrapper by default to better present test output in the command line.
Changes
go test ./...correctly identifies all go files. The last one from init-ops-manager was removed in this PR, and another one from kubectl plugin was removed recently in [CLOUDP-332196] Movekubectl-mongodbplugin tocmddir for atomic releases #271.community_e2etag, so we don't need to run tests with a filtered package list anymore.go get -tool gotest.tools/gotestsum@latest.go tool <tool>) and is not resulting in adding dependencies into the operators binary, it is still cluttering dependency list (inrequiresection). We might consider removing it from go mod and installing it as a separate step.How to run tests now
Essentially as before:
or
$ make testDifference: we don't run with coverage enabled by default, thus allowing to use test caching for faster repeated runs from cli.
In order to run all unit tests without cache and with coverage run:
We is use gotestsum as:
But thanks to the overall go.mod/unitest simplifications you can use whatever suits you:
$ go test ./...Use other test runner/viewers. I recommend to look into gotestsum options as well..
Also there is
tparsewhich also has very nice summary table:tparse is not supporting xunit output thus it's not used here as a default.
Proof of Work
Golang unit tests with remove locks to trigger race test error: link
Python unit test with injected error: evg link
Passing tests: evg link