Skip to content

Commit 9c9c8ff

Browse files
committed
fix(tests): replace sampletestfile.com with embedded server in HTTP tests (#15646)
The external site sampletestfile.com is down, causing DownloadTest.run() and RequestTest.head() to fail. Use the existing Micronaut embedded server instead, making the tests self-contained and resilient.
1 parent 77c6a4f commit 9c9c8ff

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

core/src/test/java/io/kestra/plugin/core/http/DownloadTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import reactor.core.publisher.FluxSink;
2323

2424
import java.io.IOException;
25-
import java.net.URI;
2625
import java.nio.charset.StandardCharsets;
2726
import java.util.List;
2827

@@ -33,7 +32,8 @@
3332

3433
@KestraTest
3534
class DownloadTest {
36-
public static final String FILE = "https://sampletestfile.com/wp-content/uploads/2023/07/500KB-CSV.csv";
35+
private static final String CSV_CONTENT = "id,name,value\n1,foo,100\n2,bar,200\n3,baz,300\n";
36+
3737
@Inject
3838
private RunContextFactory runContextFactory;
3939

@@ -45,10 +45,15 @@ class DownloadTest {
4545

4646
@Test
4747
void run() throws Exception {
48+
EmbeddedServer embeddedServer = applicationContext.getBean(EmbeddedServer.class);
49+
embeddedServer.start();
50+
51+
String url = embeddedServer.getURI() + "/sample.csv";
52+
4853
Download task = Download.builder()
4954
.id(DownloadTest.class.getSimpleName())
5055
.type(DownloadTest.class.getName())
51-
.uri(Property.of(FILE))
56+
.uri(Property.ofValue(url))
5257
.build();
5358

5459
RunContext runContext = TestsUtils.mockRunContext(this.runContextFactory, task, ImmutableMap.of());
@@ -57,7 +62,7 @@ void run() throws Exception {
5762

5863
assertThat(
5964
IOUtils.toString(this.storageInterface.get(null, null, output.getUri()), StandardCharsets.UTF_8),
60-
is(IOUtils.toString(new URI(FILE).toURL().openStream(), StandardCharsets.UTF_8))
65+
is(CSV_CONTENT)
6166
);
6267
assertThat(output.getUri().toString(), endsWith(".csv"));
6368
}
@@ -222,6 +227,12 @@ void contentDispositionWithDoubleDot() throws Exception {
222227

223228
@Controller()
224229
public static class SlackWebController {
230+
@Get("sample.csv")
231+
public HttpResponse<byte[]> csv() {
232+
return HttpResponse.ok(CSV_CONTENT.getBytes(StandardCharsets.UTF_8))
233+
.contentType(io.micronaut.http.MediaType.TEXT_CSV_TYPE);
234+
}
235+
225236
@Get("500")
226237
public HttpResponse<String> error() {
227238
return HttpResponse.serverError();

core/src/test/java/io/kestra/plugin/core/http/RequestTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ void run() throws Exception {
7474

7575
@Test
7676
void head() throws Exception {
77-
final String url = "https://sampletestfile.com/wp-content/uploads/2023/07/500KB-CSV.csv";
77+
try (
78+
ApplicationContext applicationContext = ApplicationContext.run();
79+
EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();
80+
) {
81+
String url = server.getURL().toString() + "/headonly";
7882

7983
Request task = Request.builder()
8084
.id(RequestTest.class.getSimpleName())
@@ -83,9 +87,9 @@ void head() throws Exception {
8387
.method(Property.of("HEAD"))
8488
.build();
8589

86-
RunContext runContext = TestsUtils.mockRunContext(this.runContextFactory, task, ImmutableMap.of());
90+
RunContext runContext = TestsUtils.mockRunContext(this.runContextFactory, task, ImmutableMap.of());
8791

88-
Request.Output output = task.run(runContext);
92+
Request.Output output = task.run(runContext);
8993

9094
assertThat(output.getUri(), is(URI.create(url)));
9195
assertThat(output.getHeaders().get("content-length").getFirst(), is("512789"));
@@ -611,6 +615,11 @@ HttpResponse<String> head() {
611615
return HttpResponse.ok();
612616
}
613617

618+
@Head("/headonly")
619+
HttpResponse<Void> headonly() {
620+
return HttpResponse.ok();
621+
}
622+
614623
@Get("/hello417")
615624
HttpResponse<String> hello417() {
616625
return HttpResponse.status(HttpStatus.EXPECTATION_FAILED).body("{ \"hello\": \"world\" }");

0 commit comments

Comments
 (0)