Skip to content

Commit d3c512b

Browse files
committed
Integration test for docker.version()
1 parent 7d7f17a commit d3c512b

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

src/main/java/com/amihaiemil/docker/RtDocker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract class RtDocker implements Docker {
4949
* Base URI.
5050
*/
5151
private final URI baseUri;
52-
52+
5353
/**
5454
* Ctor.
5555
* @param client Given HTTP Client.
@@ -59,7 +59,7 @@ abstract class RtDocker implements Docker {
5959
this.client = client;
6060
this.baseUri = baseUri;
6161
}
62-
62+
6363
@Override
6464
public final boolean ping() throws IOException {
6565
final HttpGet ping = new HttpGet(this.baseUri.toString() + "/_ping");
@@ -126,7 +126,7 @@ public final Execs execs() {
126126
public final Swarm swarm() {
127127
return new RtSwarm(
128128
this.client,
129-
URI.create(this.baseUri.toString().concat("/swarm")),
129+
URI.create(this.baseUri.toString().concat("/swarm")),
130130
this
131131
);
132132
}
@@ -157,7 +157,8 @@ public Version version() throws IOException {
157157
final String versionUri = this.baseUri.toString() + "/version";
158158
return new RtVersion(
159159
this.client,
160-
URI.create(versionUri)
160+
URI.create(versionUri),
161+
this
161162
);
162163
}
163164

src/main/java/com/amihaiemil/docker/RtVersion.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,26 @@
3939
* @since 0.0.11
4040
*/
4141
final class RtVersion extends JsonResource implements Version {
42+
43+
/**
44+
* Docker to which this Version belongs.
45+
*/
46+
private final Docker docker;
47+
4248
/**
4349
* Ctor.
4450
* @param client The http client.
4551
* @param uri The URI for this version.
52+
* @param dkr Parent Docker.
4653
* @throws IOException If an I/O error occurs.
4754
*/
48-
RtVersion(final HttpClient client, final URI uri) throws IOException {
55+
RtVersion(
56+
final HttpClient client,
57+
final URI uri,
58+
final Docker dkr
59+
) throws IOException {
4960
super(fetch(client, uri));
61+
this.docker = dkr;
5062
}
5163

5264
/**
@@ -134,4 +146,9 @@ public String arch() {
134146
public boolean experimental() {
135147
return this.getBoolean("Experimental");
136148
}
149+
150+
@Override
151+
public Docker docker() {
152+
return this.docker;
153+
}
137154
}

src/main/java/com/amihaiemil/docker/Version.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ public interface Version extends JsonObject {
4949
* @return Whether experimental docker features are enabled
5050
*/
5151
boolean experimental();
52+
53+
/**
54+
* The Docker engine to which this Version belongs.
55+
* @return Docker.
56+
*/
57+
Docker docker();
5258
}

src/test/java/com/amihaiemil/docker/UnixDockerITCase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ public void returnsInfo() throws Exception {
8080
);
8181
}
8282

83+
/**
84+
* UnixDocker can return the Version of Docker.
85+
* @throws Exception If something goes wrong.
86+
*/
87+
@Test
88+
public void returnsVersion() throws Exception {
89+
final Docker docker = new UnixDocker(
90+
new File("/var/run/docker.sock")
91+
);
92+
final Version version = docker.version();
93+
MatcherAssert.assertThat(version, Matchers.notNullValue());
94+
MatcherAssert.assertThat(version.docker(), Matchers.is(docker));
95+
MatcherAssert.assertThat(
96+
version.platformName(),
97+
Matchers.equalTo("Docker Engine - Community")
98+
);
99+
}
100+
101+
83102
/**
84103
* Docker can return its Events unfiltered.
85104
* @throws Exception If something goes wrong.

0 commit comments

Comments
 (0)