Add support for setting a test filter
This is basically taking some stuff that make a custom shell function
for.
This takes a test filter, builds the appropriate TESTFLAGS, and sets the
integration API test dirs that match the given filter to avoid building
all test dirs.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 13064b155e
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
43919c2455
commit
78abff3e39
3 changed files with 52 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -62,6 +62,7 @@ DOCKER_ENVS := \
|
|||
-e TESTFLAGS \
|
||||
-e TESTFLAGS_INTEGRATION \
|
||||
-e TESTFLAGS_INTEGRATION_CLI \
|
||||
-e TEST_FILTER \
|
||||
-e TIMEOUT \
|
||||
-e VALIDATE_REPO \
|
||||
-e VALIDATE_BRANCH \
|
||||
|
|
23
TESTING.md
23
TESTING.md
|
@ -67,6 +67,8 @@ If a remote daemon is detected, the test will be skipped.
|
|||
|
||||
## Running tests
|
||||
|
||||
### Unit Tests
|
||||
|
||||
To run the unit test suite:
|
||||
|
||||
```
|
||||
|
@ -82,12 +84,33 @@ The following environment variables may be used to run a subset of tests:
|
|||
* `TESTFLAGS` - flags passed to `go test`, to run tests which match a pattern
|
||||
use `TESTFLAGS="-test.run TestNameOrPrefix"`
|
||||
|
||||
### Integration Tests
|
||||
|
||||
To run the integration test suite:
|
||||
|
||||
```
|
||||
make test-integration
|
||||
```
|
||||
|
||||
This make target runs both the "integration" suite and the "integration-cli"
|
||||
suite.
|
||||
|
||||
You can specify which integration test dirs to build and run by specifying
|
||||
the list of dirs in the TEST_INTEGRATION_DIR environment variable.
|
||||
|
||||
You can also explicitly skip either suite by setting (any value) in
|
||||
TEST_SKIP_INTEGRATION and/or TEST_SKIP_INTEGRATION_CLI environment variables.
|
||||
|
||||
Flags specific to each suite can be set in the TESTFLAGS_INTEGRATION and
|
||||
TESTFLAGS_INTEGRATION_CLI environment variables.
|
||||
|
||||
If all you want is to specity a test filter to run, you can set the
|
||||
`TEST_FILTER` environment variable. This ends up getting passed directly to `go
|
||||
test -run` (or `go test -check-f`, dpenending on the test suite). It will also
|
||||
automatically set the other above mentioned environment variables accordingly.
|
||||
|
||||
### Go Version
|
||||
|
||||
You can change a version of golang used for building stuff that is being tested
|
||||
by setting `GO_VERSION` variable, for example:
|
||||
|
||||
|
|
|
@ -27,7 +27,34 @@ source "$MAKEDIR/.go-autogen"
|
|||
: ${TESTFLAGS:=}
|
||||
: ${TESTDEBUG:=}
|
||||
|
||||
integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(go list -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}' ./integration/...)"}
|
||||
setup_integration_test_filter() {
|
||||
if [ -z "${TEST_FILTER}" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -z "${TEST_SKIP_INTEGRATION}" ]; then
|
||||
: ${TEST_INTEGRATION_DIR:=$(grep -rl "func\ .*${TEST_FILTER}.*\(t\ \*testing\.T\)" ./integration | grep '_test\.go' | xargs -I file dirname file | uniq)}
|
||||
if [ -z "${TEST_INTEGRATION_DIR}" ]; then
|
||||
echo Skipping integration tests since the supplied filter \"${TEST_FILTER}\" omits all integration tests
|
||||
TEST_SKIP_INTEGRATION=1
|
||||
else
|
||||
TESTFLAGS_INTEGRATION+="-test.run ${TEST_FILTER}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${TEST_SKIP_INTEGRATION_CLI}" ]; then
|
||||
# ease up on the filtering here since CLI suites are namespaced by an object
|
||||
if grep -r "${TEST_FILTER}.*\(c\ \*check\.C\)" ./integration-cli | grep -q '_test\.go$'; then
|
||||
TEST_SKIP_INTEGRATION_CLI=1
|
||||
echo Skipping integration-cli tests since the supplied filter \"${TEST_FILTER}\" omits all integration-cli tests
|
||||
else
|
||||
TESTFLAGS_INTEGRATION_CLI+="-check.f ${TEST_FILTER}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_integration_test_filter
|
||||
integration_api_dirs=${TEST_INTEGRATION_DIR:-$(go list -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}' ./integration/...)}
|
||||
|
||||
run_test_integration() {
|
||||
set_platform_timeout
|
||||
|
|
Loading…
Reference in a new issue