Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core plugin sanity checks #6904

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions core/src/test/java/io/kestra/core/tasks/test/SanityCheckTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package io.kestra.core.tasks.test;

import io.kestra.core.junit.annotations.ExecuteFlow;
import io.kestra.core.junit.annotations.KestraTest;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.executions.TaskRun;
import io.kestra.core.models.flows.State;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

@KestraTest(startRunner = true)
class SanityCheckTest {
@Test
@ExecuteFlow("sanity-checks/qa.fail.yaml")
void qaFail(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(1));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.fetch.yaml")
void qaFetch(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(5));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.if.yaml")
void qaIf(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(8));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.kv.yaml")
void qaKv(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(6));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.labels.yaml")
void qaLabels(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(2));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.namespace_files.yaml")
void qaNamespaceFiles(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(8));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.parallel.yaml")
void qaParallel(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(4));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.pause.yaml")
void qaPause(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(1));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.purge_current_execution_files.yaml")
void qaPurgeExecutionFiles(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(2));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.return.yaml")
void qaReturn(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(2));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));

TaskRun taskRun = execution.findTaskRunsByTaskId("return_value").getFirst();
assertThat(taskRun.getOutputs().get("value"), is("some string with pebble test"));
}

@Test
@ExecuteFlow("sanity-checks/qa.sequential.yaml")
void qaSequential(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(5));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.sleep.yaml")
void qaSleep(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(4));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.switch.yaml")
void qaSwitch(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(3));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}

@Test
@ExecuteFlow("sanity-checks/qa.write.yaml")
void qaWrite(Execution execution) {
assertThat(execution.getTaskRunList(), hasSize(3));
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}
}
8 changes: 8 additions & 0 deletions core/src/test/resources/sanity-checks/qa.fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id: fail
namespace: qa

tasks:
- id: fail
type: io.kestra.plugin.core.execution.Fail
allowFailure: true
allowWarning: true
28 changes: 28 additions & 0 deletions core/src/test/resources/sanity-checks/qa.fetch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
id: fetch
namespace: qa

tasks:
- id: log_info
type: io.kestra.plugin.core.log.Log
message: "test"

- id: log_warn
type: io.kestra.plugin.core.log.Log
message: "warning"
level: WARN

- id: fetch_info
type: io.kestra.plugin.core.log.Fetch
level: INFO
executionId: "{{ execution.id }}"

- id: fetch_warning
type: "io.kestra.plugin.core.log.Fetch"
level: WARN
executionId: "{{ execution.id }}"

- id: assert
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.fetch_info.size == 2 }}"
- "{{ outputs.fetch_warning.size == 1 }}"
45 changes: 45 additions & 0 deletions core/src/test/resources/sanity-checks/qa.if.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
id: if
namespace: qa

tasks:
- id: if_true
type: io.kestra.plugin.core.flow.If
condition: "{{ true }}"
then:
- id: true_return
type: io.kestra.plugin.core.debug.Return
format: "{{ true }}"

- id: if_false
type: io.kestra.plugin.core.flow.If
condition: "{{ false }}"
then:
- id: does_not_run
type: io.kestra.plugin.core.log.Log
message: This won't run
else:
- id: false_return
type: io.kestra.plugin.core.debug.Return
format: "{{ false }}"

- id: run_if_true
type: io.kestra.plugin.core.execution.Assert
runIf: "{{ true }}"
conditions:
- "{{ true }}"

- id: run_if_false
type: io.kestra.plugin.core.execution.Assert
runIf: "{{ false }}"
conditions:
- "{{ false }}"

- id: if_true_assert
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.true_return.value == 'true' }}"

- id: if_false_assert
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.false_return.value == 'false' }}"
34 changes: 34 additions & 0 deletions core/src/test/resources/sanity-checks/qa.kv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
id: kv
namespace: qa

variables:
key: mykey
data: test12345

tasks:
- id: set
type: io.kestra.plugin.core.kv.Set
key: "{{ vars.key }}"
value: "{{ vars.data }}"
kvType: STRING

