-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): validate that a worker group cannot be set on WorkingDire…
- Loading branch information
1 parent
bfdc7d3
commit 8fa1444
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/src/test/java/io/kestra/core/validations/WorkingDirectoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.kestra.core.validations; | ||
|
||
import io.kestra.core.models.tasks.WorkerGroup; | ||
import io.kestra.core.models.validations.ModelValidator; | ||
import io.kestra.core.tasks.flows.Pause; | ||
import io.kestra.core.tasks.flows.WorkingDirectory; | ||
import io.kestra.core.tasks.log.Log; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@MicronautTest | ||
public class WorkingDirectoryTest { | ||
@Inject | ||
private ModelValidator modelValidator; | ||
|
||
@Test | ||
void workingDirectoryValid() { | ||
var workingDirectory = WorkingDirectory.builder() | ||
.id("workingDir") | ||
.type(WorkingDirectory.class.getName()) | ||
.tasks( | ||
List.of(Log.builder() | ||
.id("log") | ||
.type(Log.class.getName()) | ||
.message("Hello World") | ||
.build() | ||
) | ||
) | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(workingDirectory).isPresent(), is(false)); | ||
} | ||
|
||
@Test | ||
void workingDirectoryInvalid() { | ||
// empty list of tasks | ||
var workingDirectory = WorkingDirectory.builder() | ||
.id("workingDir") | ||
.type(WorkingDirectory.class.getName()) | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(workingDirectory).isPresent(), is(true)); | ||
assertThat(modelValidator.isValid(workingDirectory).get().getMessage(), containsString("The tasks property cannot be empty")); | ||
|
||
// flowable task | ||
workingDirectory = WorkingDirectory.builder() | ||
.id("workingDir") | ||
.type(WorkingDirectory.class.getName()) | ||
.tasks( | ||
List.of(Pause.builder() | ||
.id("pause") | ||
.type(Pause.class.getName()) | ||
.delay(Duration.ofSeconds(1L)) | ||
.build() | ||
) | ||
) | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(workingDirectory).isPresent(), is(true)); | ||
assertThat(modelValidator.isValid(workingDirectory).get().getMessage(), containsString("Only runnable tasks are allowed as children of a WorkingDirectory task")); | ||
|
||
// worker group at the subtasks level | ||
workingDirectory = WorkingDirectory.builder() | ||
.id("workingDir") | ||
.type(WorkingDirectory.class.getName()) | ||
.tasks( | ||
List.of(Log.builder() | ||
.id("log") | ||
.type(Log.class.getName()) | ||
.message("Hello World") | ||
.workerGroup(new WorkerGroup("toto")) | ||
.build() | ||
) | ||
) | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(workingDirectory).isPresent(), is(true)); | ||
assertThat(modelValidator.isValid(workingDirectory).get().getMessage(), containsString("Cannot set a Worker Group in any WorkingDirectory sub-tasks, it is only supported at the WorkingDirectory level")); | ||
|
||
} | ||
} |