Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 175329f

Browse filesBrowse files
authored
Alwlays use DinD in Swarm tests (#1399)
1 parent 6a0ecaa commit 175329f
Copy full SHA for 175329f

14 files changed

+213
-248
lines changed

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/CreateSecretCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/CreateSecretCmdExecIT.java
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.command.CreateSecretResponse;
4-
import com.github.dockerjava.api.exception.DockerException;
55
import com.github.dockerjava.api.model.Secret;
66
import com.github.dockerjava.api.model.SecretSpec;
77
import com.google.common.collect.Lists;
@@ -21,27 +21,28 @@ public class CreateSecretCmdExecIT extends SwarmCmdIT {
2121
public static final Logger LOG = LoggerFactory.getLogger(CreateSecretCmdExecIT.class);
2222

2323
@Test
24-
public void testCreateSecret() throws DockerException {
24+
public void testCreateSecret() throws Exception {
25+
DockerClient dockerClient = startSwarm();
2526
int length = 10;
2627
boolean useLetters = true;
2728
boolean useNumbers = false;
2829
String secretName = RandomStringUtils.random(length, useLetters, useNumbers);
29-
CreateSecretResponse exec = dockerRule.getClient().createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
30+
CreateSecretResponse exec = dockerClient.createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
3031
assertThat(exec, notNullValue());
3132
assertThat(exec.getId(), notNullValue());
3233
LOG.info("Secret created with ID {}", exec.getId());
3334

3435

35-
List<Secret> secrets = dockerRule.getClient().listSecretsCmd()
36+
List<Secret> secrets = dockerClient.listSecretsCmd()
3637
.withNameFilter(Lists.newArrayList(secretName))
3738
.exec();
3839

3940
assertThat(secrets, IsCollectionWithSize.hasSize(1));
4041

41-
dockerRule.getClient().removeSecretCmd(secrets.get(0).getId())
42+
dockerClient.removeSecretCmd(secrets.get(0).getId())
4243
.exec();
4344
LOG.info("Secret removed with ID {}", exec.getId());
44-
List<Secret> secretsAfterRemoved = dockerRule.getClient().listSecretsCmd()
45+
List<Secret> secretsAfterRemoved = dockerClient.listSecretsCmd()
4546
.withNameFilter(Lists.newArrayList(secretName))
4647
.exec();
4748

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/CreateServiceCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/CreateServiceCmdExecIT.java
+19-15Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.exception.ConflictException;
45
import com.github.dockerjava.api.exception.DockerException;
56
import com.github.dockerjava.api.model.AuthConfig;
@@ -49,32 +50,35 @@ public class CreateServiceCmdExecIT extends SwarmCmdIT {
4950
public ExpectedException exception = ExpectedException.none();
5051
private AuthConfig authConfig;
5152

53+
private DockerClient dockerClient;
54+
5255
@Before
5356
public final void setUpCreateServiceCmdExecIT() throws Exception {
5457
authConfig = REGISTRY.getAuthConfig();
58+
dockerClient = startSwarm();
5559
}
5660

5761
@Test
5862
public void testCreateService() throws DockerException {
59-
dockerRule.getClient().createServiceCmd(new ServiceSpec()
63+
dockerClient.createServiceCmd(new ServiceSpec()
6064
.withName(SERVICE_NAME)
6165
.withTaskTemplate(new TaskSpec()
6266
.withContainerSpec(new ContainerSpec()
6367
.withImage(DEFAULT_IMAGE))))
6468
.exec();
6569

66-
List<Service> services = dockerRule.getClient().listServicesCmd()
70+
List<Service> services = dockerClient.listServicesCmd()
6771
.withNameFilter(Lists.newArrayList(SERVICE_NAME))
6872
.exec();
6973

7074
assertThat(services, hasSize(1));
7175

72-
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
76+
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
7377
}
7478

7579
@Test
7680
public void testCreateServiceWithNetworks() {
77-
String networkId = dockerRule.getClient().createNetworkCmd().withName("networkname")
81+
String networkId = dockerClient.createNetworkCmd().withName("networkname")
7882
.withDriver("overlay")
7983
.withIpam(new Network.Ipam()
8084
.withDriver("default"))
@@ -104,58 +108,58 @@ public void testCreateServiceWithNetworks() {
104108
.withProtocol(PortConfigProtocol.TCP)
105109
)));
106110

107-
dockerRule.getClient().createServiceCmd(spec).exec();
111+
dockerClient.createServiceCmd(spec).exec();
108112

109-
List<Service> services = dockerRule.getClient().listServicesCmd()
113+
List<Service> services = dockerClient.listServicesCmd()
110114
.withNameFilter(Lists.newArrayList(SERVICE_NAME))
111115
.exec();
112116

113117
assertThat(services, hasSize(1));
114118

115119
assertThat(services.get(0).getSpec(), is(spec));
116120

117-
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
121+
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
118122
}
119123

120124
@Test
121125
public void testCreateServiceWithTmpfs() {
122126
Mount tmpMount = new Mount().withTmpfsOptions(new TmpfsOptions().withSizeBytes(600L)).withTarget("/tmp/foo");
123127

124-
dockerRule.getClient().createServiceCmd(new ServiceSpec()
128+
dockerClient.createServiceCmd(new ServiceSpec()
125129
.withName(SERVICE_NAME)
126130
.withTaskTemplate(new TaskSpec()
127131
.withContainerSpec(new ContainerSpec().withImage(DEFAULT_IMAGE).withMounts(Collections.singletonList(tmpMount)))))
128132
.exec();
129133

130-
List<Service> services = dockerRule.getClient().listServicesCmd()
134+
List<Service> services = dockerClient.listServicesCmd()
131135
.withNameFilter(Lists.newArrayList(SERVICE_NAME))
132136
.exec();
133137

134138
assertThat(services, hasSize(1));
135-
List<Mount> mounts = dockerRule.getClient().inspectServiceCmd(SERVICE_NAME).exec().getSpec().getTaskTemplate()
139+
List<Mount> mounts = dockerClient.inspectServiceCmd(SERVICE_NAME).exec().getSpec().getTaskTemplate()
136140
.getContainerSpec().getMounts();
137141
assertThat(mounts, hasSize(1));
138142
assertThat(mounts.get(0), is(tmpMount));
139-
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
143+
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
140144
}
141145

142146
@Test
143147
public void testCreateServiceWithValidAuth() throws DockerException {
144-
dockerRule.getClient().createServiceCmd(new ServiceSpec()
148+
dockerClient.createServiceCmd(new ServiceSpec()
145149
.withName(SERVICE_NAME)
146150
.withTaskTemplate(new TaskSpec()
147151
.withContainerSpec(new ContainerSpec()
148152
.withImage(DEFAULT_IMAGE))))
149153
.withAuthConfig(authConfig)
150154
.exec();
151155

152-
List<Service> services = dockerRule.getClient().listServicesCmd()
156+
List<Service> services = dockerClient.listServicesCmd()
153157
.withNameFilter(Lists.newArrayList(SERVICE_NAME))
154158
.exec();
155159

156160
assertThat(services, hasSize(1));
157161

158-
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
162+
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
159163
}
160164

161165
@Test
@@ -169,7 +173,7 @@ public void testCreateServiceWithInvalidAuth() throws DockerException {
169173

170174
exception.expect(ConflictException.class);
171175

172-
dockerRule.getClient().createServiceCmd(new ServiceSpec()
176+
dockerClient.createServiceCmd(new ServiceSpec()
173177
.withName(SERVICE_NAME)
174178
.withTaskTemplate(new TaskSpec()
175179
.withContainerSpec(new ContainerSpec()

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/InitializeSwarmCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/InitializeSwarmCmdExecIT.java
+7-16Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.exception.DockerException;
45
import com.github.dockerjava.api.model.Swarm;
56
import com.github.dockerjava.api.model.SwarmCAConfig;
@@ -20,13 +21,9 @@ public class InitializeSwarmCmdExecIT extends SwarmCmdIT {
2021

2122
public static final Logger LOG = LoggerFactory.getLogger(InitializeSwarmCmdExecIT.class);
2223

23-
@Override
24-
protected boolean shouldInitializeByDefault() {
25-
return false;
26-
}
27-
2824
@Test
29-
public void initializeSwarm() throws DockerException {
25+
public void initializeSwarm() throws Exception {
26+
DockerClient dockerClient = startDockerInDocker();
3027
SwarmSpec swarmSpec = new SwarmSpec()
3128
.withName("default")
3229
.withDispatcher(new SwarmDispatcherConfig()
@@ -42,29 +39,23 @@ public void initializeSwarm() throws DockerException {
4239
.withLogEntriesForSlowFollowers(200)
4340
).withTaskDefaults(new TaskDefaults());
4441

45-
dockerRule.getClient().initializeSwarmCmd(swarmSpec)
42+
dockerClient.initializeSwarmCmd(swarmSpec)
4643
.withListenAddr("127.0.0.1")
4744
.withAdvertiseAddr("127.0.0.1")
4845
.exec();
4946
LOG.info("Initialized swarm: {}", swarmSpec.toString());
5047

51-
Swarm swarm = dockerRule.getClient().inspectSwarmCmd().exec();
48+
Swarm swarm = dockerClient.inspectSwarmCmd().exec();
5249
LOG.info("Inspected swarm: {}", swarm.toString());
5350
assertThat(swarm.getSpec(), is(equalTo(swarmSpec)));
5451
}
5552

5653
@Test(expected = DockerException.class)
5754
public void initializingSwarmThrowsWhenAlreadyInSwarm() throws DockerException {
58-
SwarmSpec swarmSpec = new SwarmSpec();
59-
60-
dockerRule.getClient().initializeSwarmCmd(swarmSpec)
61-
.withListenAddr("127.0.0.1")
62-
.withAdvertiseAddr("127.0.0.1")
63-
.exec();
64-
LOG.info("Initialized swarm: {}", swarmSpec.toString());
55+
DockerClient dockerClient = startSwarm();
6556

6657
// Initializing a swarm if already in swarm mode should fail
67-
dockerRule.getClient().initializeSwarmCmd(swarmSpec)
58+
dockerClient.initializeSwarmCmd(new SwarmSpec())
6859
.withListenAddr("127.0.0.1")
6960
.exec();
7061
}

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/JoinSwarmCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/JoinSwarmCmdExecIT.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import static org.hamcrest.Matchers.equalTo;
1818
import static org.hamcrest.Matchers.is;
1919

20-
public class JoinSwarmCmdExecIT extends MultiNodeSwarmCmdIT {
20+
public class JoinSwarmCmdExecIT extends SwarmCmdIT {
2121

2222
public static final Logger LOG = LoggerFactory.getLogger(JoinSwarmCmdExecIT.class);
2323

+8-15Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.exception.DockerException;
45
import com.github.dockerjava.api.model.Info;
56
import com.github.dockerjava.api.model.LocalNodeState;
6-
import com.github.dockerjava.api.model.SwarmSpec;
77
import org.junit.Test;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
@@ -15,38 +15,31 @@ public class LeaveSwarmCmdExecIT extends SwarmCmdIT {
1515

1616
public static final Logger LOG = LoggerFactory.getLogger(LeaveSwarmCmdExecIT.class);
1717

18-
@Override
19-
protected boolean shouldInitializeByDefault() {
20-
return false;
21-
}
22-
2318
@Test
2419
public void leaveSwarmAsMaster() throws DockerException {
25-
dockerRule.getClient().initializeSwarmCmd(new SwarmSpec())
26-
.withListenAddr("127.0.0.1")
27-
.withAdvertiseAddr("127.0.0.1")
28-
.exec();
20+
DockerClient dockerClient = startSwarm();
2921

30-
Info info = dockerRule.getClient().infoCmd().exec();
22+
Info info = dockerClient.infoCmd().exec();
3123
LOG.info("Inspected docker: {}", info.toString());
3224

3325
assertThat(info.getSwarm().getLocalNodeState(), is(LocalNodeState.ACTIVE));
3426

35-
dockerRule.getClient().leaveSwarmCmd()
27+
dockerClient.leaveSwarmCmd()
3628
.withForceEnabled(true)
3729
.exec();
3830
LOG.info("Left swarm");
3931

40-
info = dockerRule.getClient().infoCmd().exec();
32+
info = dockerClient.infoCmd().exec();
4133
LOG.info("Inspected docker: {}", info.toString());
4234

4335
assertThat(info.getSwarm().getLocalNodeState(), is(LocalNodeState.INACTIVE));
4436

4537
}
4638

4739
@Test(expected = DockerException.class)
48-
public void leavingSwarmThrowsWhenNotInSwarm() throws DockerException {
49-
dockerRule.getClient().leaveSwarmCmd().exec();
40+
public void leavingSwarmThrowsWhenNotInSwarm() throws Exception {
41+
DockerClient dockerClient = startDockerInDocker();
42+
dockerClient.leaveSwarmCmd().exec();
5043
}
5144

5245
}

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/ListSecretCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/ListSecretCmdExecIT.java
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.command.CreateSecretResponse;
45
import com.github.dockerjava.api.exception.DockerException;
56
import com.github.dockerjava.api.model.Secret;
@@ -22,26 +23,27 @@ public class ListSecretCmdExecIT extends SwarmCmdIT {
2223

2324
@Test
2425
public void tesListSecret() throws DockerException {
26+
DockerClient dockerClient = startSwarm();
2527
int length = 10;
2628
boolean useLetters = true;
2729
boolean useNumbers = false;
2830
String secretName = RandomStringUtils.random(length, useLetters, useNumbers);
29-
CreateSecretResponse exec = dockerRule.getClient().createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
31+
CreateSecretResponse exec = dockerClient.createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
3032
assertThat(exec, notNullValue());
3133
assertThat(exec.getId(), notNullValue());
3234
LOG.info("Secret created with ID {}", exec.getId());
3335

3436

35-
List<Secret> secrets = dockerRule.getClient().listSecretsCmd()
37+
List<Secret> secrets = dockerClient.listSecretsCmd()
3638
.withNameFilter(Lists.newArrayList(secretName))
3739
.exec();
3840

3941
assertThat(secrets, hasSize(1));
4042

41-
dockerRule.getClient().removeSecretCmd(secrets.get(0).getId())
43+
dockerClient.removeSecretCmd(secrets.get(0).getId())
4244
.exec();
4345
LOG.info("Secret removed with ID {}", exec.getId());
44-
List<Secret> secretsAfterRemoved = dockerRule.getClient().listSecretsCmd()
46+
List<Secret> secretsAfterRemoved = dockerClient.listSecretsCmd()
4547
.withNameFilter(Lists.newArrayList(secretName))
4648
.exec();
4749

‎docker-java/src/test/java/com/github/dockerjava/cmd/swarm/ListServicesCmdExecIT.java

Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/swarm/ListServicesCmdExecIT.java
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.cmd.swarm;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import com.github.dockerjava.api.command.CreateServiceResponse;
45
import com.github.dockerjava.api.model.ContainerSpec;
56
import com.github.dockerjava.api.model.Service;
@@ -27,8 +28,9 @@ public class ListServicesCmdExecIT extends SwarmCmdIT {
2728

2829
@Test
2930
public void testListServices() throws Exception {
31+
DockerClient dockerClient = startSwarm();
3032
Map<String, String> serviceLabels = Collections.singletonMap(LABEL_KEY, LABEL_VALUE);
31-
CreateServiceResponse response = dockerRule.getClient().createServiceCmd(new ServiceSpec()
33+
CreateServiceResponse response = dockerClient.createServiceCmd(new ServiceSpec()
3234
.withLabels(serviceLabels)
3335
.withName(SERVICE_NAME)
3436
.withMode(new ServiceModeConfig().withReplicated(
@@ -41,14 +43,14 @@ public void testListServices() throws Exception {
4143
.exec();
4244
String serviceId = response.getId();
4345
//filtering with service id
44-
List<Service> services = dockerRule.getClient().listServicesCmd().withIdFilter(Collections.singletonList(serviceId)).exec();
46+
List<Service> services = dockerClient.listServicesCmd().withIdFilter(Collections.singletonList(serviceId)).exec();
4547
assertThat(services, hasSize(1));
4648
//filtering with service name
47-
services = dockerRule.getClient().listServicesCmd().withNameFilter(Collections.singletonList(SERVICE_NAME)).exec();
49+
services = dockerClient.listServicesCmd().withNameFilter(Collections.singletonList(SERVICE_NAME)).exec();
4850
assertThat(services, hasSize(1));
4951
//filter labels
50-
services = dockerRule.getClient().listServicesCmd().withLabelFilter(serviceLabels).exec();
52+
services = dockerClient.listServicesCmd().withLabelFilter(serviceLabels).exec();
5153
assertThat(services, hasSize(1));
52-
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
54+
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
5355
}
5456
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.