Skip to content

Commit 71eb480

Browse files
authored
[v0.9.0] fixed incompatibility with spring-boot 3.x (#68)
1 parent c6d63a5 commit 71eb480

28 files changed

+562
-329
lines changed

.github/overview.png

174 KB
Loading

.github/test-app/pom.xml renamed to .github/test-app-sb-2x/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<artifactId>test-app</artifactId>
1313
<version>0.0.2</version>
1414
<name>test-app</name>
15-
<description>Dummy app for tests</description>
15+
<description>Dummy app for tests with spring-boot v2</description>
1616
<properties>
1717
<java.version>11</java.version>
1818
<ngrok-spring-boot-starter.version>SNAPSHOT</ngrok-spring-boot-starter.version>
@@ -46,4 +46,4 @@
4646
</plugin>
4747
</plugins>
4848
</build>
49-
</project>
49+
</project>

.github/test-app-sb-3x/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.1.3</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>io.github.kilmajster</groupId>
12+
<artifactId>test-app</artifactId>
13+
<version>0.0.1</version>
14+
<name>test-app</name>
15+
<description>Dummy app for tests with spring-boot v3</description>
16+
<properties>
17+
<java.version>17</java.version>
18+
<ngrok-spring-boot-starter.version>SNAPSHOT</ngrok-spring-boot-starter.version>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>io.github.kilmajster</groupId>
23+
<artifactId>ngrok-spring-boot-starter</artifactId>
24+
<version>${ngrok-spring-boot-starter.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.apache.commons</groupId>
32+
<artifactId>commons-lang3</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-test</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-maven-plugin</artifactId>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.kilmajster;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
@SpringBootApplication
10+
public class App {
11+
12+
public static void main(String[] args) { SpringApplication.run(App.class, args); }
13+
14+
public @GetMapping("/") String sayHello() { return "<h1>Hello World!</h1>"; }
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ngrok.enabled=true
2+
ngrok.authToken=${NGROK_AUTH_TOKEN}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package io.github.kilmajster;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.extension.ExtendWith;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.system.CapturedOutput;
8+
import org.springframework.boot.test.system.OutputCaptureExtension;
9+
import org.springframework.boot.test.web.server.LocalServerPort;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.client.RestTemplate;
13+
14+
import java.io.IOException;
15+
import java.net.URISyntaxException;
16+
import java.net.URL;
17+
import java.util.Arrays;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Fail.fail;
21+
22+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
23+
@ExtendWith(OutputCaptureExtension.class)
24+
class AppTests {
25+
26+
static final int WAIT_FOR_STARTUP_SECONDS = 90;
27+
28+
@LocalServerPort
29+
int serverPort;
30+
31+
32+
@Test
33+
void should_start_ngrok_and_log_tunnel_details(CapturedOutput output) throws IOException, URISyntaxException, InterruptedException {
34+
System.out.println("[automation-test] Waiting for ngrok startup confirmation in output logs...");
35+
waitForNgrokStartConfirmationInLogs(output);
36+
final String ngrokHttpsTunnelUrl = extractNgrokHttpsTunnelUrlFromLogs(output);
37+
System.out.println("[automation-test] Ngrok tunnel is running between ::" + serverPort + " <-> " + ngrokHttpsTunnelUrl);
38+
39+
System.out.println("[automation-test] Executing GET request...");
40+
long timerStart = System.currentTimeMillis();
41+
final ResponseEntity<String> responseFromTunnel = new RestTemplate()
42+
.getForEntity(
43+
new URL(ngrokHttpsTunnelUrl).toURI(),
44+
String.class
45+
);
46+
long timerStop = System.currentTimeMillis();
47+
System.out.println("[automation-test] " + ngrokHttpsTunnelUrl + " responded in "
48+
+ (timerStop - timerStart) + "ms with\n\n" + responseFromTunnel + "\n");
49+
50+
assertThat(responseFromTunnel.getStatusCode()).isEqualTo(HttpStatus.OK);
51+
assertThat(responseFromTunnel.getBody()).isEqualTo("<h1>Hello World!</h1>");
52+
}
53+
54+
private String extractNgrokHttpsTunnelUrlFromLogs(CapturedOutput output) {
55+
return Arrays.stream(StringUtils.split(output.toString(), " "))
56+
.filter(this::isNgrokAppLink).findFirst().get();
57+
}
58+
59+
private boolean isNgrokAppLink(String s) {
60+
return s != null
61+
&& s.startsWith("https://")
62+
&& StringUtils.containsAny(s, "ngrok.io", "ngrok-free.app", "ngrok.app");
63+
}
64+
65+
private void waitForNgrokStartConfirmationInLogs(CapturedOutput output) throws InterruptedException {
66+
for (int i = WAIT_FOR_STARTUP_SECONDS; i > 0; i--) {
67+
Thread.sleep(1000);
68+
if (output.toString().contains("Ngrok started successfully!") || output.toString().contains("Ngrok was already running!")) {
69+
Thread.sleep(2000);
70+
return;
71+
}
72+
}
73+
fail("Ngrok not started!");
74+
}
75+
}

.github/workflows/automation-test-macos.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,30 @@ jobs:
1414
runs-on: macos-latest
1515
steps:
1616
- uses: actions/checkout@v2
17+
1718
- name: Set up JDK 11
18-
uses: actions/setup-java@v1
19+
uses: actions/setup-java@v3
1920
with:
20-
java-version: 11
21+
distribution: 'adopt'
22+
java-version: '11'
2123

2224
- name: Silent install main project
2325
run: mvn --batch-mode --no-transfer-progress install -Dmaven.test.skip=true
2426

25-
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app
26-
working-directory: ./.github/test-app/
27+
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app and spring-boot v2
28+
working-directory: ./.github/test-app-sb-2x/
2729
env:
2830
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
2931
run: mvn --batch-mode --no-transfer-progress test
32+
33+
- name: Set up JDK 17
34+
uses: actions/setup-java@v3
35+
with:
36+
distribution: 'adopt'
37+
java-version: '17'
38+
39+
- name: Run automation tests with latest ngrok-spring-boot-starter version on test-app and spring-boot v3
40+
working-directory: ./.github/test-app-sb-3x/
41+
env:
42+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
43+
run: mvn --batch-mode --no-transfer-progress test

0 commit comments

Comments
 (0)