-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be29ef5
commit c62fd37
Showing
11 changed files
with
255 additions
and
6 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
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
11 changes: 11 additions & 0 deletions
11
core/src/main/java/io/kestra/core/validations/InputValidation.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,11 @@ | ||
package io.kestra.core.validations; | ||
|
||
import javax.validation.Constraint; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = { }) | ||
public @interface InputValidation { | ||
String message() default "invalid Input"; | ||
} |
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,11 @@ | ||
package io.kestra.core.validations; | ||
|
||
import javax.validation.Constraint; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = { }) | ||
public @interface Regex { | ||
String message() default "invalid pattern ({validatedValue})"; | ||
} |
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
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
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
37 changes: 37 additions & 0 deletions
37
core/src/test/java/io/kestra/core/validations/InputTest.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,37 @@ | ||
package io.kestra.core.validations; | ||
|
||
import io.kestra.core.models.flows.Input; | ||
import io.kestra.core.models.validations.ModelValidator; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest | ||
class InputTest { | ||
@Inject | ||
private ModelValidator modelValidator; | ||
|
||
@Test | ||
void inputValidation() { | ||
final Input validInput = Input.builder() | ||
.name("test") | ||
.type(Input.Type.STRING) | ||
.validator("[A-Z]+") | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(validInput).isEmpty(), is(true)); | ||
|
||
final Input invalidInput = Input.builder() | ||
.name("test") | ||
.type(Input.Type.INT) | ||
.validator("[A-Z]+") | ||
.build(); | ||
|
||
assertThat(modelValidator.isValid(invalidInput).isPresent(), is(true)); | ||
assertThat(modelValidator.isValid(invalidInput).get().getMessage(), containsString("Invalid Input: Validator")); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/src/test/java/io/kestra/core/validations/RegexTest.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,39 @@ | ||
package io.kestra.core.validations; | ||
|
||
import io.kestra.core.models.validations.ModelValidator; | ||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest | ||
class RegexTest { | ||
@Inject | ||
private ModelValidator modelValidator; | ||
|
||
@AllArgsConstructor | ||
@Introspected | ||
@Getter | ||
public static class RegexCls { | ||
@Regex | ||
String pattern; | ||
} | ||
|
||
@Test | ||
void inputValidation() { | ||
final RegexCls validRegex = new RegexCls("[A-Z]+"); | ||
|
||
assertThat(modelValidator.isValid(validRegex).isEmpty(), is(true)); | ||
|
||
final RegexCls invalidRegex = new RegexCls("\\"); | ||
|
||
assertThat(modelValidator.isValid(invalidRegex).isPresent(), is(true)); | ||
assertThat(modelValidator.isValid(invalidRegex).get().getMessage(), containsString("invalid pattern")); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/resources/flows/invalids/inputs-bad-validator-syntax.yaml
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,10 @@ | ||
id: empty | ||
namespace: io.kestra.tests | ||
inputs: | ||
- name: badValidatorSyntax | ||
type: STRING | ||
validator: \ | ||
tasks: | ||
- id: date | ||
type: io.kestra.core.tasks.debugs.Return | ||
format: "{{taskrun.startDate}}" |
Oops, something went wrong.