Skip to content

Commit

Permalink
fix(core): WorkingDirectory validation throws an exception when tasks…
Browse files Browse the repository at this point in the history
… is null or empty
  • Loading branch information
loicmathieu committed Aug 1, 2023
1 parent 5327c73 commit 968f97d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ ConstraintValidator<WorkingDirectoryTaskValidation, WorkingDirectory> workingDir
return true;
}

if(value.getTasks().stream().anyMatch(task -> !(task instanceof RunnableTask<?>))) {
if (value.getTasks() == null || value.getTasks().isEmpty()) {
context.messageTemplate("The 'tasks' property cannot be empty");
return false;
}

if (value.getTasks().stream().anyMatch(task -> !(task instanceof RunnableTask<?>))) {
context.messageTemplate("Only runnable tasks are allowed as children of a WorkingDirectory task");
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/io/kestra/core/models/flows/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ void workingDirectoryTaskInvalid() {
assertThat(validate.get().getMessage(), containsString("tasks[0]: Only runnable tasks are allowed as children of a WorkingDirectory task"));
}

@Test
void workingDirectoryNoTasks() {
Flow flow = this.parse("flows/invalids/workingdirectory-no-tasks.yaml");
Optional<ConstraintViolationException> validate = modelValidator.isValid(flow);

assertThat(validate.isPresent(), is(true));
assertThat(validate.get().getConstraintViolations().size(), is(2));

assertThat(validate.get().getMessage(), containsString("tasks[0]: The tasks property cannot be empty"));
}

@Test
void updateTask() throws InternalException {
Flow flow = this.parse("flows/valids/each-sequential-nested.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id: workingdirectory-no-tasks
namespace: io.kestra.tests

tasks:
- id: impossible
type: io.kestra.core.tasks.flows.WorkingDirectory

0 comments on commit 968f97d

Please sign in to comment.