Skip to content

Commit

Permalink
Code coverage increased and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSPb89 committed Nov 23, 2017
1 parent 951b3eb commit 6fb6cec
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/generator/WDL/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* GLOBAL KEYWORDS*/
/* GLOBAL KEYWORDS */
export const TASK = 'task';
export const WORKFLOW = 'workflow';
export const CALL = 'call';
Expand Down
1 change: 1 addition & 0 deletions src/model/Workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Workflow extends Group {
});
} else {
let found = false;
// eslint-disable-next-line no-return-assign
this.walk(step => !found && !(found = (step.action === action)));
if (found) {
throw new Error('Cannot remove action in use');
Expand Down
1 change: 1 addition & 0 deletions src/parser/WDL/entities/WDLWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default class WDLWorkflow {
if (expression.type !== 'MemberAccess') {
obj[name].default = expression.string;
} else {
// eslint-disable-next-line no-return-assign
expression.accesses.forEach(v => (v.to = name));
wfOutLinksList = expression.accesses;
}
Expand Down
10 changes: 6 additions & 4 deletions src/parser/WDL/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ function updateFirstAst(firstAst, calls) {
const change = list => list.map((i) => {
if (i.name.toLowerCase() !== Constants.DECLARATION) {
if (i.name.toLowerCase() === Constants.CALL) {
i.attributes.body.attributes.io.list = i.attributes.body.attributes.io.list
.map(io => proceedCallInputs(io, callNames, namespaces));
if (i.attributes.body && i.attributes.body.attributes && i.attributes.body.attributes.io) {
i.attributes.body.attributes.io.list = i.attributes.body.attributes.io.list
.map(io => proceedCallInputs(io, callNames, namespaces));
}

if (calls.includes(i.attributes.task.source_string)) {
i.attributes.task.source_string = i.attributes.task.source_string
Expand Down Expand Up @@ -302,7 +304,7 @@ function clearWorkflowCallsAndOutputs(workflows) {
});
}
return item;
}).filter(i => !!i);
}).filter(i => !!i && !_.isArray(i));

wf.attributes.body.list = clearWf(wf.attributes.body.list);
return wf;
Expand Down Expand Up @@ -362,7 +364,7 @@ function resolveCalls(calls, imports, preparedSubWdl) {
// convert workflow to task to enable it's presentation
.forEach((wf) => {
wf.attributes.name.source_string = `${nsName}_${wf.attributes.name.source_string}`;
// clear wf calls and outputs expressions
// clear sub wf calls and outputs expressions
wf = clearWorkflowCallsAndOutputs([wf])[0];
foundTasks.push(wf);
});
Expand Down
164 changes: 158 additions & 6 deletions test/parser/WDL/parseTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ workflow RootWorkflow {
taskInput = wfInput
}
if (wfInput) {
call tasks.TaskOne as Two {
input:
taskInput = wfInput
}
}
call task2
call SubWorkflow.Workflow {
input:
wf_input = TaskOne.task_output,
Expand All @@ -208,7 +217,7 @@ workflow RootWorkflow {
call SubWorkflow.Workflow as WorkflowAliasTwo {
input:
wf_input = TaskOne.task_output,
wf_input = Two.task_output,
wf_input_two = wfInputThree
}
Expand All @@ -217,7 +226,16 @@ workflow RootWorkflow {
String? output_2 = Workflow.output_string
String? output_3 = WorkflowAliasOne.output_string
}
}`;
}
task task2 {
String str
output {
String outStr = str
}
}
`;
const wdlArray = [{
name: 'tasks.wdl',
// language=wdl
Expand Down Expand Up @@ -246,10 +264,25 @@ workflow Workflow {
String wf_input
String wf_input_two
call task2
if (wf_input) {
call task2 as task3
}
output {
String output_string = "outputString"
}
}`,
}
task task2 {
String str
output {
String outStr = str
}
}
`,
}];

return parse(src, { wdlArray }).then(res => expect(res.status).to.equal(true));
Expand Down Expand Up @@ -313,6 +346,73 @@ workflow RootWorkflow {
return parse(src).then(res => expect(res.status).to.equal(false));
});

it('returns with error when parsing valid wdl script with import statements and incorrect import\'s wdl presented', () => {
// language=wdl
const src = `
import "tasks.wdl"
import "sub_workflow.wdl" as SubWorkflow
workflow RootWorkflow {
File? wfInput
File? wfInputTwo
File? wfInputThree
call tasks.TaskOne {
input:
taskInput = wfInput
}
call SubWorkflow.Workflow as WorkflowAliasOne {
input:
wf_input = TaskOne.task_output,
wf_input_two = wfInputTwo
}
output {
String? output_3 = WorkflowAliasOne.output_string
}
}`;
const wdlArray = [{
name: 'tasks.wdl',
// language=wdl
wdl: `
task TaskOne {
File taskInput
command <<<
echo "test"; \\
>>>
runtime {
test: "test"
}
output {
String task_output = "outputString"
}
}
`,
}, {
name: 'sub_workflow.wdl',
// language=wdl
wdl: `
workflow Workflow {
# this is an error: task should be declared outside of workflow
task task2 {
String str
output {
String outStr = str
}
}
}
`,
}];

return parse(src, { wdlArray }).then(res => expect(res.status).to.equal(false));
});

it('returns with error when parsing valid wdl script with "file://" protocol in import statement', () => {
// language=wdl
const src = `
Expand Down Expand Up @@ -415,16 +515,28 @@ task convert {
});
});

it('requires to parse valid wdl script with "http://" protocol in import statements', () => {
it('requires to parse valid wdl script with "http://" and "https://" protocol in import statements and baseURI', () => {
// language=wdl
const src = `
import "http://test.com/sub_workflow.wdl" as SubWorkflow
import "http://test.com/sub_workflow" as SubWorkflow
import "https://test.com/tasks"
import "tasks_two"
workflow RootWorkflow {
File? wfInput
File? wfInputTwo
File? wfInputThree
call tasks.TaskOne {
input:
taskInput = wfInput
}
call tasks_two.TaskTwo {
input:
taskInput = wfInput
}
call SubWorkflow.Workflow {
input:
wf_input = wfInputTwo,
Expand Down Expand Up @@ -459,10 +571,50 @@ task convert {
}
}`;

// language=wdl
const subWdlHttps = `
task TaskOne {
File taskInput
const promise = parse(src);
command <<<
echo "test"; \\
>>>
runtime {
test: "test"
}
output {
String task_output = "outputString"
}
}
`;

// language=wdl
const subWdlBaseUri = `
task TaskTwo {
File taskInput
command <<<
echo "test"; \\
>>>
runtime {
test: "test"
}
output {
String task_output = "outputString"
}
}
`;


const promise = parse(src, { baseURI: 'http://test.com/' });

requests[0].respond(200, { 'Content-Type': 'text' }, subWdl);
requests[1].respond(200, { 'Content-Type': 'text' }, subWdlHttps);
requests[2].respond(200, { 'Content-Type': 'text' }, subWdlBaseUri);

return promise.then((res) => {
expect(res.status).to.equal(true);
Expand Down

0 comments on commit 6fb6cec

Please sign in to comment.