Skip to content

Commit

Permalink
fix(core): Concat must allow to specify a file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu authored and tchiotludo committed Sep 25, 2023
1 parent 7e3bf8e commit a0ef8e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/io/kestra/core/tasks/storages/Concat.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.net.URI;
import java.util.List;

import javax.validation.constraints.NotNull;

import static io.kestra.core.utils.Rethrow.throwConsumer;

@SuperBuilder
Expand Down Expand Up @@ -89,6 +91,7 @@ public class Concat extends Task implements RunnableTask<Concat.Output> {
description = "Must be a `kestra://` storage urls, can be a list of string or json string"
)
@PluginProperty(dynamic = true)
@NotNull
private Object files;

@Schema(
Expand All @@ -97,10 +100,17 @@ public class Concat extends Task implements RunnableTask<Concat.Output> {
@PluginProperty(dynamic = true)
private String separator;

@Schema(
title = "The extension of the created file, default is .tmp"
)
@PluginProperty(dynamic = true)
@Builder.Default
private String extension = ".tmp";

@SuppressWarnings("unchecked")
@Override
public Concat.Output run(RunContext runContext) throws Exception {
File tempFile = runContext.tempFile().toFile();
File tempFile = runContext.tempFile(extension).toFile();
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
List<String> finalFiles;
if (this.files instanceof List) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.inject.Inject;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;

@MicronautTest
Expand Down Expand Up @@ -47,6 +48,7 @@ void run(Boolean json) throws Exception {
Concat result = Concat.builder()
.files(json ? JacksonMapper.ofJson().writeValueAsString(files) : files)
.separator("\n")
.extension(".yml")
.build();

Concat.Output run = result.run(runContext);
Expand All @@ -57,6 +59,7 @@ void run(Boolean json) throws Exception {
CharStreams.toString(new InputStreamReader(storageInterface.get(run.getUri()))),
is(s + "\n" + s + "\n")
);
assertThat(run.getUri().getPath(), endsWith(".yml"));
}

@Test
Expand Down

0 comments on commit a0ef8e4

Please sign in to comment.