Skip to content

Commit d8e7c1b

Browse files
authored
fix(api): fix duplicate notif for empty pipeline
* test(api): integration test for mail notif Signed-off-by: Yvonnick Esnault <[email protected]>
1 parent 7505302 commit d8e7c1b

File tree

8 files changed

+169
-6
lines changed

8 files changed

+169
-6
lines changed

engine/api/workflow/execute_node_job_run.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) {
6161
case *sdk.WorkflowNodeJobRun:
6262
r.jobs = append(r.jobs, *x)
6363
case sdk.WorkflowNodeRun:
64-
r.nodes = append(r.nodes, x)
64+
r.addWorkflowNodeRun(ctx, x)
6565
case *sdk.WorkflowNodeRun:
66-
r.nodes = append(r.nodes, *x)
66+
r.addWorkflowNodeRun(ctx, *x)
6767
case sdk.WorkflowRun:
6868
r.workflows = append(r.workflows, x)
6969
case *sdk.WorkflowRun:
@@ -74,6 +74,16 @@ func (r *ProcessorReport) Add(ctx context.Context, i ...interface{}) {
7474
}
7575
}
7676

77+
func (r *ProcessorReport) addWorkflowNodeRun(ctx context.Context, nr sdk.WorkflowNodeRun) {
78+
for i := range r.nodes {
79+
if nr.ID == r.nodes[i].ID {
80+
r.nodes[i] = nr
81+
return
82+
}
83+
}
84+
r.nodes = append(r.nodes, nr)
85+
}
86+
7787
//All returns all the objects in the reports
7888
func (r *ProcessorReport) All() []interface{} {
7989
r.mutex.Lock()

tests/01_signup.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ vars:
77
cdsctl.config : './cdsrc'
88
smtpmock.url: 'http://localhost:2024'
99
username: cds.integration.tests.rw
10+
ring:
1011
1112
fullname: cds.integration.tests.rw
1213
password: "123456&éçà(§"
13-
ring:
14-
smtpmock.url: 'http://localhost:2024'
14+
1515

1616
testcases:
1717
- name: Check SMTP mock

tests/04_sc_workflow_run_notif.yml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Create a simple workflow (04SCWorkflowRunNotif) that use all worker command and run it
2+
version: "2"
3+
4+
vars :
5+
smtpmock.url: 'http://localhost:2024'
6+
7+
testcases:
8+
- name: Check SMTP mock
9+
steps:
10+
- type: http
11+
method: GET
12+
url: '{{.smtpmock.url}}'
13+
retry: 5
14+
delay: 5
15+
16+
- name: assert filepath, your current directory must be at the root of this project
17+
steps:
18+
- script: '[ -f ./fixtures/04SCWorkflowRunNotif/pipeline.yml ]'
19+
- script: '[ -f ./fixtures/04SCWorkflowRunNotif/workflow.yml ]'
20+
21+
- name: prepare test
22+
steps:
23+
- script: "{{.cdsctl}} -f {{.cdsctl.config}} project remove --force 04SCWORKFLOWRUNNOTIF"
24+
- script: "{{.cdsctl}} -f {{.cdsctl.config}} group remove --force 04scworkflowrunnotif"
25+
- script: "{{.cdsctl}} -f {{.cdsctl.config}} project add 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif"
26+
27+
- name: import pipeline and workflow
28+
steps:
29+
- script: {{.cdsctl}} -f {{.cdsctl.config}} pipeline import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/pipeline.yml
30+
- script: {{.cdsctl}} -f {{.cdsctl.config}} pipeline import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/empty.yml
31+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/workflow.yml
32+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow import --force 04SCWORKFLOWRUNNOTIF ./fixtures/04SCWorkflowRunNotif/workflow-empty.yml
33+
34+
- name: run workflow
35+
steps:
36+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow run 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW
37+
assertions:
38+
- result.code ShouldEqual 0
39+
- "result.systemout ShouldContainSubstring Workflow 04SCWorkflowRunNotif-WORKFLOW #1 has been launched"
40+
41+
- name: check workflow
42+
steps:
43+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow status 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW 1 --format json
44+
retry: 20
45+
delay: 10
46+
assertions:
47+
- result.code ShouldEqual 0
48+
- result.systemoutjson.last_execution ShouldNotBeEmpty
49+
- result.systemoutjson.start ShouldNotBeEmpty
50+
- result.systemoutjson.num ShouldContainSubstring 1
51+
- result.systemoutjson.status ShouldEqual Success
52+
53+
- name: check-mail-notif
54+
steps:
55+
- type: http
56+
method: GET
57+
url: '{{.smtpmock.url}}/messages/[email protected]'
58+
assertions:
59+
- result.statuscode ShouldEqual 200
60+
- result.bodyjson.__len__ ShouldEqual 1
61+
- type: http
62+
method: GET
63+
url: '{{.smtpmock.url}}/messages/[email protected]/latest'
64+
assertions:
65+
- result.statuscode ShouldEqual 200
66+
retry: 10
67+
delay: 3
68+
vars:
69+
verify:
70+
from: result.bodyjson.content
71+
regex: logcontent:foo2
72+
73+
- name: run workflow
74+
steps:
75+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow run 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW-EMPTY
76+
assertions:
77+
- result.code ShouldEqual 0
78+
- "result.systemout ShouldContainSubstring Workflow 04SCWorkflowRunNotif-WORKFLOW-EMPTY #1 has been launched"
79+
80+
- name: check workflow
81+
steps:
82+
- script: {{.cdsctl}} -f {{.cdsctl.config}} workflow status 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif-WORKFLOW-EMPTY 1 --format json
83+
retry: 20
84+
delay: 10
85+
assertions:
86+
- result.code ShouldEqual 0
87+
- result.systemoutjson.last_execution ShouldNotBeEmpty
88+
- result.systemoutjson.start ShouldNotBeEmpty
89+
- result.systemoutjson.num ShouldContainSubstring 1
90+
- result.systemoutjson.status ShouldEqual Success
91+
92+
- name: check-mail-notif
93+
steps:
94+
- type: http
95+
method: GET
96+
url: '{{.smtpmock.url}}/messages/[email protected]'
97+
assertions:
98+
- result.statuscode ShouldEqual 200
99+
- result.bodyjson.__len__ ShouldEqual 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version: v1.0
2+
name: empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: v1.0
2+
name: 04SCWorkflowRunNotif-PIPELINE
3+
stages:
4+
- Stage1
5+
6+
jobs:
7+
- job: EXPORT
8+
stage: Stage1
9+
steps:
10+
- script:
11+
- set -ex
12+
- echo "foo2" >> build.log
13+
- BUILD_LOG=$(cat build.log | tail -n 200 | base64)
14+
- worker export logcontent "$BUILD_LOG"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 04SCWorkflowRunNotif-WORKFLOW-EMPTY
2+
version: v2.0
3+
workflow:
4+
empty:
5+
pipeline: empty
6+
metadata:
7+
default_tags: git.branch,git.author
8+
notifications:
9+
- type: email
10+
pipelines:
11+
- empty
12+
settings:
13+
on_success: always
14+
recipients:
15+
16+
template:
17+
body: |
18+
foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 04SCWorkflowRunNotif-WORKFLOW
2+
version: v2.0
3+
workflow:
4+
test-notif:
5+
pipeline: 04SCWorkflowRunNotif-PIPELINE
6+
metadata:
7+
default_tags: git.branch,git.author
8+
notifications:
9+
- type: email
10+
pipelines:
11+
- test-notif
12+
settings:
13+
on_success: always
14+
recipients:
15+
16+
template:
17+
body: |
18+
title:{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}}
19+
url:{{.cds.buildURL}}
20+
logcontent:{{.cds.build.logcontent | b64dec}}

tests/test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ cli_tests() {
123123
workflow_tests() {
124124
echo "Running Workflow tests:"
125125
for f in $(ls -1 04_*.yml); do
126-
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"
126+
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"
127127
echo -e " ${YELLOW}${f} ${DARKGRAY}[${CMD}]${NOCOLOR}"
128128
${CMD} >${f}.output 2>&1
129129
check_failure $? ${f}.output
@@ -138,7 +138,7 @@ workflow_with_integration_tests() {
138138
if [ -z "$OS_PASSWORD" ]; then echo "missing OS_* variables"; exit 1; fi
139139
echo "Running Workflow with Storage integration tests:"
140140
for f in $(ls -1 05_*.yml); do
141-
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}"
141+
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}"
142142
echo -e " ${YELLOW}${f} ${DARKGRAY}[${CMD}]${NOCOLOR}"
143143
${CMD} >${f}.output 2>&1
144144
check_failure $? ${f}.output

0 commit comments

Comments
 (0)