Skip to content

Commit f25c564

Browse files
authored
Merge pull request #126 from ebean-orm/feature/125-followup
Followup tidy for #125, deleting a container and its volumes
2 parents 6aceb4f + 9c29a0d commit f25c564

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/main/java/io/ebean/test/containers/Commands.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ public void stop(String containerName) {
8585
public void removeContainers(String... containerNames) {
8686
log.log(Level.DEBUG, "remove {0}", Arrays.toString(containerNames));
8787
try {
88-
final List<String> cmds = dockerCmd("rm", "-f", "--volumes");
89-
cmds.addAll(Arrays.asList(containerNames));
90-
ProcessHandler.command(cmds);
88+
var args = new ArrayList<String>();
89+
args.add("-f");
90+
args.add("--volumes");
91+
args.addAll(Arrays.asList(containerNames));
92+
dockerCmd("rm", args);
9193
} catch (CommandException e) {
9294
log.log(Level.DEBUG, "removing containers that don't exist " + e.getMessage());
9395
}
@@ -96,19 +98,18 @@ public void removeContainers(String... containerNames) {
9698
public void stopContainers(String... containerNames) {
9799
log.log(Level.DEBUG, "stop {0}", Arrays.toString(containerNames));
98100
try {
99-
final List<String> cmds = dockerCmd("stop");
100-
cmds.addAll(Arrays.asList(containerNames));
101-
ProcessHandler.command(cmds);
101+
dockerCmd("stop", Arrays.asList(containerNames));
102102
} catch (CommandException e) {
103103
log.log(Level.DEBUG, "stopping containers that don't exist " + e.getMessage());
104104
}
105105
}
106106

107-
private List<String> dockerCmd(String... args) {
107+
private void dockerCmd(String first, List<String> args) {
108108
final List<String> cmd = new ArrayList<>();
109109
cmd.add(docker);
110-
cmd.addAll(Arrays.asList(args));
111-
return cmd;
110+
cmd.add(first);
111+
cmd.addAll(args);
112+
ProcessHandler.command(cmd);
112113
}
113114

114115
/**

src/test/java/io/ebean/test/containers/PostgresContainerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ void startPortBased() {
9090
.build();
9191

9292
container.stopRemove();
93+
Commands commands = new Commands();
94+
commands.stopContainers("temp_pg15_9824");
95+
commands.removeContainers("temp_pg15_9824");
96+
9397
container.startContainerOnly();
9498

99+
95100
runBasedOnPort(9824);
96101

97102
container.stopRemove();

0 commit comments

Comments
 (0)