Search in sources :

Example 11 with ScriptOutput

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"));
}
Also used : ScriptOutput(io.kestra.core.tasks.scripts.ScriptOutput) HashMap(java.util.HashMap) RunContext(io.kestra.core.runners.RunContext) Python(io.kestra.core.tasks.scripts.Python) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 12 with ScriptOutput

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"));
}
Also used : ScriptOutput(io.kestra.core.tasks.scripts.ScriptOutput) HashMap(java.util.HashMap) Node(io.kestra.core.tasks.scripts.Node) RunContext(io.kestra.core.runners.RunContext) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 13 with ScriptOutput

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));
}
Also used : ScriptOutput(io.kestra.core.tasks.scripts.ScriptOutput) HashMap(java.util.HashMap) Node(io.kestra.core.tasks.scripts.Node) RunContext(io.kestra.core.runners.RunContext) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 14 with ScriptOutput

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"));
}
Also used : ScriptOutput(io.kestra.core.tasks.scripts.ScriptOutput) HashMap(java.util.HashMap) Node(io.kestra.core.tasks.scripts.Node) RunContext(io.kestra.core.runners.RunContext) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 15 with ScriptOutput

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);
}
Also used : ScriptOutput(io.kestra.core.tasks.scripts.ScriptOutput) HashMap(java.util.HashMap) RunContext(io.kestra.core.runners.RunContext) Python(io.kestra.core.tasks.scripts.Python) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Aggregations

RunContext (io.kestra.core.runners.RunContext)21 ScriptOutput (io.kestra.core.tasks.scripts.ScriptOutput)21 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)21 Test (org.junit.jupiter.api.Test)21 HashMap (java.util.HashMap)14 Python (io.kestra.core.tasks.scripts.Python)8 Bash (io.kestra.core.tasks.scripts.Bash)7 Node (io.kestra.core.tasks.scripts.Node)6 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 URL (java.net.URL)2 File (java.io.File)1 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)1