use of com.spotify.docker.client.messages.swarm.PortConfig.PortConfigPublishMode in project docker-client by spotify.
the class DefaultDockerClientTest method testInspectServiceEndpoint.
@Test
public void testInspectServiceEndpoint() throws Exception {
requireDockerApiVersionAtLeast("1.24", "swarm support");
final String name = randomName();
final String imageName = "demo/test";
final PortConfig.Builder portConfigBuilder = PortConfig.builder().name("web").protocol("tcp").publishedPort(8080).targetPort(80);
if (dockerApiVersionAtLeast("1.25")) {
portConfigBuilder.publishMode(PortConfigPublishMode.INGRESS);
}
final PortConfig expectedPort1 = portConfigBuilder.build();
final ServiceSpec spec = ServiceSpec.builder().name(name).endpointSpec(EndpointSpec.builder().addPort(expectedPort1).addPort(PortConfig.builder().targetPort(22).publishMode(PortConfigPublishMode.HOST).build()).build()).taskTemplate(TaskSpec.builder().containerSpec(ContainerSpec.builder().image(imageName).build()).build()).build();
sut.createService(spec);
final Service service = sut.inspectService(name);
final Endpoint endpoint = service.endpoint();
final PortConfig.Builder portConfigBuilder2 = PortConfig.builder().targetPort(22).protocol("tcp");
if (dockerApiVersionAtLeast("1.25")) {
portConfigBuilder2.publishMode(PortConfigPublishMode.HOST);
}
final PortConfig expectedPort2Spec = portConfigBuilder2.build();
assertThat(endpoint.spec().ports(), containsInAnyOrder(expectedPort1, expectedPort2Spec));
// API versions less than 1.25 get assigned a random published port and have null publish mode
final Matcher<Integer> publishedPortMatcher;
final Matcher<PortConfigPublishMode> publishModeMatcher;
if (dockerApiVersionLessThan("1.25")) {
publishedPortMatcher = any(Integer.class);
publishModeMatcher = nullValue(PortConfigPublishMode.class);
} else {
publishedPortMatcher = nullValue(Integer.class);
publishModeMatcher = equalTo(PortConfigPublishMode.HOST);
}
// noinspection unchecked
assertThat(endpoint.ports(), containsInAnyOrder(equalTo(expectedPort1), portConfigWith(nullValue(String.class), equalTo("tcp"), equalTo(22), publishedPortMatcher, publishModeMatcher)));
// noinspection ConstantConditions
assertThat(endpoint.virtualIps().size(), equalTo(1));
}
Aggregations