diff --git a/Makefile b/Makefile index a3aeb45eca..71f12d176e 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ DOCKER_ENVS := \ -e TESTFLAGS \ -e TESTFLAGS_INTEGRATION \ -e TESTFLAGS_INTEGRATION_CLI \ + -e TEST_FILTER \ -e TIMEOUT \ -e VALIDATE_REPO \ -e VALIDATE_BRANCH \ diff --git a/TESTING.md b/TESTING.md index 15322f9eed..ba5bcda289 100644 --- a/TESTING.md +++ b/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: diff --git a/hack/make/.integration-test-helpers b/hack/make/.integration-test-helpers index abe69474ae..484aa448c0 100644 --- a/hack/make/.integration-test-helpers +++ b/hack/make/.integration-test-helpers @@ -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