Skip to content

Commit

Permalink
Pass a runtime to the test runner (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferglor authored Jan 24, 2025
1 parent bcaa629 commit a36a3f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
12 changes: 6 additions & 6 deletions pkg/capabilities/cli/cmd/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestTypeGeneration(t *testing.T) {

func TestMockGeneration(t *testing.T) {
t.Run("Basic trigger", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
capMock := basictriggertest.Trigger(runner, func() (basictrigger.TriggerOutputs, error) {
return basictrigger.TriggerOutputs{}, nil
})
Expand All @@ -280,7 +280,7 @@ func TestMockGeneration(t *testing.T) {
})

t.Run("Basic action", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

// nolint value is never used but it's assigned to mock to verify the type
capMock := basicactiontest.Action(runner, func(_ basicaction.ActionInputs) (basicaction.ActionOutputs, error) {
Expand All @@ -300,7 +300,7 @@ func TestMockGeneration(t *testing.T) {
})

t.Run("Basic target", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
capMock := basictargettest.Target(runner, func(_ basictarget.TargetInputs) error {
return nil
})
Expand All @@ -312,7 +312,7 @@ func TestMockGeneration(t *testing.T) {
})

t.Run("References", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

// nolint value is never used but it's assigned to mock to verify the type
capMock := referenceactiontest.Action(runner, func(_ referenceaction.SomeInputs) (referenceaction.SomeOutputs, error) {
Expand All @@ -332,7 +332,7 @@ func TestMockGeneration(t *testing.T) {
})

t.Run("External references", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

// nolint value is never used but it's assigned to mock to verify the type
capMock := externalreferenceactiontest.Action(runner, func(_ referenceaction.SomeInputs) (referenceaction.SomeOutputs, error) {
Expand All @@ -355,7 +355,7 @@ func TestMockGeneration(t *testing.T) {
// no need to test nesting, we don't generate anything different for the mock's

t.Run("Array action", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
// nolint value is never used but it's assigned to mock to verify the type
capMock := arrayactiontest.Action(runner, func(_ arrayaction.ActionInputs) ([]arrayaction.ActionOutputsElem, error) {
return []arrayaction.ActionOutputsElem{}, nil
Expand Down
8 changes: 6 additions & 2 deletions pkg/workflows/sdk/testutils/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"
)

func NewRunner(ctx context.Context) *Runner {
func NewRunner(ctx context.Context, runtime sdk.Runtime) *Runner {
if runtime == nil {
runtime = &NoopRuntime{}
}

return &Runner{
ctx: ctx,
registry: map[string]capabilities.ExecutableCapability{},
results: runnerResults{},
idToStep: map[string]sdk.StepDefinition{},
dependencies: map[string][]string{},
runtime: &NoopRuntime{},
runtime: runtime,
}
}

Expand Down
28 changes: 14 additions & 14 deletions pkg/workflows/sdk/testutils/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRunner(t *testing.T) {
helper := &testHelper{t: t}
workflow := createBasicTestWorkflow(helper.transformTrigger)

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

triggerMock, actionMock, consensusMock, targetMock := setupAllRunnerMocks(t, runner)

Expand Down Expand Up @@ -92,7 +92,7 @@ func TestRunner(t *testing.T) {
Schedule: "oneAtATime",
}.New(workflow, "[email protected]", chainwriter.TargetInput{SignedReport: consensus})

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
_, _, _, targetMock := setupAllRunnerMocks(t, runner)

runner.Run(workflow)
Expand All @@ -104,7 +104,7 @@ func TestRunner(t *testing.T) {
t.Run("Run returns errors if capabilities were registered multiple times", func(t *testing.T) {
helper := &testHelper{t: t}
workflow := createBasicTestWorkflow(helper.transformTrigger)
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
setupAllRunnerMocks(t, runner)
setupAllRunnerMocks(t, runner)

Expand All @@ -118,7 +118,7 @@ func TestRunner(t *testing.T) {
return false, expectedErr
})

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

basictriggertest.Trigger(runner, func() (basictrigger.TriggerOutputs, error) {
return basictrigger.TriggerOutputs{CoolOutput: "cool"}, nil
Expand All @@ -141,7 +141,7 @@ func TestRunner(t *testing.T) {
helper := &testHelper{t: t}
workflow := createBasicTestWorkflow(helper.transformTrigger)

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

basictriggertest.Trigger(runner, func() (basictrigger.TriggerOutputs, error) {
return basictrigger.TriggerOutputs{CoolOutput: "cool"}, nil
Expand All @@ -159,7 +159,7 @@ func TestRunner(t *testing.T) {
})

t.Run("Run registers and unregisters from capabilities", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

workflow, testTriggerConfig, testTargetConfig := registrationWorkflow()

Expand All @@ -178,7 +178,7 @@ func TestRunner(t *testing.T) {
})

t.Run("Run captures register errors", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

workflow, _, _ := registrationWorkflow()

Expand All @@ -196,7 +196,7 @@ func TestRunner(t *testing.T) {
})

t.Run("Run captures unregister errors", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})

workflow, _, _ := registrationWorkflow()

Expand All @@ -214,7 +214,7 @@ func TestRunner(t *testing.T) {
})

t.Run("GetRegisteredMock returns the mock for a step", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
expected := basicactiontest.ActionForStep(runner, "action", func(input basicaction.ActionInputs) (basicaction.ActionOutputs, error) {
return basicaction.ActionOutputs{}, nil
})
Expand All @@ -229,7 +229,7 @@ func TestRunner(t *testing.T) {
})

t.Run("GetRegisteredMock returns a default mock if step wasn't specified", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
expected := basicactiontest.Action(runner, func(input basicaction.ActionInputs) (basicaction.ActionOutputs, error) {
return basicaction.ActionOutputs{}, nil
})
Expand All @@ -238,15 +238,15 @@ func TestRunner(t *testing.T) {
})

t.Run("GetRegisteredMock returns nil if no mock was registered", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
referenceactiontest.Action(runner, func(input referenceaction.SomeInputs) (referenceaction.SomeOutputs, error) {
return referenceaction.SomeOutputs{}, nil
})
assert.Nil(t, runner.GetRegisteredMock("[email protected]", "action"))
})

t.Run("GetRegisteredMock returns nil if no mock was registered for a step", func(t *testing.T) {
runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
differentStep := basicactiontest.ActionForStep(runner, "step", func(input basicaction.ActionInputs) (basicaction.ActionOutputs, error) {
return basicaction.ActionOutputs{}, nil
})
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestCompute(t *testing.T) {
return actual, nil
})

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
basictriggertest.Trigger(runner, func() (basictrigger.TriggerOutputs, error) {
return basictrigger.TriggerOutputs{CoolOutput: "100"}, nil
})
Expand All @@ -304,7 +304,7 @@ func TestCompute(t *testing.T) {
return c, nil
})

runner := testutils.NewRunner(tests.Context(t))
runner := testutils.NewRunner(tests.Context(t), &testutils.NoopRuntime{})
secretToken := "superSuperSecretToken"
runner.Secrets = map[string]string{
"fidelity": secretToken,
Expand Down

0 comments on commit a36a3f7

Please sign in to comment.