use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class PythonTest method docker.
@Test
void docker() throws Exception {
Map<String, String> files = new HashMap<>();
files.put("main.py", "import requests; print('::{\"outputs\": {\"extract\":\"' + str(requests.get('http://google.com').status_code) + '\"}}::')");
Python python = Python.builder().id("test-python-task").type(Python.class.getName()).inputFiles(files).runner(AbstractBash.Runner.DOCKER).dockerOptions(AbstractBash.DockerOptions.builder().image("python").build()).requirements(Collections.singletonList("requests")).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, python, ImmutableMap.of());
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("extract"), is("200"));
}
use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class PythonTest method run.
@Test
void run() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "print('::{\"outputs\": {\"extract\":\"hello world\"}}::')");
Python python = Python.builder().id("test-python-task").pythonPath("python3").inputFiles(files).build();
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(1));
assertThat(run.getVars().get("extract"), is("hello world"));
}
use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class PythonTest method requirements.
@Test
void requirements() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "import requests; print('::{\"outputs\": {\"extract\":\"' + str(requests.get('http://google.com').status_code) + '\"}}::')");
Python python = Python.builder().id("test-python-task").pythonPath("python3").inputFiles(files).requirements(Collections.singletonList("requests")).build();
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("extract"), is("200"));
}
use of io.kestra.core.tasks.scripts.ScriptOutput 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.ScriptOutput 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));
}
Aggregations