Skip to content

Commit f1c1cd4

Browse files
author
Tibor Vass
committed
integration-cli: move each test suite to its own TestX testing function
Signed-off-by: Tibor Vass <[email protected]>
1 parent 84928be commit f1c1cd4

5 files changed

Lines changed: 68 additions & 21 deletions

File tree

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ pipeline {
307307
TEST_INTEGRATION_DEST=1 CONTAINER_NAME=${CONTAINER_NAME}-1 TEST_SKIP_INTEGRATION_CLI=1 run_tests test-integration-flaky &
308308
309309
# integration-cli first set
310-
TEST_INTEGRATION_DEST=2 CONTAINER_NAME=${CONTAINER_NAME}-2 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run /(DockerSuite|DockerNetworkSuite|DockerHubPullSuite|DockerRegistrySuite|DockerSchema1RegistrySuite|DockerRegistryAuthTokenSuite|DockerRegistryAuthHtpasswdSuite)/" run_tests &
310+
TEST_INTEGRATION_DEST=2 CONTAINER_NAME=${CONTAINER_NAME}-2 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run Test(DockerSuite|DockerNetworkSuite|DockerHubPullSuite|DockerRegistrySuite|DockerSchema1RegistrySuite|DockerRegistryAuthTokenSuite|DockerRegistryAuthHtpasswdSuite)/" run_tests &
311311
312312
# integration-cli second set
313-
TEST_INTEGRATION_DEST=3 CONTAINER_NAME=${CONTAINER_NAME}-3 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run /(DockerSwarmSuite|DockerDaemonSuite|DockerExternalVolumeSuite)/" run_tests &
313+
TEST_INTEGRATION_DEST=3 CONTAINER_NAME=${CONTAINER_NAME}-3 TEST_SKIP_INTEGRATION=1 TESTFLAGS="-test.run Test(DockerSwarmSuite|DockerDaemonSuite|DockerExternalVolumeSuite)/" run_tests &
314314
315315
set +x
316316
c=0

docs/contributing/test.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ flag's value is passed as arguments to the `go test` command. For example, from
174174
your local host you can run the `TestBuild` test with this command:
175175

176176
```bash
177-
$ TESTFLAGS='-test.run /DockerSuite/TestBuild*' make test-integration
177+
$ TESTFLAGS='-test.run TestDockerSuite/TestBuild*' make test-integration
178178
```
179179

180180
To run the same test inside your Docker development container, you do this:
181181

182182
```bash
183-
# TESTFLAGS='-test.run /DockerSuite/TestBuild*' hack/make.sh binary test-integration
183+
# TESTFLAGS='-test.run TestDockerSuite/TestBuild*' hack/make.sh binary test-integration
184184
```
185185

186186
## Test the Windows binary against a Linux daemon
@@ -228,11 +228,11 @@ run a Bash terminal on Windows.
228228
```
229229

230230
Should you wish to run a single test such as one with the name
231-
'TestExample', you can pass in `TESTFLAGS='-test.run //TestExample'`. For
231+
'TestExample', you can pass in `TESTFLAGS='-test.run /TestExample'`. For
232232
example
233233

234234
```bash
235-
$ TESTFLAGS='-test.run //TestExample' hack/make.sh binary test-integration
235+
$ TESTFLAGS='-test.run /TestExample' hack/make.sh binary test-integration
236236
```
237237

238238
You can now choose to make changes to the Moby source or the tests. If you

hack/make/.integration-test-helpers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
44
# to run certain tests on your local host, you should run with command:
55
#
6-
# TESTFLAGS='-test.run /DockerSuite/TestBuild*' ./hack/make.sh binary test-integration
6+
# TESTFLAGS='-test.run TestDockerSuite/TestBuild*' ./hack/make.sh binary test-integration
77
#
88

99
if [ -z "${MAKEDIR}" ]; then

integration-cli/check_test.go

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"path"
1111
"path/filepath"
12-
"runtime"
1312
"strconv"
1413
"sync"
1514
"syscall"
@@ -45,6 +44,8 @@ var (
4544

4645
// the docker client binary to use
4746
dockerBinary = ""
47+
48+
testEnvOnce sync.Once
4849
)
4950

5051
func init() {
@@ -74,25 +75,72 @@ func TestMain(m *testing.M) {
7475
os.Exit(m.Run())
7576
}
7677

77-
func Test(t *testing.T) {
78-
cli.SetTestEnvironment(testEnv)
79-
fakestorage.SetTestEnvironment(&testEnv.Execution)
80-
ienv.ProtectAll(t, &testEnv.Execution)
78+
func ensureTestEnvSetup(t *testing.T) {
79+
testEnvOnce.Do(func() {
80+
cli.SetTestEnvironment(testEnv)
81+
fakestorage.SetTestEnvironment(&testEnv.Execution)
82+
ienv.ProtectAll(t, &testEnv.Execution)
83+
})
84+
}
85+
86+
func TestDockerSuite(t *testing.T) {
87+
ensureTestEnvSetup(t)
8188
suite.Run(t, &DockerSuite{})
89+
}
90+
91+
func TestDockerRegistrySuite(t *testing.T) {
92+
ensureTestEnvSetup(t)
8293
suite.Run(t, &DockerRegistrySuite{ds: &DockerSuite{}})
94+
}
95+
96+
func TestDockerSchema1RegistrySuite(t *testing.T) {
97+
ensureTestEnvSetup(t)
8398
suite.Run(t, &DockerSchema1RegistrySuite{ds: &DockerSuite{}})
99+
}
100+
101+
func TestDockerRegistryAuthHtpasswdSuite(t *testing.T) {
102+
ensureTestEnvSetup(t)
84103
suite.Run(t, &DockerRegistryAuthHtpasswdSuite{ds: &DockerSuite{}})
104+
}
105+
106+
func TestDockerRegistryAuthTokenSuite(t *testing.T) {
107+
ensureTestEnvSetup(t)
85108
suite.Run(t, &DockerRegistryAuthTokenSuite{ds: &DockerSuite{}})
109+
}
110+
111+
func TestDockerDaemonSuite(t *testing.T) {
112+
ensureTestEnvSetup(t)
86113
suite.Run(t, &DockerDaemonSuite{ds: &DockerSuite{}})
114+
}
115+
116+
func TestDockerSwarmSuite(t *testing.T) {
117+
ensureTestEnvSetup(t)
87118
suite.Run(t, &DockerSwarmSuite{ds: &DockerSuite{}})
119+
}
120+
121+
func TestDockerPluginSuite(t *testing.T) {
122+
ensureTestEnvSetup(t)
88123
suite.Run(t, &DockerPluginSuite{ds: &DockerSuite{}})
89-
if runtime.GOOS != "windows" {
90-
suite.Run(t, &DockerExternalVolumeSuite{ds: &DockerSuite{}})
91-
suite.Run(t, &DockerNetworkSuite{ds: &DockerSuite{}})
92-
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
93-
// Windows to Linux CI @icecrime
94-
suite.Run(t, newDockerHubPullSuite())
95-
}
124+
}
125+
126+
func TestDockerExternalVolumeSuite(t *testing.T) {
127+
ensureTestEnvSetup(t)
128+
testRequires(t, DaemonIsLinux)
129+
suite.Run(t, &DockerExternalVolumeSuite{ds: &DockerSuite{}})
130+
}
131+
132+
func TestDockerNetworkSuite(t *testing.T) {
133+
ensureTestEnvSetup(t)
134+
testRequires(t, DaemonIsLinux)
135+
suite.Run(t, &DockerExternalVolumeSuite{ds: &DockerSuite{}})
136+
}
137+
138+
func TestDockerHubPullSuite(t *testing.T) {
139+
ensureTestEnvSetup(t)
140+
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
141+
// Windows to Linux CI @icecrime
142+
testRequires(t, DaemonIsLinux)
143+
suite.Run(t, newDockerHubPullSuite())
96144
}
97145

98146
type DockerSuite struct {

internal/test/suite/suite.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ func Run(t *testing.T, suite interface{}) {
3030
}()
3131

3232
methodFinder := reflect.TypeOf(suite)
33-
suiteName := methodFinder.Elem().Name()
3433
for index := 0; index < methodFinder.NumMethod(); index++ {
3534
method := methodFinder.Method(index)
3635
if !methodFilter(method.Name, method.Type) {
3736
continue
3837
}
39-
t.Run(suiteName+"/"+method.Name, func(t *testing.T) {
38+
t.Run(method.Name, func(t *testing.T) {
4039
defer failOnPanic(t)
4140

4241
if !suiteSetupDone {

0 commit comments

Comments
 (0)