use of com.spotify.docker.client.messages.NetworkCreation in project docker-client by spotify.
the class DefaultDockerClientTest method testNetworks.
@Test
public void testNetworks() throws Exception {
requireDockerApiVersionAtLeast("1.21", "createNetwork and listNetworks");
assumeFalse(CIRCLECI);
final String networkName = randomName();
final IpamConfig ipamConfig = IpamConfig.create("192.168.0.0/24", "192.168.0.0/24", "192.168.0.1");
final Ipam ipam = Ipam.builder().driver("default").config(singletonList(ipamConfig)).build();
final Map<String, String> labels = ImmutableMap.of("name", "starship", "foo", "bar");
final NetworkConfig networkConfig = NetworkConfig.builder().name(networkName).driver("bridge").checkDuplicate(true).ipam(ipam).internal(false).enableIPv6(false).labels(labels).build();
final NetworkCreation networkCreation = sut.createNetwork(networkConfig);
assertThat(networkCreation.id(), is(notNullValue()));
assertThat(networkCreation.warnings(), is(nullValue()));
final List<Network> networks = sut.listNetworks();
assertTrue(networks.size() > 0);
Network network = null;
for (final Network n : networks) {
if (n.name().equals(networkName)) {
network = n;
}
}
assertThat(network, is(notNullValue()));
// noinspection ConstantConditions
assertThat(network.id(), is(notNullValue()));
assertThat(sut.inspectNetwork(network.id()).name(), is(networkName));
assertThat(network.ipam(), equalTo(ipam));
if (dockerApiVersionAtLeast("1.23")) {
assertThat(network.internal(), is(false));
assertThat(network.enableIPv6(), is(false));
assertThat(network.labels(), is(labels));
}
sut.removeNetwork(network.id());
exception.expect(NetworkNotFoundException.class);
sut.inspectNetwork(network.id());
}
Aggregations