From 7fb993d784fcca2660651756858e3bd5f248de77 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 4 Nov 2021 11:19:26 +0100 Subject: [PATCH] Resolve duplicate issues --- automation/service/workflow_converter.go | 2 +- automation/types/workflow.go | 21 +++++++++++++++++++++ tests/workflows/0015_step_issue_test.go | 4 ---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/automation/service/workflow_converter.go b/automation/service/workflow_converter.go index 3fb55b5c3..e380c017a 100644 --- a/automation/service/workflow_converter.go +++ b/automation/service/workflow_converter.go @@ -142,7 +142,7 @@ func (svc workflowConverter) makeGraph(def *types.Workflow) (*wfexec.Graph, type } if len(wfii) > 0 { - return nil, wfii + return nil, wfii.Distinct() } return g, nil diff --git a/automation/types/workflow.go b/automation/types/workflow.go index 055aef912..831a8029c 100644 --- a/automation/types/workflow.go +++ b/automation/types/workflow.go @@ -149,6 +149,10 @@ func (set WorkflowIssueSet) Value() (driver.Value, error) { return json.Marshal(set) } +func (issue *WorkflowIssue) String() string { + return fmt.Sprintf("%s [%v]", issue.Description, issue.Culprit) +} + func (set *WorkflowIssueSet) Scan(value interface{}) error { //lint:ignore S1034 This typecast is intentional, we need to get []byte out of a []uint8 switch value.(type) { @@ -186,6 +190,23 @@ func (set WorkflowIssueSet) Append(err error, culprit map[string]int) WorkflowIs }) } +// Distinct returns set of issues without duplicates +func (set WorkflowIssueSet) Distinct() (out WorkflowIssueSet) { + idx := make(map[string]bool) + out = make([]*WorkflowIssue, 0, len(set)) + + for i := range set { + if idx[set[i].String()] { + continue + } + + out = append(out, set[i]) + idx[set[i].String()] = true + } + + return +} + func (set WorkflowIssueSet) SetCulprit(name string, pos int) WorkflowIssueSet { for i := range set { set[i].Culprit[name] = pos diff --git a/tests/workflows/0015_step_issue_test.go b/tests/workflows/0015_step_issue_test.go index 46b0a973d..1dfdfbb53 100644 --- a/tests/workflows/0015_step_issue_test.go +++ b/tests/workflows/0015_step_issue_test.go @@ -18,7 +18,6 @@ func Test0015_step_issue(t *testing.T) { loadScenario(ctx, t) t.Run("exclusive gateway step issue", func(t *testing.T) { - t.Skipf("workflow step resolution & validation need to be to be fixed") _, _, err := execWorkflow(ctx, "case1", types.WorkflowExecParams{}) issues, is := err.(types.WorkflowIssueSet) @@ -31,7 +30,6 @@ func Test0015_step_issue(t *testing.T) { }) t.Run("inclusive gateway step issue", func(t *testing.T) { - t.Skipf("workflow step resolution & validation need to be to be fixed") _, _, err := execWorkflow(ctx, "case2", types.WorkflowExecParams{}) issues, is := err.(types.WorkflowIssueSet) @@ -44,7 +42,6 @@ func Test0015_step_issue(t *testing.T) { }) t.Run("function step issue", func(t *testing.T) { - t.Skipf("workflow step resolution & validation need to be to be fixed") _, _, err := execWorkflow(ctx, "case3", types.WorkflowExecParams{}) issues, is := err.(types.WorkflowIssueSet) @@ -56,7 +53,6 @@ func Test0015_step_issue(t *testing.T) { }) t.Run("iterator step issue", func(t *testing.T) { - t.Skipf("workflow step resolution & validation need to be to be fixed") _, _, err := execWorkflow(ctx, "case4", types.WorkflowExecParams{}) issues, is := err.(types.WorkflowIssueSet)