use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class PythonTest method manyFiles.
@Test
void manyFiles() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "import otherfile; otherfile.test()");
files.put("otherfile.py", "def test(): print('::{\"outputs\": {\"extract\":\"success\"}}::')");
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.getVars().get("extract"), is("success"));
}
use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class NodeTest method requirements.
@Test
void requirements() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.js", "require('axios').get('http://google.com').then(r => { console.log('::{\"outputs\": {\"extract\":\"' + r.status + '\"}}::') })");
files.put("package.json", "{\"dependencies\":{\"axios\":\"^0.20.0\"}}");
Node node = Node.builder().id("test-node-task").nodePath("node").npmPath("npm").inputFiles(files).build();
ScriptOutput run = node.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 NodeTest method run.
@Test
void run() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.js", "console.log('::{\"outputs\": {\"extract\":\"hello world\"}}::')");
Node node = Node.builder().id("test-node-task").nodePath("node").inputFiles(files).build();
ScriptOutput run = node.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(1));
assertThat(run.getVars().get("extract"), is("hello world"));
assertThat(run.getStdErrLineCount(), equalTo(0));
}
use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class NodeTest method manyFiles.
@Test
void manyFiles() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.js", "console.log('::{\"outputs\": {\"extract\":\"' + (require('./otherfile').value) + '\"}}::')");
files.put("otherfile.js", "module.exports.value = 'success'");
Node node = Node.builder().id("test-node-task").nodePath("node").inputFiles(files).build();
ScriptOutput run = node.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("extract"), is("success"));
}
use of io.kestra.core.tasks.scripts.ScriptOutput in project kestra by kestra-io.
the class PythonTest method outputs.
@Test
void outputs() throws Exception {
RunContext runContext = runContextFactory.of(ImmutableMap.of("test", "value"));
Map<String, String> files = new HashMap<>();
files.put("main.py", "from kestra import Kestra\n" + "import time\n" + "Kestra.outputs({'test': 'value', 'int': 2, 'bool': True, 'float': 3.65})\n" + "Kestra.counter('count', 1, {'tag1': 'i', 'tag2': 'win'})\n" + "Kestra.counter('count2', 2)\n" + "Kestra.timer('timer1', lambda: time.sleep(1), {'tag1': 'i', 'tag2': 'lost'})\n" + "Kestra.timer('timer2', 2.12, {'tag1': 'i', 'tag2': 'destroy'})\n");
Python node = Python.builder().id("test-node-task").pythonPath("python3").inputFiles(files).build();
ScriptOutput run = node.run(runContext);
assertThat(run.getVars().get("test"), is("value"));
assertThat(run.getVars().get("int"), is(2));
assertThat(run.getVars().get("bool"), is(true));
assertThat(run.getVars().get("float"), is(3.65));
AbstractBashTest.controlOutputs(runContext, run);
}
Aggregations