Search in sources :

Example 6 with Node

use of io.kestra.core.tasks.scripts.Node 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 7 with Node

use of io.kestra.core.tasks.scripts.Node 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)

Aggregations

RunContext (io.kestra.core.runners.RunContext)7 Node (io.kestra.core.tasks.scripts.Node)7 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)7 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 ScriptOutput (io.kestra.core.tasks.scripts.ScriptOutput)6 Bash (io.kestra.core.tasks.scripts.Bash)1