mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-19 18:05:41 -05:00
fix: add unit test
This commit is contained in:
@@ -3,6 +3,7 @@ package io.kestra.core.serializers;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.kestra.core.models.flows.Flow;
|
||||
import io.kestra.core.models.flows.FlowWithSource;
|
||||
import io.kestra.core.models.flows.Input;
|
||||
import io.kestra.core.models.flows.Type;
|
||||
import io.kestra.core.models.flows.input.StringInput;
|
||||
@@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@KestraTest
|
||||
class YamlParserTest {
|
||||
private static final ObjectMapper MAPPER = JacksonMapper.ofJson();
|
||||
private static final ObjectMapper OBJECT_MAPPER = JacksonMapper.ofYaml().copy();
|
||||
|
||||
@Inject
|
||||
private ModelValidator modelValidator;
|
||||
@@ -235,6 +237,29 @@ class YamlParserTest {
|
||||
assertThat(new ArrayList<>(exception.getConstraintViolations()).getFirst().getMessage()).contains("Duplicate field 'variables.tf'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void vaildLabelsParser() throws IOException {
|
||||
Flow flow = parse("flows/valids/labels-deserialization.yaml");
|
||||
// like change execution state api,Serialize flow to YAML/JSON string
|
||||
String s = OBJECT_MAPPER.writeValueAsString(flow);
|
||||
assertThat(s).isEqualTo("id: full\n" +
|
||||
"namespace: io.kestra.tests\n" +
|
||||
"disabled: false\n" +
|
||||
"deleted: false\n" +
|
||||
"labels:\n" +
|
||||
"- key: key1\n" +
|
||||
" value: 123\n" +
|
||||
"tasks:\n" +
|
||||
"- id: t1\n" +
|
||||
" type: io.kestra.plugin.core.log.Log\n" +
|
||||
" message: \"{{ task.id }}\"\n");
|
||||
Map<String, Object> mapFlow = OBJECT_MAPPER.readValue(s, JacksonMapper.MAP_TYPE_REFERENCE);
|
||||
// Parse into FlowWithSource (simulates state update scenario)
|
||||
FlowWithSource parse = YamlParser.parse(mapFlow, FlowWithSource.class, false);
|
||||
|
||||
assertThat(parse.getLabels().size()).isEqualTo(1);;
|
||||
}
|
||||
|
||||
private Flow parse(String path) {
|
||||
URL resource = TestsUtils.class.getClassLoader().getResource(path);
|
||||
assert resource != null;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
id: full
|
||||
namespace: io.kestra.tests
|
||||
labels:
|
||||
key1: 123
|
||||
|
||||
#triggers:
|
||||
#- type: schedule
|
||||
# expression: 42 4 1 * *
|
||||
# backfill:
|
||||
# start: 2018-01-01
|
||||
# depend-on-past: false
|
||||
#
|
||||
|
||||
tasks:
|
||||
- id: t1
|
||||
type: io.kestra.plugin.core.log.Log
|
||||
message: "{{ task.id }}"
|
||||
Reference in New Issue
Block a user