Skip to content

Commit 2b6457d

Browse files
committed
fix tests
1 parent b4c5891 commit 2b6457d

7 files changed

Lines changed: 176 additions & 69 deletions

File tree

src/main/java/com/github/dockerjava/api/model/HostConfig.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ public class HostConfig implements Serializable {
236236
@JsonProperty("Tmpfs")
237237
private Map<String, String> tmpFs;
238238

239+
public static HostConfig newHostConfig() {
240+
return new HostConfig();
241+
}
242+
239243
@JsonIgnore
240244
public Bind[] getBinds() {
241245
return (binds == null) ? new Bind[0] : binds.getBinds();
@@ -517,6 +521,12 @@ public HostConfig withBinds(Binds binds) {
517521
return this;
518522
}
519523

524+
public HostConfig withBinds(Bind... binds) {
525+
checkNotNull(binds, "binds was not specified");
526+
setBinds(binds);
527+
return this;
528+
}
529+
520530
/**
521531
* @see #blkioDeviceReadBps
522532
*/
@@ -569,15 +579,15 @@ public HostConfig withBlkioWeightDevice(List<Object> blkioWeightDevice) {
569579
* Add linux <a href="http://man7.org/linux/man-pages/man7/capabilities.7.html">kernel capability</a> to the container. For example:
570580
* adding {@link Capability#MKNOD} allows the container to create special files using the 'mknod' command.
571581
*/
572-
public HostConfig withCapAdd(Capability[] capAdd) {
582+
public HostConfig withCapAdd(Capability... capAdd) {
573583
this.capAdd = capAdd;
574584
return this;
575585
}
576586

577587
/**
578588
* @see #capDrop
579589
*/
580-
public HostConfig withCapDrop(Capability[] capDrop) {
590+
public HostConfig withCapDrop(Capability... capDrop) {
581591
this.capDrop = capDrop;
582592
return this;
583593
}
@@ -646,7 +656,7 @@ public HostConfig withDevices(List<Device> devices) {
646656
/**
647657
* @see #devices
648658
*/
649-
public HostConfig withDevices(Device[] devices) {
659+
public HostConfig withDevices(Device... devices) {
650660
this.devices = devices;
651661
return this;
652662
}
@@ -662,7 +672,7 @@ public HostConfig withDiskQuota(Long diskQuota) {
662672
/**
663673
* @see #dns
664674
*/
665-
public HostConfig withDns(String[] dns) {
675+
public HostConfig withDns(String... dns) {
666676
this.dns = dns;
667677
return this;
668678
}
@@ -675,7 +685,7 @@ public HostConfig withDns(List<String> dns) {
675685
/**
676686
* @see #dnsSearch
677687
*/
678-
public HostConfig withDnsSearch(String[] dnsSearch) {
688+
public HostConfig withDnsSearch(String... dnsSearch) {
679689
this.dnsSearch = dnsSearch;
680690
return this;
681691
}
@@ -688,7 +698,7 @@ public HostConfig withDnsSearch(List<String> dnsSearch) {
688698
/**
689699
* @see #extraHosts
690700
*/
691-
public HostConfig withExtraHosts(String[] extraHosts) {
701+
public HostConfig withExtraHosts(String... extraHosts) {
692702
this.extraHosts = extraHosts;
693703
return this;
694704
}
@@ -720,6 +730,12 @@ public HostConfig withLinks(List<Link> links) {
720730
return this;
721731
}
722732

733+
public HostConfig withLinks(Link... links) {
734+
checkNotNull(links, "links was not specified");
735+
setLinks(links);
736+
return this;
737+
}
738+
723739
/**
724740
* @see #logConfig
725741
*/
@@ -971,8 +987,6 @@ public HostConfig withTmpFs(Map<String, String> tmpFs) {
971987
return this;
972988
}
973989

974-
// end of auto-generated
975-
976990
@Override
977991
public String toString() {
978992
return ToStringBuilder.reflectionToString(this);
@@ -987,4 +1001,5 @@ public boolean equals(Object o) {
9871001
public int hashCode() {
9881002
return HashCodeBuilder.reflectionHashCode(this);
9891003
}
1004+
9901005
}

src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import static com.github.dockerjava.api.model.Capability.MKNOD;
5050
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
51+
import static com.github.dockerjava.api.model.HostConfig.newHostConfig;
5152
import static com.github.dockerjava.cmd.CmdIT.FactoryType.JERSEY;
5253
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23;
5354
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24;
@@ -160,7 +161,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
160161
CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
161162
.withCmd("sleep", "9999")
162163
.withName(container1Name)
163-
.withBinds(bind1, bind2)
164+
.withHostConfig(newHostConfig()
165+
.withBinds(bind1, bind2))
164166
.exec();
165167

166168
LOG.info("Created container1 {}", container1.toString());
@@ -175,7 +177,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
175177
// create a second container with volumes from first container
176178
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
177179
.withCmd("sleep", "9999")
178-
.withVolumesFrom(new VolumesFrom(container1Name))
180+
.withHostConfig(newHostConfig()
181+
.withVolumesFrom(new VolumesFrom(container1Name)))
179182
.exec();
180183

181184
LOG.info("Created container2 {}", container2.toString());
@@ -285,7 +288,10 @@ public void createContainerWithLink() throws DockerException {
285288
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));
286289

287290
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withName(containerName2)
288-
.withCmd("env").withLinks(new Link(containerName1, "container1Link")).exec();
291+
.withCmd("env")
292+
.withHostConfig(newHostConfig()
293+
.withLinks(new Link(containerName1, "container1Link")))
294+
.exec();
289295
LOG.info("Created container {}", container2.toString());
290296
assertThat(container2.getId(), not(isEmptyString()));
291297

@@ -299,7 +305,8 @@ public void createContainerWithLink() throws DockerException {
299305
public void createContainerWithMemorySwappiness() throws DockerException {
300306
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
301307
.withCmd("sleep", "9999")
302-
.withMemorySwappiness(42)
308+
.withHostConfig(newHostConfig()
309+
.withMemorySwappiness(42))
303310
.exec();
304311
assertThat(container.getId(), not(isEmptyString()));
305312
LOG.info("Created container {}", container.toString());
@@ -328,8 +335,9 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
328335
assertNotNull(createNetworkResponse.getId());
329336

330337
CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
331-
.withNetworkMode(networkName)
332338
.withCmd("sleep", "9999")
339+
.withHostConfig(newHostConfig()
340+
.withNetworkMode(networkName))
333341
.withName(containerName1)
334342
.exec();
335343

@@ -343,10 +351,12 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
343351
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));
344352

345353
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
346-
.withNetworkMode(networkName)
354+
.withHostConfig(newHostConfig()
355+
.withNetworkMode(networkName)
356+
.withLinks(new Link(containerName1, containerName1 + "Link"))
357+
)
347358
.withName(containerName2)
348359
.withCmd("env")
349-
.withLinks(new Link(containerName1, containerName1 + "Link"))
350360
.exec();
351361

352362
LOG.info("Created container {}", container2.toString());
@@ -377,10 +387,11 @@ public void createContainerWithCustomIp() throws DockerException {
377387
assertNotNull(createNetworkResponse.getId());
378388

379389
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
380-
.withNetworkMode(networkName)
381390
.withCmd("sleep", "9999")
391+
.withHostConfig(newHostConfig()
392+
.withNetworkMode(networkName))
382393
.withName(containerName1)
383-
.withIpv4Address(subnetPrefix +".100")
394+
.withIpv4Address(subnetPrefix + ".100")
384395
.exec();
385396

386397
assertThat(container.getId(), not(isEmptyString()));
@@ -410,8 +421,9 @@ public void createContainerWithAlias() throws DockerException {
410421
assertNotNull(createNetworkResponse.getId());
411422

412423
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
413-
.withNetworkMode(networkName)
414424
.withCmd("sleep", "9999")
425+
.withHostConfig(newHostConfig()
426+
.withNetworkMode(networkName))
415427
.withName(containerName1)
416428
.withAliases("server" + dockerRule.getKind())
417429
.exec();
@@ -430,8 +442,11 @@ public void createContainerWithAlias() throws DockerException {
430442
@Test
431443
public void createContainerWithCapAddAndCapDrop() throws DockerException {
432444

433-
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCapAdd(NET_ADMIN)
434-
.withCapDrop(MKNOD).exec();
445+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
446+
.withHostConfig(newHostConfig()
447+
.withCapAdd(NET_ADMIN)
448+
.withCapDrop(MKNOD))
449+
.exec();
435450

436451
LOG.info("Created container {}", container.toString());
437452

@@ -451,7 +466,9 @@ public void createContainerWithDns() throws DockerException {
451466
String anotherDnsServer = "8.8.4.4";
452467

453468
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
454-
.withDns(aDnsServer, anotherDnsServer).exec();
469+
.withHostConfig(newHostConfig()
470+
.withDns(aDnsServer, anotherDnsServer))
471+
.exec();
455472

456473
LOG.info("Created container {}", container.toString());
457474

@@ -487,7 +504,9 @@ public void createContainerWithExtraHosts() throws DockerException {
487504

488505
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
489506
.withName("containerextrahosts" + dockerRule.getKind())
490-
.withExtraHosts(extraHosts).exec();
507+
.withHostConfig(newHostConfig()
508+
.withExtraHosts(extraHosts))
509+
.exec();
491510

492511
LOG.info("Created container {}", container.toString());
493512

@@ -503,7 +522,8 @@ public void createContainerWithExtraHosts() throws DockerException {
503522
public void createContainerWithDevices() throws DockerException {
504523

505524
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
506-
.withDevices(new Device("rwm", "/dev/nulo", "/dev/zero")).exec();
525+
.withHostConfig(newHostConfig()
526+
.withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))).exec();
507527

508528
LOG.info("Created container {}", container.toString());
509529

@@ -517,7 +537,7 @@ public void createContainerWithDevices() throws DockerException {
517537

518538
@Test
519539
public void createContainerWithPortBindings() throws DockerException {
520-
int baseport = getFactoryType() == FactoryType.JERSEY? 11000: 12000;
540+
int baseport = getFactoryType() == FactoryType.JERSEY ? 11000 : 12000;
521541

522542
ExposedPort tcp22 = ExposedPort.tcp(22);
523543
ExposedPort tcp23 = ExposedPort.tcp(23);
@@ -528,7 +548,8 @@ public void createContainerWithPortBindings() throws DockerException {
528548
portBindings.bind(tcp23, Binding.bindPort(baseport + 24));
529549

530550
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
531-
.withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();
551+
.withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig()
552+
.withPortBindings(portBindings)).exec();
532553

533554
LOG.info("Created container {}", container.toString());
534555

@@ -581,7 +602,8 @@ public void createContainerWithLinking() throws DockerException {
581602

582603
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
583604
.withName(containerName2)
584-
.withLinks(new Link(containerName1, containerName1 + "Link")).exec();
605+
.withHostConfig(newHostConfig()
606+
.withLinks(new Link(containerName1, containerName1 + "Link"))).exec();
585607

586608
LOG.info("Created container2 {}", container2.toString());
587609
assertThat(container2.getId(), not(isEmptyString()));
@@ -608,7 +630,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
608630
RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);
609631

610632
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
611-
.withRestartPolicy(restartPolicy).exec();
633+
.withHostConfig(newHostConfig()
634+
.withRestartPolicy(restartPolicy)).exec();
612635

613636
LOG.info("Created container {}", container.toString());
614637

@@ -623,7 +646,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
623646
public void createContainerWithPidMode() throws DockerException {
624647

625648
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
626-
.withPidMode("host").exec();
649+
.withHostConfig(newHostConfig()
650+
.withPidMode("host")).exec();
627651

628652
LOG.info("Created container {}", container.toString());
629653

@@ -644,7 +668,8 @@ public void createContainerWithPidMode() throws DockerException {
644668
public void createContainerWithNetworkMode() throws DockerException {
645669

646670
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
647-
.withNetworkMode("host").exec();
671+
.withHostConfig(newHostConfig()
672+
.withNetworkMode("host")).exec();
648673

649674
LOG.info("Created container {}", container.toString());
650675

@@ -677,7 +702,8 @@ public void createContainerWithULimits() throws DockerException {
677702

678703
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
679704
.withName(containerName)
680-
.withUlimits(ulimits).exec();
705+
.withHostConfig(newHostConfig()
706+
.withUlimits(ulimits)).exec();
681707

682708
LOG.info("Created container {}", container.toString());
683709

@@ -720,7 +746,10 @@ public void createContainerWithLabels() throws DockerException {
720746
public void createContainerWithLogConfig() throws DockerException {
721747

722748
LogConfig logConfig = new LogConfig(LogConfig.LoggingType.NONE, null);
723-
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withLogConfig(logConfig).exec();
749+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
750+
.withHostConfig(newHostConfig()
751+
.withLogConfig(logConfig))
752+
.exec();
724753

725754
LOG.info("Created container {}", container.toString());
726755

@@ -789,7 +818,8 @@ public void onNext(Frame item) {
789818
@Test
790819
public void createContainerWithCgroupParent() throws DockerException {
791820
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
792-
.withCgroupParent("/parent").exec();
821+
.withHostConfig(newHostConfig()
822+
.withCgroupParent("/parent")).exec();
793823

794824
LOG.info("Created container {}", container.toString());
795825

src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.dockerjava.api.model.Network;
66
import org.junit.Test;
77

8+
import static com.github.dockerjava.api.model.HostConfig.newHostConfig;
89
import static com.github.dockerjava.junit.DockerAssume.assumeNotSwarm;
910
import static org.junit.Assert.assertFalse;
1011
import static org.junit.Assert.assertTrue;
@@ -40,8 +41,9 @@ public void forceDisconnectFromNetwork() throws InterruptedException {
4041
CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName("testNetwork2" + dockerRule.getKind()).exec();
4142

4243
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
43-
.withNetworkMode("testNetwork2" + dockerRule.getKind())
4444
.withCmd("sleep", "9999")
45+
.withHostConfig(newHostConfig()
46+
.withNetworkMode("testNetwork2" + dockerRule.getKind()))
4547
.exec();
4648

4749
dockerRule.getClient().startContainerCmd(container.getId()).exec();

src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.dockerjava.api.command.InspectContainerResponse;
55
import com.github.dockerjava.api.model.Bind;
66
import com.github.dockerjava.api.model.Container;
7+
import com.github.dockerjava.api.model.HostConfig;
78
import com.github.dockerjava.api.model.Volume;
89
import com.github.dockerjava.core.command.PullImageResultCallback;
910
import com.github.dockerjava.core.command.WaitContainerResultCallback;
@@ -257,7 +258,9 @@ public void testVolumeFilter() throws Exception {
257258

258259
id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
259260
.withLabels(testLabel)
260-
.withBinds(new Bind("TestFilterVolume", new Volume("/test")))
261+
.withHostConfig(HostConfig.newHostConfig()
262+
.withBinds(new Bind("TestFilterVolume", new Volume("/test")))
263+
)
261264
.exec()
262265
.getId();
263266

@@ -285,7 +288,9 @@ public void testNetworkFilter() throws Exception {
285288

286289
id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
287290
.withLabels(testLabel)
288-
.withNetworkMode("TestFilterNetwork")
291+
.withHostConfig(HostConfig.newHostConfig()
292+
.withNetworkMode("TestFilterNetwork")
293+
)
289294
.exec()
290295
.getId();
291296

0 commit comments

Comments
 (0)