|
| 1 | +package com.github.dockerjava.transport; |
| 2 | + |
| 3 | +import com.github.dockerjava.transport.DockerHttpClient.Request; |
| 4 | +import com.github.dockerjava.transport.DockerHttpClient.Request.Method; |
| 5 | +import com.github.dockerjava.transport.DockerHttpClient.Response; |
| 6 | +import okhttp3.mockwebserver.MockResponse; |
| 7 | +import okhttp3.mockwebserver.MockWebServer; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +import java.net.URI; |
| 11 | + |
| 12 | +import static org.assertj.core.api.Assertions.assertThat; |
| 13 | + |
| 14 | +public abstract class DockerHttpClientTCK { |
| 15 | + |
| 16 | + protected abstract DockerHttpClient createDockerHttpClient(URI dockerHost, SSLConfig sslConfig); |
| 17 | + |
| 18 | + /** |
| 19 | + * Test that docker-java supports path in DOCKER_HOST |
| 20 | + * |
| 21 | + * @see <a href="https://github.com/moby/moby/blob/7b9275c0da707b030e62c96b679a976f31f929d3/opts/hosts_test.go#L64">valid values</a> |
| 22 | + */ |
| 23 | + @Test |
| 24 | + public final void testPath() throws Exception { |
| 25 | + try (MockWebServer server = new MockWebServer()) { |
| 26 | + String dockerHost = server.url("/%20some/path/").toString() |
| 27 | + .replace("http://", "tcp://"); |
| 28 | + |
| 29 | + try (DockerHttpClient client = createDockerHttpClient(dockerHost)) { |
| 30 | + server.enqueue(new MockResponse().setResponseCode(200)); |
| 31 | + ping(client); |
| 32 | + assertThat(server.takeRequest().getPath()) |
| 33 | + .as("recorded path") |
| 34 | + .isEqualTo("/%20some/path/_ping"); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + private DockerHttpClient createDockerHttpClient(String dockerHost) { |
| 40 | + return createDockerHttpClient(URI.create(dockerHost), null); |
| 41 | + } |
| 42 | + |
| 43 | + private void ping(DockerHttpClient client) { |
| 44 | + Request pingRequest = Request.builder() |
| 45 | + .method(Method.GET) |
| 46 | + .path("/_ping") |
| 47 | + .build(); |
| 48 | + |
| 49 | + try (Response response = client.execute(pingRequest)) { |
| 50 | + assertThat(response.getStatusCode()) |
| 51 | + .as("status code") |
| 52 | + .isEqualTo(200); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments