Skip to content

Commit 84ff233

Browse files
committed
Polish "Test the launch script when executed directly"
See gh-21388
1 parent 02a6a84 commit 84ff233

File tree

51 files changed

+165
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+165
-154
lines changed

spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/AbstractLaunchScriptIT.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@
3535
/**
3636
* Abstract base class for testing the launch script.
3737
*
38+
* @author Andy Wilkinson
39+
* @author Ali Shahbour
3840
* @author Alexey Vinogradov
3941
*/
4042
abstract class AbstractLaunchScriptIT {
4143

4244
protected static final char ESC = 27;
4345

46+
private final String scriptsDir;
47+
48+
protected AbstractLaunchScriptIT(String scriptsDir) {
49+
this.scriptsDir = scriptsDir;
50+
}
51+
4452
static List<Object[]> parameters() {
4553
List<Object[]> parameters = new ArrayList<>();
4654
for (File os : new File("src/test/resources/conf").listFiles()) {
@@ -69,7 +77,8 @@ protected void doLaunch(String os, String version, String script) throws Excepti
6977

7078
protected String doTest(String os, String version, String script) throws Exception {
7179
ToStringConsumer consumer = new ToStringConsumer().withRemoveAnsiCodes(false);
72-
try (LaunchScriptTestContainer container = new LaunchScriptTestContainer(os, version, script)) {
80+
try (LaunchScriptTestContainer container = new LaunchScriptTestContainer(os, version, this.scriptsDir,
81+
script)) {
7382
container.withLogConsumer(consumer);
7483
container.start();
7584
while (container.isRunning()) {
@@ -81,17 +90,16 @@ protected String doTest(String os, String version, String script) throws Excepti
8190

8291
private static final class LaunchScriptTestContainer extends GenericContainer<LaunchScriptTestContainer> {
8392

84-
private LaunchScriptTestContainer(String os, String version, String testScript) {
93+
private LaunchScriptTestContainer(String os, String version, String scriptsDir, String testScript) {
8594
super(new ImageFromDockerfile("spring-boot-launch-script/" + os.toLowerCase() + "-" + version)
8695
.withFileFromFile("Dockerfile",
87-
new File("src/test/resources/conf/" + os + "/" + version + "/Dockerfile"))
88-
.withFileFromFile("spring-boot-launch-script-tests.jar", findApplication())
89-
.withFileFromFile("test-functions.sh", new File("src/test/resources/scripts/test-functions.sh"))
90-
.withFileFromFile("jar/test-functions.sh",
91-
new File("src/test/resources/scripts/jar/test-functions.sh"))
92-
.withFileFromFile("init.d/test-functions.sh",
93-
new File("src/test/resources/scripts/init.d/test-functions.sh")));
94-
withCopyFileToContainer(MountableFile.forHostPath("src/test/resources/scripts/" + testScript),
96+
new File("src/test/resources/conf/" + os + "/" + version + "/Dockerfile")));
97+
withCopyFileToContainer(MountableFile.forHostPath(findApplication().getAbsolutePath()),
98+
"/spring-boot-launch-script-tests.jar");
99+
withCopyFileToContainer(
100+
MountableFile.forHostPath("src/test/resources/scripts/" + scriptsDir + "test-functions.sh"),
101+
"/test-functions.sh");
102+
withCopyFileToContainer(MountableFile.forHostPath("src/test/resources/scripts/" + scriptsDir + testScript),
95103
"/" + testScript);
96104
withCommand("/bin/bash", "-c", "chmod +x " + testScript + " && ./" + testScript);
97105
withStartupTimeout(Duration.ofMinutes(10));
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,72 @@
2222
import static org.assertj.core.api.Assertions.assertThat;
2323

2424
/**
25-
* Integration tests of Spring Boot's launch script with launching via shell.
25+
* Integration tests of Spring Boot's launch script when executing the jar directly.
2626
*
2727
* @author Alexey Vinogradov
28+
* @author Andy Wilkinson
2829
*/
29-
class ShellLaunchScriptIT extends AbstractLaunchScriptIT {
30+
class JarLaunchScriptIT extends AbstractLaunchScriptIT {
31+
32+
JarLaunchScriptIT() {
33+
super("jar/");
34+
}
3035

3136
@ParameterizedTest(name = "{0} {1}")
3237
@MethodSource("parameters")
3338
void basicLaunch(String os, String version) throws Exception {
34-
doLaunch(os, version, "jar/basic-launch.sh");
39+
doLaunch(os, version, "basic-launch.sh");
3540
}
3641

3742
@ParameterizedTest(name = "{0} {1}")
3843
@MethodSource("parameters")
3944
void launchWithDebugEnv(String os, String version) throws Exception {
40-
final String output = doTest(os, version, "jar/launch-with-debug.sh");
45+
final String output = doTest(os, version, "launch-with-debug.sh");
4146
assertThat(output).contains("++ pwd");
4247
}
4348

4449
@ParameterizedTest(name = "{0} {1}")
4550
@MethodSource("parameters")
4651
void launchWithDifferentJarFileEnv(String os, String version) throws Exception {
47-
final String output = doTest(os, version, "jar/launch-with-jarfile.sh");
52+
final String output = doTest(os, version, "launch-with-jarfile.sh");
4853
assertThat(output).contains("app-another.jar");
4954
assertThat(output).doesNotContain("spring-boot-launch-script-tests.jar");
5055
}
5156

5257
@ParameterizedTest(name = "{0} {1}")
5358
@MethodSource("parameters")
54-
void launchWithDifferentAppName(String os, String version) throws Exception {
55-
final String output = doTest(os, version, "jar/launch-with-app-name.sh");
56-
assertThat(output).contains("All tests are passed.");
59+
void launchWithSingleCommandLineArgument(String os, String version) throws Exception {
60+
doLaunch(os, version, "launch-with-single-command-line-argument.sh");
61+
}
62+
63+
@ParameterizedTest(name = "{0} {1}")
64+
@MethodSource("parameters")
65+
void launchWithMultipleCommandLineArguments(String os, String version) throws Exception {
66+
doLaunch(os, version, "launch-with-multiple-command-line-arguments.sh");
67+
}
68+
69+
@ParameterizedTest(name = "{0} {1}")
70+
@MethodSource("parameters")
71+
void launchWithSingleRunArg(String os, String version) throws Exception {
72+
doLaunch(os, version, "launch-with-single-run-arg.sh");
73+
}
74+
75+
@ParameterizedTest(name = "{0} {1}")
76+
@MethodSource("parameters")
77+
void launchWithMultipleRunArgs(String os, String version) throws Exception {
78+
doLaunch(os, version, "launch-with-multiple-run-args.sh");
79+
}
80+
81+
@ParameterizedTest(name = "{0} {1}")
82+
@MethodSource("parameters")
83+
void launchWithSingleJavaOpt(String os, String version) throws Exception {
84+
doLaunch(os, version, "launch-with-single-java-opt.sh");
5785
}
5886

5987
@ParameterizedTest(name = "{0} {1}")
6088
@MethodSource("parameters")
61-
void launchInInitdDir(String os, String version) throws Exception {
62-
final String output = doTest(os, version, "jar/launch-in-init.d-dir.sh");
63-
assertThat(output).contains("Usage: ./some_app {start|stop|force-stop|restart|force-reload|status|run}");
89+
void launchWithMultipleJavaOpts(String os, String version) throws Exception {
90+
doLaunch(os, version, "launch-with-multiple-java-opts.sh");
6491
}
6592

6693
}

0 commit comments

Comments
 (0)