Skip to content

Commit

Permalink
fix(api): fix duplicate notif for empty pipeline
Browse files Browse the repository at this point in the history
* test(api): integration test for mail notif

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Mar 26, 2020
1 parent 7505302 commit d8e7c1b
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 6 deletions.
14 changes: 12 additions & 2 deletions engine/api/workflow/execute_node_job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/01_signup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ vars:
cdsctl.config : './cdsrc'
smtpmock.url: 'http://localhost:2024'
username: cds.integration.tests.rw
ring:
email: [email protected]
fullname: cds.integration.tests.rw
password: "123456&éçà(§"
ring:
smtpmock.url: 'http://localhost:2024'


testcases:
- name: Check SMTP mock
Expand Down
99 changes: 99 additions & 0 deletions tests/04_sc_workflow_run_notif.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]'
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.__len__ ShouldEqual 1
- type: http
method: GET
url: '{{.smtpmock.url}}/messages/[email protected]/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/[email protected]'
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.__len__ ShouldEqual 1
2 changes: 2 additions & 0 deletions tests/fixtures/04SCWorkflowRunNotif/empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version: v1.0
name: empty
14 changes: 14 additions & 0 deletions tests/fixtures/04SCWorkflowRunNotif/pipeline.yml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions tests/fixtures/04SCWorkflowRunNotif/workflow-empty.yml
Original file line number Diff line number Diff line change
@@ -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:
- [email protected]
template:
body: |
foo
20 changes: 20 additions & 0 deletions tests/fixtures/04SCWorkflowRunNotif/workflow.yml
Original file line number Diff line number Diff line change
@@ -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:
- [email protected]
template:
body: |
title:{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}}
url:{{.cds.buildURL}}
logcontent:{{.cds.build.logcontent | b64dec}}
4 changes: 2 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d8e7c1b

Please sign in to comment.