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>
... | ... |
@@ -67,6 +67,8 @@ If a remote daemon is detected, the test will be skipped. |
67 | 67 |
|
68 | 68 |
## Running tests |
69 | 69 |
|
70 |
+### Unit Tests |
|
71 |
+ |
|
70 | 72 |
To run the unit test suite: |
71 | 73 |
|
72 | 74 |
``` |
... | ... |
@@ -82,12 +84,33 @@ The following environment variables may be used to run a subset of tests: |
82 | 82 |
* `TESTFLAGS` - flags passed to `go test`, to run tests which match a pattern |
83 | 83 |
use `TESTFLAGS="-test.run TestNameOrPrefix"` |
84 | 84 |
|
85 |
+### Integration Tests |
|
86 |
+ |
|
85 | 87 |
To run the integration test suite: |
86 | 88 |
|
87 | 89 |
``` |
88 | 90 |
make test-integration |
89 | 91 |
``` |
90 | 92 |
|
93 |
+This make target runs both the "integration" suite and the "integration-cli" |
|
94 |
+suite. |
|
95 |
+ |
|
96 |
+You can specify which integration test dirs to build and run by specifying |
|
97 |
+the list of dirs in the TEST_INTEGRATION_DIR environment variable. |
|
98 |
+ |
|
99 |
+You can also explicitly skip either suite by setting (any value) in |
|
100 |
+TEST_SKIP_INTEGRATION and/or TEST_SKIP_INTEGRATION_CLI environment variables. |
|
101 |
+ |
|
102 |
+Flags specific to each suite can be set in the TESTFLAGS_INTEGRATION and |
|
103 |
+TESTFLAGS_INTEGRATION_CLI environment variables. |
|
104 |
+ |
|
105 |
+If all you want is to specity a test filter to run, you can set the |
|
106 |
+`TEST_FILTER` environment variable. This ends up getting passed directly to `go |
|
107 |
+test -run` (or `go test -check-f`, dpenending on the test suite). It will also |
|
108 |
+automatically set the other above mentioned environment variables accordingly. |
|
109 |
+ |
|
110 |
+### Go Version |
|
111 |
+ |
|
91 | 112 |
You can change a version of golang used for building stuff that is being tested |
92 | 113 |
by setting `GO_VERSION` variable, for example: |
93 | 114 |
|
... | ... |
@@ -27,7 +27,34 @@ source "$MAKEDIR/.go-autogen" |
27 | 27 |
: ${TESTFLAGS:=} |
28 | 28 |
: ${TESTDEBUG:=} |
29 | 29 |
|
30 |
-integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(go list -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}' ./integration/...)"} |
|
30 |
+setup_integration_test_filter() { |
|
31 |
+ if [ -z "${TEST_FILTER}" ]; then |
|
32 |
+ return |
|
33 |
+ fi |
|
34 |
+ |
|
35 |
+ if [ -z "${TEST_SKIP_INTEGRATION}" ]; then |
|
36 |
+ : ${TEST_INTEGRATION_DIR:=$(grep -rl "func\ .*${TEST_FILTER}.*\(t\ \*testing\.T\)" ./integration | grep '_test\.go' | xargs -I file dirname file | uniq)} |
|
37 |
+ if [ -z "${TEST_INTEGRATION_DIR}" ]; then |
|
38 |
+ echo Skipping integration tests since the supplied filter \"${TEST_FILTER}\" omits all integration tests |
|
39 |
+ TEST_SKIP_INTEGRATION=1 |
|
40 |
+ else |
|
41 |
+ TESTFLAGS_INTEGRATION+="-test.run ${TEST_FILTER}" |
|
42 |
+ fi |
|
43 |
+ fi |
|
44 |
+ |
|
45 |
+ if [ -z "${TEST_SKIP_INTEGRATION_CLI}" ]; then |
|
46 |
+ # ease up on the filtering here since CLI suites are namespaced by an object |
|
47 |
+ if grep -r "${TEST_FILTER}.*\(c\ \*check\.C\)" ./integration-cli | grep -q '_test\.go$'; then |
|
48 |
+ TEST_SKIP_INTEGRATION_CLI=1 |
|
49 |
+ echo Skipping integration-cli tests since the supplied filter \"${TEST_FILTER}\" omits all integration-cli tests |
|
50 |
+ else |
|
51 |
+ TESTFLAGS_INTEGRATION_CLI+="-check.f ${TEST_FILTER}" |
|
52 |
+ fi |
|
53 |
+ fi |
|
54 |
+} |
|
55 |
+ |
|
56 |
+setup_integration_test_filter |
|
57 |
+integration_api_dirs=${TEST_INTEGRATION_DIR:-$(go list -test -f '{{- if ne .ForTest "" -}}{{- .Dir -}}{{- end -}}' ./integration/...)} |
|
31 | 58 |
|
32 | 59 |
run_test_integration() { |
33 | 60 |
set_platform_timeout |