- id: get
type: io.kestra.plugin.core.kv.Get
key: "{{ vars.key }}"

- id: assert_get_set
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ vars.data == outputs.get.value }}"

- id: delete
type: io.kestra.plugin.core.kv.Delete
key: "{{ vars.key }}"

- id: get_keys
type: io.kestra.plugin.core.kv.GetKeys

- id: assert_delete_get_keys
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.get_keys.keys | length == 0 }}"
21 changes: 21 additions & 0 deletions core/src/test/resources/sanity-checks/qa.labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
id: labels
namespace: qa

variables:
label_1: test1
label_2: test2
label_3: test3

tasks:
- id: update_labels_with_map
type: io.kestra.plugin.core.execution.Labels
labels:
label_1: "{{ vars.label_1 }}"

- id: update_labels_by_list
type: io.kestra.plugin.core.execution.Labels
labels:
- key: label_2
value: "{{ vars.label_2 }}"
- key: label_3
value: "{{ vars.label_3 }}"
44 changes: 44 additions & 0 deletions core/src/test/resources/sanity-checks/qa.namespace_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
id: namespace_files
namespace: qa

tasks:
- id: download
type: io.kestra.plugin.core.http.Download
uri: https://raw.githubusercontent.com/kestra-io/scripts/refs/heads/main/automation/list_kestra_repos.py

- id: upload_files
type: io.kestra.plugin.core.namespace.UploadFiles
filesMap:
main.py: "{{ outputs.download.uri }}"
namespace: "{{ flow.namespace }}"

- id: download_files
type: io.kestra.plugin.core.namespace.DownloadFiles
namespace: "{{ flow.namespace }}"
files:
- "main.py"

- id: assert_upload_download
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ read(outputs.download.uri) == read(outputs.download_files.files['/main.py']) }}"

- id: delete_files
type: io.kestra.plugin.core.namespace.DeleteFiles
namespace: "{{ flow.namespace }}"
files:
- "main.py"

- id: download_files_check
type: io.kestra.plugin.core.namespace.DownloadFiles
namespace: "{{ flow.namespace }}"
files:
- "main.py"

- id: assert_delete
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.download_files_check.files | length == 0 }}"

- id: purge
type: io.kestra.plugin.core.storage.PurgeCurrentExecutionFiles
17 changes: 17 additions & 0 deletions core/src/test/resources/sanity-checks/qa.parallel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id: parallel
namespace: qa

tasks:
- id: parallel
type: io.kestra.plugin.core.flow.Parallel
tasks:
- id: 1st
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.startDate }}"
- id: 2nd
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.id }}"

- id: last
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.startDate }}"
7 changes: 7 additions & 0 deletions core/src/test/resources/sanity-checks/qa.pause.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: pause
namespace: qa

tasks:
- id: pause_flow
type: io.kestra.plugin.core.flow.Pause
delay: PT1S
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: purge_current_execution_files
namespace: qa

tasks:
- id: download
type: io.kestra.plugin.core.http.Download
uri: https://huggingface.co/datasets/kestra/datasets/raw/main/csv/orders.csv

- id: purge
type: io.kestra.plugin.core.storage.PurgeCurrentExecutionFiles
15 changes: 15 additions & 0 deletions core/src/test/resources/sanity-checks/qa.return.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: return
namespace: qa

variables:
my_var: test

tasks:
- id: return_value
type: io.kestra.plugin.core.debug.Return
format: "some string with pebble {{ vars.my_var }}"

- id: assert
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.return_value.value == 'some string with pebble test'}}"
22 changes: 22 additions & 0 deletions core/src/test/resources/sanity-checks/qa.sequential.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id: sequential
namespace: qa

tasks:
- id: sequential_root
type: io.kestra.plugin.core.flow.Sequential
tasks:
- id: n1_task
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} - {{ taskrun.id }} - {{ taskrun.startDate }}"

- id: sequential_child
type: io.kestra.plugin.core.flow.Sequential
tasks:

- id: n2_task
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} - {{ taskrun.id }} - {{ taskrun.startDate }}"

- id: last
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.startDate }}"
Loading
Loading