From c4843cdaf5ddf518e1cb45f4123dd38e84905b31 Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Tue, 23 Feb 2021 22:55:29 +0530 Subject: [PATCH] Misc fixes related to workflows --- v2/pkg/templates/compile.go | 1 + v2/pkg/workflows/compile.go | 2 +- v2/pkg/workflows/execute.go | 2 +- v2/pkg/workflows/execute_test.go | 24 ++++++++++++------------ v2/pkg/workflows/workflows.go | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/v2/pkg/templates/compile.go b/v2/pkg/templates/compile.go index 6b2630e7..90035104 100644 --- a/v2/pkg/templates/compile.go +++ b/v2/pkg/templates/compile.go @@ -71,6 +71,7 @@ func Parse(filePath string, options protocols.ExecuterOptions) (*Template, error return nil, errors.Wrap(err, "could not compile workflow") } template.CompiledWorkflow = compiled + template.CompiledWorkflow.Options = &options } // Compile the requests found diff --git a/v2/pkg/workflows/compile.go b/v2/pkg/workflows/compile.go index d7392dbf..59d45e06 100644 --- a/v2/pkg/workflows/compile.go +++ b/v2/pkg/workflows/compile.go @@ -10,7 +10,7 @@ import ( // Parse a yaml workflow file func Parse(file string, options *protocols.ExecuterOptions) (*Workflow, error) { - workflow := &Workflow{options: options} + workflow := &Workflow{Options: options} f, err := os.Open(file) if err != nil { diff --git a/v2/pkg/workflows/execute.go b/v2/pkg/workflows/execute.go index c22ccb02..70d1edcc 100644 --- a/v2/pkg/workflows/execute.go +++ b/v2/pkg/workflows/execute.go @@ -11,7 +11,7 @@ import ( func (w *Workflow) RunWorkflow(input string) bool { results := &atomic.Bool{} - swg := sizedwaitgroup.New(w.options.Options.TemplateThreads) + swg := sizedwaitgroup.New(w.Options.Options.TemplateThreads) for _, template := range w.Workflows { swg.Add() func(template *WorkflowTemplate) { diff --git a/v2/pkg/workflows/execute_test.go b/v2/pkg/workflows/execute_test.go index 6a94cefc..86cc92d6 100644 --- a/v2/pkg/workflows/execute_test.go +++ b/v2/pkg/workflows/execute_test.go @@ -12,9 +12,9 @@ import ( ) func TestWorkflowsSimple(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: true}, Options: &protocols.ExecuterOptions{Progress: progress}}, }}, @@ -25,10 +25,10 @@ func TestWorkflowsSimple(t *testing.T) { } func TestWorkflowsSimpleMultiple(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) var firstInput, secondInput string - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: true, executeHook: func(input string) { firstInput = input @@ -49,10 +49,10 @@ func TestWorkflowsSimpleMultiple(t *testing.T) { } func TestWorkflowsSubtemplates(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) var firstInput, secondInput string - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: true, executeHook: func(input string) { firstInput = input @@ -72,10 +72,10 @@ func TestWorkflowsSubtemplates(t *testing.T) { } func TestWorkflowsSubtemplatesNoMatch(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) var firstInput, secondInput string - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: false, executeHook: func(input string) { firstInput = input @@ -95,10 +95,10 @@ func TestWorkflowsSubtemplatesNoMatch(t *testing.T) { } func TestWorkflowsSubtemplatesWithMatcher(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) var firstInput, secondInput string - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: true, executeHook: func(input string) { firstInput = input @@ -123,10 +123,10 @@ func TestWorkflowsSubtemplatesWithMatcher(t *testing.T) { } func TestWorkflowsSubtemplatesWithMatcherNoMatch(t *testing.T) { - progress, _ := progress.NewProgress(false, false, 0) + progress, _ := progress.NewProgress(0, false, false, 0) var firstInput, secondInput string - workflow := &Workflow{options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ + workflow := &Workflow{Options: &protocols.ExecuterOptions{Options: &types.Options{TemplateThreads: 10}}, Workflows: []*WorkflowTemplate{ {Executers: []*ProtocolExecuterPair{{ Executer: &mockExecuter{result: true, executeHook: func(input string) { firstInput = input diff --git a/v2/pkg/workflows/workflows.go b/v2/pkg/workflows/workflows.go index 0ac29f67..91a8ae34 100644 --- a/v2/pkg/workflows/workflows.go +++ b/v2/pkg/workflows/workflows.go @@ -7,7 +7,7 @@ type Workflow struct { // Workflows is a yaml based workflow declaration code. Workflows []*WorkflowTemplate `yaml:"workflows,omitempty"` - options *protocols.ExecuterOptions + Options *protocols.ExecuterOptions } // WorkflowTemplate is a template to be ran as part of a workflow