From 4dd15ddffc3f0c3a827e266e5a32171ea545efd1 Mon Sep 17 00:00:00 2001 From: Michael Street <5597260+MStreet3@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:23:57 +0200 Subject: [PATCH] refactor(syncer): alias to ORM with new spec DS --- core/services/workflows/syncer/handler.go | 2 +- core/services/workflows/syncer/mocks/orm.go | 58 +++++++++++++++++++++ core/services/workflows/syncer/orm.go | 9 +++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/core/services/workflows/syncer/handler.go b/core/services/workflows/syncer/handler.go index f5e2f3aea9b..01e13d106f9 100644 --- a/core/services/workflows/syncer/handler.go +++ b/core/services/workflows/syncer/handler.go @@ -101,7 +101,7 @@ type eventHandler struct { // newEventHandler returns a new eventHandler instance. func newEventHandler( lggr logger.Logger, - orm WorkflowSecretsDS, + orm ORM, gateway FetcherFunc, workflowStore store.Store, capRegistry core.CapabilitiesRegistry, diff --git a/core/services/workflows/syncer/mocks/orm.go b/core/services/workflows/syncer/mocks/orm.go index b3d82c2067d..19c459fa0ee 100644 --- a/core/services/workflows/syncer/mocks/orm.go +++ b/core/services/workflows/syncer/mocks/orm.go @@ -5,6 +5,7 @@ package mocks import ( context "context" + job "github.com/smartcontractkit/chainlink/v2/core/services/job" mock "github.com/stretchr/testify/mock" ) @@ -80,6 +81,63 @@ func (_c *ORM_Create_Call) RunAndReturn(run func(context.Context, string, string return _c } +// CreateWorkflowSpec provides a mock function with given fields: ctx, spec +func (_m *ORM) CreateWorkflowSpec(ctx context.Context, spec *job.WorkflowSpec) (int64, error) { + ret := _m.Called(ctx, spec) + + if len(ret) == 0 { + panic("no return value specified for CreateWorkflowSpec") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *job.WorkflowSpec) (int64, error)); ok { + return rf(ctx, spec) + } + if rf, ok := ret.Get(0).(func(context.Context, *job.WorkflowSpec) int64); ok { + r0 = rf(ctx, spec) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, *job.WorkflowSpec) error); ok { + r1 = rf(ctx, spec) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ORM_CreateWorkflowSpec_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateWorkflowSpec' +type ORM_CreateWorkflowSpec_Call struct { + *mock.Call +} + +// CreateWorkflowSpec is a helper method to define mock.On call +// - ctx context.Context +// - spec *job.WorkflowSpec +func (_e *ORM_Expecter) CreateWorkflowSpec(ctx interface{}, spec interface{}) *ORM_CreateWorkflowSpec_Call { + return &ORM_CreateWorkflowSpec_Call{Call: _e.mock.On("CreateWorkflowSpec", ctx, spec)} +} + +func (_c *ORM_CreateWorkflowSpec_Call) Run(run func(ctx context.Context, spec *job.WorkflowSpec)) *ORM_CreateWorkflowSpec_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*job.WorkflowSpec)) + }) + return _c +} + +func (_c *ORM_CreateWorkflowSpec_Call) Return(_a0 int64, _a1 error) *ORM_CreateWorkflowSpec_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ORM_CreateWorkflowSpec_Call) RunAndReturn(run func(context.Context, *job.WorkflowSpec) (int64, error)) *ORM_CreateWorkflowSpec_Call { + _c.Call.Return(run) + return _c +} + // GetContents provides a mock function with given fields: ctx, url func (_m *ORM) GetContents(ctx context.Context, url string) (string, error) { ret := _m.Called(ctx, url) diff --git a/core/services/workflows/syncer/orm.go b/core/services/workflows/syncer/orm.go index 6c767127908..d43dbe09b78 100644 --- a/core/services/workflows/syncer/orm.go +++ b/core/services/workflows/syncer/orm.go @@ -36,14 +36,19 @@ type WorkflowSpecsDS interface { CreateWorkflowSpec(ctx context.Context, spec *job.WorkflowSpec) (int64, error) } -type WorkflowRegistryDS = WorkflowSecretsDS +type ORM interface { + WorkflowSecretsDS + WorkflowSpecsDS +} + +type WorkflowRegistryDS = ORM type orm struct { ds sqlutil.DataSource lggr logger.Logger } -var _ WorkflowSecretsDS = (*orm)(nil) +var _ WorkflowRegistryDS = (*orm)(nil) func NewWorkflowRegistryDS(ds sqlutil.DataSource, lggr logger.Logger) *orm { return &orm{