use of io.kestra.core.tasks.scripts.Node in project kestra by kestra-io.
the class NodeTest method fileInSubFolders.
@Test
void fileInSubFolders() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.js", "console.log('::{\"outputs\": {\"extract\":\"' + (require('fs').readFileSync('./sub/folder/file/test.txt', 'utf-8')) + '\"}}::')");
files.put("sub/folder/file/test.txt", "OK");
files.put("sub/folder/file/test1.txt", "OK");
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("OK"));
}
use of io.kestra.core.tasks.scripts.Node in project kestra by kestra-io.
the class NodeTest method args.
@Test
void args() throws Exception {
RunContext runContext = runContextFactory.of(ImmutableMap.of("test", "value"));
Map<String, String> files = new HashMap<>();
files.put("main.js", "console.log('::{\"outputs\": {\"extract\":\"' + (process.argv.slice(2).join(' ')) + '\"}}::')");
Node node = Node.builder().id("test-node-task").nodePath("node").inputFiles(files).args(Arrays.asList("test", "param", "{{test}}")).build();
ScriptOutput run = node.run(runContext);
assertThat(run.getVars().get("extract"), is("test param value"));
}
use of io.kestra.core.tasks.scripts.Node in project kestra by kestra-io.
the class NodeTest method outputs.
@Test
void outputs() throws Exception {
RunContext runContext = runContextFactory.of(ImmutableMap.of("test", "value"));
Map<String, String> files = new HashMap<>();
files.put("main.js", "const Kestra = require(\"./kestra\");" + "Kestra.outputs({test: 'value', int: 2, bool: true, float: 3.65});" + "Kestra.counter('count', 1, {tag1: 'i', tag2: 'win'});" + "Kestra.counter('count2', 2);" + "Kestra.timer('timer1', (callback) => { setTimeout(callback, 1000) }, {tag1: 'i', tag2: 'lost'});" + "Kestra.timer('timer2', 2.12, {tag1: 'i', tag2: 'destroy'});");
Node node = Node.builder().id("test-node-task").nodePath("node").inputFiles(files).build();
ScriptOutput run = node.run(runContext);
AbstractBashTest.controlOutputs(runContext, run);
}
use of io.kestra.core.tasks.scripts.Node 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.Node in project kestra by kestra-io.
the class NodeTest method failed.
@Test
void failed() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.js", "process.exit(1)");
Node node = Node.builder().id("test-node-task").nodePath("node").inputFiles(files).build();
Bash.BashException nodeException = assertThrows(Bash.BashException.class, () -> {
node.run(runContext);
});
assertThat(nodeException.getExitCode(), is(1));
assertThat(nodeException.getStdOutSize(), is(0));
assertThat(nodeException.getStdErrSize(), equalTo(0));
}
Aggregations