Browse code

Fix TEST_FILTER to work for both "integration" and "integration-cli"

The TEST_FILTER variable allows running a single integration or integration-cli
test. However, it failed to work properly for integration-cli tests.

Before:
-----------

# Filtering "integration" tests works:
make TEST_FILTER=TestInspectCpusetInConfigPre120 test-integration
...
DONE 1 tests in 18.331s

# But running a single test in "integration-cli" did not:

make TEST_FILTER=TestSwarmNetworkCreateIssue27866 test-integration
...
DONE 0 tests in 17.314s

Trying to manually add the `/` prefix, didn't work either, because that made the
"grep" fail to find which test-suites to run/skip:

make TEST_FILTER=/TestSwarmNetworkCreateIssue27866 test-integration
---> Making bundle: test-integration (in bundles/test-integration)
make: *** [test-integration] Error 1

After:
-----------

make TEST_FILTER=TestInspectCpusetInConfigPre120 test-integration
...
DONE 1 tests in 18.331s

make TEST_FILTER=TestSwarmNetworkCreateIssue27866 test-integration
...
DONE 12 tests in 26.527s

Note that the `12` tests is still a bit misleading, because every _suite_ is
started (which is counted as a test), but no tests are run. This is still
something that could be improved on.

This patch also makes a small modification to the code that's setting
`integration_api_dirs`, and no longer runs `go list` if not needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/10/21 20:57:40
Showing 1 changed files
... ...
@@ -21,7 +21,6 @@ setup_integration_test_filter() {
21 21
 	if [ -z "${TEST_FILTER}" ]; then
22 22
 		return
23 23
 	fi
24
-	TESTFLAGS+="-test.run ${TEST_FILTER}"
25 24
 
26 25
 	local dirs
27 26
 	dirs=$(grep -rIlE --include '*_test.go' "func .*${TEST_FILTER}.*\(. \*testing\.T\)" ./integration*/ | xargs -I file dirname file | uniq)
... ...
@@ -30,6 +29,8 @@ setup_integration_test_filter() {
30 30
 		if [ -z "${TEST_INTEGRATION_DIR}" ]; then
31 31
 			echo "Skipping integration tests since the supplied filter \"${TEST_FILTER}\" omits all integration tests"
32 32
 			TEST_SKIP_INTEGRATION=1
33
+		else
34
+			TESTFLAGS+=" -test.run ${TEST_FILTER}"
33 35
 		fi
34 36
 	fi
35 37
 
... ...
@@ -37,12 +38,18 @@ setup_integration_test_filter() {
37 37
 		if echo "$dirs" | grep -vq '^./integration-cli$'; then
38 38
 			TEST_SKIP_INTEGRATION_CLI=1
39 39
 			echo "Skipping integration-cli tests since the supplied filter \"${TEST_FILTER}\" omits all integration-cli tests"
40
+		else
41
+			TESTFLAGS+=" -test.run /${TEST_FILTER}"
40 42
 		fi
41 43
 	fi
42 44
 }
43 45
 
44 46
 setup_integration_test_filter
45
-integration_api_dirs="${TEST_INTEGRATION_DIR:-$(go list  -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}'  ./integration/...)}"
47
+if [ -z "${TEST_SKIP_INTEGRATION}" ] && [ -z "${TEST_INTEGRATION_DIR}" ]; then
48
+	integration_api_dirs="$(go list -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}'  ./integration/...)"
49
+else
50
+	integration_api_dirs="${TEST_INTEGRATION_DIR}"
51
+fi
46 52
 
47 53
 run_test_integration() {
48 54
 	set_platform_timeout