diff --git a/engine/api/workflow/execute_node_job_run.go b/engine/api/workflow/execute_node_job_run.go index 2e01328dd0..35ab3bd64a 100644 --- a/engine/api/workflow/execute_node_job_run.go +++ b/engine/api/workflow/execute_node_job_run.go @@ -61,9 +61,9 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) { case *sdk.WorkflowNodeJobRun: r.jobs = append(r.jobs, *x) case sdk.WorkflowNodeRun: - r.nodes = append(r.nodes, x) + r.addWorkflowNodeRun(ctx, x) case *sdk.WorkflowNodeRun: - r.nodes = append(r.nodes, *x) + r.addWorkflowNodeRun(ctx, *x) case sdk.WorkflowRun: r.workflows = append(r.workflows, x) case *sdk.WorkflowRun: @@ -74,6 +74,16 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) { } } +func (r *ProcessorReport) addWorkflowNodeRun(ctx context.Context, nr sdk.WorkflowNodeRun) { + for i := range r.nodes { + if nr.ID == r.nodes[i].ID { + r.nodes[i] = nr + return + } + } + r.nodes = append(r.nodes, nr) +} + //All returns all the objects in the reports func (r *ProcessorReport) All() []interface{} { r.mutex.Lock() diff --git a/tests/01_signup.yml b/tests/01_signup.yml index 0bda409f90..2af4ca10f0 100644 --- a/tests/01_signup.yml +++ b/tests/01_signup.yml @@ -7,11 +7,11 @@ vars: cdsctl.config : './cdsrc' smtpmock.url: 'http://localhost:2024' username: cds.integration.tests.rw + ring: email: it-user-rw@localhost.local fullname: cds.integration.tests.rw password: "123456&éçà(§" - ring: - smtpmock.url: 'http://localhost:2024' + testcases: - name: Check SMTP mock diff --git a/tests/04_sc_workflow_run_notif.yml b/tests/04_sc_workflow_run_notif.yml new file mode 100644 index 0000000000..3b4da9e6e6 --- /dev/null +++ b/tests/04_sc_workflow_run_notif.yml @@ -0,0 +1,99 @@ +name: Create a simple workflow (04SCWorkflowRunNotif) that use all worker command and run it +version: "2" + +vars : + smtpmock.url: 'http://localhost:2024' + +testcases: +- name: Check SMTP mock + steps: + - type: http + method: GET + url: '{{.smtpmock.url}}' + retry: 5 + delay: 5 + +- name: assert filepath, your current directory must be at the root of this project + steps: + - script: '[ -f ./fixtures/04SCWorkflowRunNotif/pipeline.yml ]' + - script: '[ -f ./fixtures/04SCWorkflowRunNotif/workflow.yml ]' + +- name: prepare test + steps: + - script: "{{.cdsctl}} -f {{.cdsctl.config}} project remove --force 04SCWORKFLOWRUNNOTIF" + - script: "{{.cdsctl}} -f {{.cdsctl.config}} group remove --force 04scworkflowrunnotif" + - script: "{{.cdsctl}} -f {{.cdsctl.config}} project add 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif" + +- name: import pipeline and workflow + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} pipeline import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/pipeline.yml + - script: {{.cdsctl}} -f {{.cdsctl.config}} pipeline import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/empty.yml + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/workflow.yml + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/workflow-empty.yml + +- name: run workflow + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow run 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW + assertions: + - result.code ShouldEqual 0 + - "result.systemout ShouldContainSubstring Workflow 04SCWorkflowRunNotif-WORKFLOW #1 has been launched" + +- name: check workflow + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow status 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW 1 --format json + retry: 20 + delay: 10 + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.last_execution ShouldNotBeEmpty + - result.systemoutjson.start ShouldNotBeEmpty + - result.systemoutjson.num ShouldContainSubstring 1 + - result.systemoutjson.status ShouldEqual Success + +- name: check-mail-notif + steps: + - type: http + method: GET + url: '{{.smtpmock.url}}/messages/notif@localhost.local' + assertions: + - result.statuscode ShouldEqual 200 + - result.bodyjson.__len__ ShouldEqual 1 + - type: http + method: GET + url: '{{.smtpmock.url}}/messages/notif@localhost.local/latest' + assertions: + - result.statuscode ShouldEqual 200 + retry: 10 + delay: 3 + vars: + verify: + from: result.bodyjson.content + regex: logcontent:foo2 + +- name: run workflow + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow run 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW-EMPTY + assertions: + - result.code ShouldEqual 0 + - "result.systemout ShouldContainSubstring Workflow 04SCWorkflowRunNotif-WORKFLOW-EMPTY #1 has been launched" + +- name: check workflow + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow status 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW-EMPTY 1 --format json + retry: 20 + delay: 10 + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.last_execution ShouldNotBeEmpty + - result.systemoutjson.start ShouldNotBeEmpty + - result.systemoutjson.num ShouldContainSubstring 1 + - result.systemoutjson.status ShouldEqual Success + +- name: check-mail-notif + steps: + - type: http + method: GET + url: '{{.smtpmock.url}}/messages/notif-empty@localhost.local' + assertions: + - result.statuscode ShouldEqual 200 + - result.bodyjson.__len__ ShouldEqual 1 diff --git a/tests/fixtures/04SCWorkflowRunNotif/empty.yml b/tests/fixtures/04SCWorkflowRunNotif/empty.yml new file mode 100644 index 0000000000..839e63a2ca --- /dev/null +++ b/tests/fixtures/04SCWorkflowRunNotif/empty.yml @@ -0,0 +1,2 @@ +version: v1.0 +name: empty diff --git a/tests/fixtures/04SCWorkflowRunNotif/pipeline.yml b/tests/fixtures/04SCWorkflowRunNotif/pipeline.yml new file mode 100644 index 0000000000..5a7c57aac2 --- /dev/null +++ b/tests/fixtures/04SCWorkflowRunNotif/pipeline.yml @@ -0,0 +1,14 @@ +version: v1.0 +name: 04SCWorkflowRunNotif-PIPELINE +stages: +- Stage1 + +jobs: +- job: EXPORT + stage: Stage1 + steps: + - script: + - set -ex + - echo "foo2" >> build.log + - BUILD_LOG=$(cat build.log | tail -n 200 | base64) + - worker export logcontent "$BUILD_LOG" diff --git a/tests/fixtures/04SCWorkflowRunNotif/workflow-empty.yml b/tests/fixtures/04SCWorkflowRunNotif/workflow-empty.yml new file mode 100644 index 0000000000..fe8852210e --- /dev/null +++ b/tests/fixtures/04SCWorkflowRunNotif/workflow-empty.yml @@ -0,0 +1,18 @@ +name: 04SCWorkflowRunNotif-WORKFLOW-EMPTY +version: v2.0 +workflow: + empty: + pipeline: empty +metadata: + default_tags: git.branch,git.author +notifications: +- type: email + pipelines: + - empty + settings: + on_success: always + recipients: + - notif-empty@localhost.local + template: + body: | + foo diff --git a/tests/fixtures/04SCWorkflowRunNotif/workflow.yml b/tests/fixtures/04SCWorkflowRunNotif/workflow.yml new file mode 100644 index 0000000000..38cf3f5003 --- /dev/null +++ b/tests/fixtures/04SCWorkflowRunNotif/workflow.yml @@ -0,0 +1,20 @@ +name: 04SCWorkflowRunNotif-WORKFLOW +version: v2.0 +workflow: + test-notif: + pipeline: 04SCWorkflowRunNotif-PIPELINE +metadata: + default_tags: git.branch,git.author +notifications: +- type: email + pipelines: + - test-notif + settings: + on_success: always + recipients: + - notif@localhost.local + template: + body: | + title:{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}} + url:{{.cds.buildURL}} + logcontent:{{.cds.build.logcontent | b64dec}} diff --git a/tests/test.sh b/tests/test.sh index a5112eff06..d5e948c035 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -123,7 +123,7 @@ cli_tests() { workflow_tests() { echo "Running Workflow tests:" for f in $(ls -1 04_*.yml); do - CMD="${VENOM} run ${VENOM_OPTS} ${f} --var cdsctl=${CDSCTL} --var cdsctl.config=${CDSCTL_CONFIG}_admin --var api.url=${CDS_API_URL} --var ui.url=${CDS_UI_URL} --var smtpmock.url=${SMTP_MOCK_URL} --var ro_username=cds.integration.tests.ro --var cdsctl.config_ro_user=${CDSCTL_CONFIG}_user" + CMD="${VENOM} run ${VENOM_OPTS} ${f} --var cdsctl=${CDSCTL} --var cdsctl.config=${CDSCTL_CONFIG}_admin --var api.url=${CDS_API_URL} --var ui.url=${CDS_UI_URL} --var smtpmock.url=${SMTP_MOCK_URL} --var ro_username=cds.integration.tests.ro --var cdsctl.config_ro_user=${CDSCTL_CONFIG}_user" echo -e " ${YELLOW}${f} ${DARKGRAY}[${CMD}]${NOCOLOR}" ${CMD} >${f}.output 2>&1 check_failure $? ${f}.output @@ -138,7 +138,7 @@ workflow_with_integration_tests() { if [ -z "$OS_PASSWORD" ]; then echo "missing OS_* variables"; exit 1; fi echo "Running Workflow with Storage integration tests:" for f in $(ls -1 05_*.yml); do - CMD="${VENOM} run ${VENOM_OPTS} ${f} --var cdsctl=${CDSCTL} --var cdsctl.config=${CDSCTL_CONFIG}_admin --var api.url=${CDS_API_URL} --var ui.url=${CDS_UI_URL} --var smtpmock.url=${SMTP_MOCK_URL}" + CMD="${VENOM} run ${VENOM_OPTS} ${f} --var cdsctl=${CDSCTL} --var cdsctl.config=${CDSCTL_CONFIG}_admin --var api.url=${CDS_API_URL} --var ui.url=${CDS_UI_URL} --var smtpmock.url=${SMTP_MOCK_URL}" echo -e " ${YELLOW}${f} ${DARKGRAY}[${CMD}]${NOCOLOR}" ${CMD} >${f}.output 2>&1 check_failure $? ${f}.output