|
1 | 1 | package org.testcontainers.dockerclient; |
2 | 2 |
|
3 | | -import com.github.dockerjava.core.DefaultDockerClientConfig; |
4 | | -import com.github.dockerjava.core.DockerClientConfig; |
5 | | -import org.junit.Ignore; |
| 3 | +import com.github.dockerjava.api.DockerClient; |
6 | 4 | import org.junit.Test; |
| 5 | +import org.testcontainers.DockerClientFactory; |
| 6 | + |
| 7 | +import java.net.URI; |
7 | 8 |
|
8 | 9 | import static org.junit.Assert.assertEquals; |
9 | 10 | import static org.junit.Assert.assertNotNull; |
10 | 11 | import static org.junit.Assert.assertNull; |
11 | 12 |
|
12 | 13 | public class DockerClientConfigUtilsTest { |
13 | 14 |
|
| 15 | + DockerClient client = DockerClientFactory.lazyClient(); |
| 16 | + |
14 | 17 | @Test |
15 | 18 | public void getDockerHostIpAddressShouldReturnLocalhostWhenUnixSocket() { |
16 | | - DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder() |
17 | | - .withDockerHost("unix:///var/run/docker.sock") |
18 | | - .withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588 |
19 | | - .build(); |
20 | | - String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); |
| 19 | + String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("unix:///var/run/docker.sock")); |
21 | 20 | assertEquals("localhost", actual); |
22 | 21 | } |
23 | 22 |
|
24 | | - @Test @Ignore |
25 | | - public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpUri() { |
26 | | - DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("http://12.23.34.45").build(); |
27 | | - String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); |
28 | | - assertEquals("12.23.34.45", actual); |
29 | | - } |
30 | | - |
31 | | - @Test @Ignore |
| 23 | + @Test |
32 | 24 | public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpsUri() { |
33 | | - DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("https://12.23.34.45").build(); |
34 | | - String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); |
| 25 | + String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("http://12.23.34.45")); |
35 | 26 | assertEquals("12.23.34.45", actual); |
36 | 27 | } |
37 | 28 |
|
38 | 29 | @Test |
39 | 30 | public void getDockerHostIpAddressShouldReturnDockerHostIpWhenTcpUri() { |
40 | | - DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder() |
41 | | - .withDockerHost("tcp://12.23.34.45") |
42 | | - .withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588 |
43 | | - .build(); |
44 | | - String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); |
| 31 | + String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("tcp://12.23.34.45")); |
45 | 32 | assertEquals("12.23.34.45", actual); |
46 | 33 | } |
47 | 34 |
|
48 | | - @Test @Ignore |
| 35 | + @Test |
49 | 36 | public void getDockerHostIpAddressShouldReturnNullWhenUnsupportedUriScheme() { |
50 | | - DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("gopher://12.23.34.45").build(); |
51 | | - String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration); |
| 37 | + String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("gopher://12.23.34.45")); |
52 | 38 | assertNull(actual); |
53 | 39 | } |
54 | 40 |
|
|
0 commit comments