Skip to content

Commit

Permalink
fix(api): display hook's conditions in as code (#4756)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
  • Loading branch information
bnjjj authored and sguiheux committed Nov 14, 2019
1 parent 29b8c8a commit c967013
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sdk/exportentities/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,18 @@ func NewWorkflow(w sdk.Workflow, opts ...WorkflowOptions) (Workflow, error) {
if m == nil {
return exportedWorkflow, sdk.WrapError(sdk.ErrNotFound, "unable to find hook model %s", h.HookModelName)
}
pipHook := HookEntry{
Model: h.HookModelName,
Ref: h.Ref,
Config: h.Config.Values(m.DefaultConfig),
Conditions: &h.Conditions,
}

if h.Conditions.LuaScript == "" && len(h.Conditions.PlainConditions) == 0 {
pipHook.Conditions = nil
}

exportedWorkflow.Hooks[n.Name] = append(exportedWorkflow.Hooks[n.Name], HookEntry{
Model: h.HookModelName,
Ref: h.Ref,
Config: h.Config.Values(m.DefaultConfig),
})
exportedWorkflow.Hooks[n.Name] = append(exportedWorkflow.Hooks[n.Name], pipHook)
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions sdk/exportentities/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,80 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
},
},
},
// hook conditions
{
name: "Workflow with multiple nodes should display hook conditions",
fields: fields{
Workflow: map[string]exportentities.NodeEntry{
"root": {
PipelineName: "pipeline-root",
},
"child": {
PipelineName: "pipeline-child",
DependsOn: []string{"root"},
OneAtATime: &exportentities.True,
},
},
Hooks: map[string][]exportentities.HookEntry{
"root": []exportentities.HookEntry{{
Model: "Scheduler",
Config: map[string]string{
"crontab": "* * * * *",
"payload": "{}",
},
Conditions: &sdk.WorkflowNodeConditions{
LuaScript: "return true",
},
}},
},
},
wantErr: false,
want: sdk.Workflow{
HistoryLength: sdk.DefaultHistoryLength,
WorkflowData: &sdk.WorkflowData{
Node: sdk.Node{
Name: "root",
Type: "pipeline",
Hooks: []sdk.NodeHook{
{
HookModelName: "Scheduler",
Conditions: sdk.WorkflowNodeConditions{
LuaScript: "return true",
},
Config: sdk.WorkflowNodeHookConfig{
"crontab": sdk.WorkflowNodeHookConfigValue{
Value: "* * * * *",
Configurable: true,
Type: sdk.HookConfigTypeString,
},
"payload": sdk.WorkflowNodeHookConfigValue{
Value: "{}",
Configurable: true,
Type: sdk.HookConfigTypeString,
},
},
},
},
Context: &sdk.NodeContext{
PipelineName: "pipeline-root",
},
Triggers: []sdk.NodeTrigger{
{
ChildNode: sdk.Node{
Name: "child",
Ref: "child",
Type: "pipeline",
Context: &sdk.NodeContext{
PipelineName: "pipeline-child",
Mutex: true,
},
},
},
},
},
},
},
},
// root(pipeline-root) -> child(pipeline-child)
{
name: "Complexe workflow without joins and mutex should not raise an error",
Expand Down

0 comments on commit c967013

Please sign in to comment.