use of io.kestra.core.tasks.scripts.Bash in project kestra by kestra-io.
the class AbstractBashTest method run.
@Test
void run() throws Exception {
Bash bash = configure(Bash.builder().commands(new String[] { "echo 0", "echo 1", ">&2 echo 2", ">&2 echo 3" })).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, bash, ImmutableMap.of());
ScriptOutput run = bash.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(2));
assertThat(run.getStdErrLineCount(), is(2));
}
use of io.kestra.core.tasks.scripts.Bash in project kestra by kestra-io.
the class WorkerTest method workerTask.
private WorkerTask workerTask(String sleep) {
Bash bash = Bash.builder().type(Bash.class.getName()).id("unit-test").commands(new String[] { "for i in $(seq 1 " + sleep + "); do echo $i; sleep 1; done" }).build();
Flow flow = Flow.builder().id(IdUtils.create()).namespace("io.kestra.unit-test").tasks(Collections.singletonList(bash)).build();
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
ResolvedTask resolvedTask = ResolvedTask.of(bash);
return WorkerTask.builder().runContext(runContextFactory.of(ImmutableMap.of("key", "value"))).task(bash).taskRun(TaskRun.of(execution, resolvedTask)).build();
}
use of io.kestra.core.tasks.scripts.Bash in project kestra by kestra-io.
the class AbstractBashTest method useInputFilesFromKestraFs.
@Test
void useInputFilesFromKestraFs() throws Exception {
URL resource = AbstractBashTest.class.getClassLoader().getResource("application.yml");
URI put = storageInterface.put(new URI("/file/storage/get.yml"), new FileInputStream(Objects.requireNonNull(resource).getFile()));
Map<String, String> files = new HashMap<>();
files.put("test.sh", "cat fscontent.txt");
files.put("fscontent.txt", put.toString());
List<String> commands = new ArrayList<>();
commands.add("cat fscontent.txt > {{ outputFiles.out }} ");
Bash bash = configure(Bash.builder().interpreter("/bin/bash").commands(commands.toArray(String[]::new)).inputFiles(files).outputFiles(Collections.singletonList("out"))).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, bash, ImmutableMap.of());
ScriptOutput run = bash.run(runContext);
assertThat(run.getExitCode(), is(0));
InputStream get = storageInterface.get(run.getOutputFiles().get("out"));
String outputContent = CharStreams.toString(new InputStreamReader(get));
String fileContent = String.join("\n", Files.readAllLines(new File(resource.getPath()).toPath(), StandardCharsets.UTF_8));
assertThat(outputContent, is(fileContent));
}
use of io.kestra.core.tasks.scripts.Bash in project kestra by kestra-io.
the class AbstractBashTest method dontStopOnFirstFailed.
@Test
@DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*")
void dontStopOnFirstFailed() throws Exception {
Bash bash = configure(Bash.builder().commands(new String[] { "unknown", "echo 1" }).exitOnFailed(false)).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, bash, ImmutableMap.of());
ScriptOutput run = bash.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(1));
assertThat(run.getStdErrLineCount(), is(1));
}
use of io.kestra.core.tasks.scripts.Bash in project kestra by kestra-io.
the class AbstractBashTest method longBashCreateTempFiles.
@Test
void longBashCreateTempFiles() throws Exception {
List<String> commands = new ArrayList<>();
for (int i = 0; i < 15000; i++) {
commands.add("if [ \"" + i + "\" -eq 0 ] || [ \"" + i + "\" -eq 14999 ]; then echo " + i + ";fi;");
}
Bash bash = configure(Bash.builder().commands(commands.toArray(String[]::new))).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, bash, ImmutableMap.of());
ScriptOutput run = bash.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(2));
assertThat(run.getStdErrLineCount() > 0, is(false));
}
Aggregations