mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-25 20:00:14 -05:00
Compare commits
1 Commits
run-develo
...
feat/tests
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e993fbb40 |
@@ -89,8 +89,35 @@ public class TestSuite implements HasUID, TenantInterface, DeletedInterface, Has
|
||||
return this.toBuilder().deleted(true).build();
|
||||
}
|
||||
|
||||
public TestSuite disable() {
|
||||
var disabled = true;
|
||||
return this.toBuilder()
|
||||
.disabled(disabled)
|
||||
.source(toggleDisabledInYamlSource(this.source, disabled))
|
||||
.build();
|
||||
}
|
||||
|
||||
public TestSuite enable() {
|
||||
var disabled = false;
|
||||
return this.toBuilder()
|
||||
.disabled(disabled)
|
||||
.source(toggleDisabledInYamlSource(this.source, disabled))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String source() {
|
||||
return this.getSource();
|
||||
}
|
||||
|
||||
protected static String toggleDisabledInYamlSource(String yamlSource, boolean disabled) {
|
||||
String regex = disabled ? "^disabled\\s*:\\s*false\\s*" : "^disabled\\s*:\\s*true\\s*";
|
||||
|
||||
java.util.regex.Pattern p = java.util.regex.Pattern.compile(regex, java.util.regex.Pattern.MULTILINE);
|
||||
if (p.matcher(yamlSource).find()) {
|
||||
return p.matcher(yamlSource).replaceAll(String.format("disabled: %s\n", disabled));
|
||||
}
|
||||
|
||||
return yamlSource + String.format("\ndisabled: %s", disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package io.kestra.core.test;
|
||||
|
||||
import io.kestra.core.test.flow.UnitTestResult;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public record TestSuiteRunResult(
|
||||
@NotNull
|
||||
String id,
|
||||
@NotNull
|
||||
String testSuiteId,
|
||||
@NotNull
|
||||
String namespace,
|
||||
@NotNull
|
||||
String flowId,
|
||||
@NotNull
|
||||
TestState state,
|
||||
List<UnitTestResult> results
|
||||
) {
|
||||
@@ -22,4 +28,8 @@ public record TestSuiteRunResult(
|
||||
}
|
||||
return new TestSuiteRunResult(id, testSuiteId, namespace, flowId, TestState.SUCCESS, results);
|
||||
}
|
||||
|
||||
public static TestSuiteRunResult ofDisabledTestSuite(String id, String testSuiteId, String namespace, String flowId) {
|
||||
return new TestSuiteRunResult(id, testSuiteId, namespace, flowId, TestState.SKIPPED, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
84
core/src/test/java/io/kestra/core/test/TestSuiteTest.java
Normal file
84
core/src/test/java/io/kestra/core/test/TestSuiteTest.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package io.kestra.core.test;
|
||||
|
||||
import io.kestra.core.serializers.YamlParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestSuiteTest {
|
||||
|
||||
@Test
|
||||
void canBe_parsed() {
|
||||
var source = """
|
||||
id: simple-return-test-suite-1-id
|
||||
namespace: io.kestra.tests
|
||||
description: assert flow is returning the input value as output
|
||||
flowId: return-flow
|
||||
testCases:
|
||||
- id: test_case_1
|
||||
type: io.kestra.core.tests.flow.UnitTest
|
||||
fixtures:
|
||||
inputs:
|
||||
inputA: "Hi there"
|
||||
assertions:
|
||||
- value: "{{ outputs.return.value }}"
|
||||
equalTo: 'Hi there'
|
||||
""";
|
||||
|
||||
var parsedTestSuite = YamlParser.parse(source, TestSuite.class).toBuilder().source(source).tenantId("main").build();
|
||||
|
||||
assertThat(parsedTestSuite).isNotNull();
|
||||
assertThat(parsedTestSuite).extracting(TestSuite::getId).isEqualTo("simple-return-test-suite-1-id");
|
||||
}
|
||||
|
||||
@Test
|
||||
void canBe_disabled() {
|
||||
var source = """
|
||||
id: simple-return-test-suite-1-id
|
||||
namespace: io.kestra.tests
|
||||
description: assert flow is returning the input value as output
|
||||
flowId: return-flow
|
||||
testCases:
|
||||
- id: test_case_1
|
||||
type: io.kestra.core.tests.flow.UnitTest
|
||||
fixtures:
|
||||
inputs:
|
||||
inputA: "Hi there"
|
||||
assertions:
|
||||
- value: "{{ outputs.return.value }}"
|
||||
equalTo: 'Hi there'
|
||||
""";
|
||||
var parsedTestSuite = YamlParser.parse(source, TestSuite.class).toBuilder().source(source).tenantId("main").build();
|
||||
|
||||
parsedTestSuite = parsedTestSuite.disable();
|
||||
|
||||
assertThat(parsedTestSuite).extracting(TestSuite::isDisabled).isEqualTo(true);
|
||||
assertThat(parsedTestSuite.getSource()).contains("disabled: true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void canBe_enabled() {
|
||||
var source = """
|
||||
id: simple-return-test-suite-1-id
|
||||
namespace: io.kestra.tests
|
||||
description: assert flow is returning the input value as output
|
||||
flowId: return-flow
|
||||
disabled: true
|
||||
testCases:
|
||||
- id: test_case_1
|
||||
type: io.kestra.core.tests.flow.UnitTest
|
||||
fixtures:
|
||||
inputs:
|
||||
inputA: "Hi there"
|
||||
assertions:
|
||||
- value: "{{ outputs.return.value }}"
|
||||
equalTo: 'Hi there'
|
||||
""";
|
||||
var parsedTestSuite = YamlParser.parse(source, TestSuite.class).toBuilder().source(source).tenantId("main").build();
|
||||
|
||||
parsedTestSuite = parsedTestSuite.enable();
|
||||
|
||||
assertThat(parsedTestSuite).extracting(TestSuite::isDisabled).isEqualTo(false);
|
||||
assertThat(parsedTestSuite.getSource()).contains("disabled: false");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user