forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateNetworkCmdIT.java
More file actions
88 lines (70 loc) · 3.99 KB
/
Copy pathCreateNetworkCmdIT.java
File metadata and controls
88 lines (70 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.github.dockerjava.cmd;
import com.github.dockerjava.api.command.CreateNetworkResponse;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.Network;
import net.jcip.annotations.NotThreadSafe;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_21;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_25;
import static com.github.dockerjava.junit.DockerAssume.assumeNotSwarm;
import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeThat;
@NotThreadSafe
public class CreateNetworkCmdIT extends CmdIT {
@Test
public void createNetwork() throws DockerException {
assumeNotSwarm("no network in swarm", dockerRule);
String networkName = "createNetwork" + dockerRule.getKind();
CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).exec();
assertNotNull(createNetworkResponse.getId());
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
assertThat(network.getName(), is(networkName));
assertThat(network.getDriver(), is("bridge"));
}
@Test
public void createNetworkWithIpamConfig() throws DockerException {
assumeNotSwarm("no network in swarm", dockerRule);
String networkName = "networkIpam" + dockerRule.getKind();
String subnet = "10.67." + (79 + getFactoryType().ordinal()) + ".0/24";
Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet(subnet));
CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).withIpam(ipam).exec();
assertNotNull(createNetworkResponse.getId());
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
assertEquals(network.getName(), networkName);
assertEquals("bridge", network.getDriver());
assertEquals(subnet, network.getIpam().getConfig().iterator().next().getSubnet());
}
@Test
public void createAttachableNetwork() throws DockerException {
assumeThat("API version should be > 1.24", dockerRule, isGreaterOrEqual(VERSION_1_25));
String networkName = "createAttachableNetwork" + dockerRule.getKind();
CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
.withName(networkName)
.withAttachable(true)
.exec();
assertNotNull(createNetworkResponse.getId());
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
assertThat(network, notNullValue());
assertTrue(network.isAttachable());
}
@Test
public void createNetworkWithLabel() throws DockerException {
assumeNotSwarm("no network in swarm?", dockerRule);
assumeThat("API version should be >= 1.21", dockerRule, isGreaterOrEqual(VERSION_1_21));
String networkName = "createNetworkWithLabel" + dockerRule.getKind();
Map<String, String> labels = new HashMap<>();
labels.put("com.example.usage" + dockerRule.getKind(), "test");
CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).withLabels(labels).exec();
assertNotNull(createNetworkResponse.getId());
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
assertEquals(network.getLabels(), labels);
}
}