diff --git a/.ci/mockery_header.txt b/.ci/mockery_header.txt new file mode 100644 index 00000000..d1bc2101 --- /dev/null +++ b/.ci/mockery_header.txt @@ -0,0 +1,7 @@ +/* + * SPDX-FileCopyrightText: 2023 Siemens AG + * + * SPDX-License-Identifier: Apache-2.0 + * + * Author: Michael Adler + */ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52e0e9d6..ce86b6e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -213,5 +213,8 @@ jobs: - run: apk add --no-cache py3-yaml git just bash go - name: Disable git security features run: git config --global safe.directory '*' + - uses: brokeyourbike/go-mockery-action@v0 + with: + mockery-version: "2.36.0" - run: just generate - run: git diff --exit-code diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 00000000..cf4115e3 --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,19 @@ +with-expecter: True +inpackage: True +dir: "{{.InterfaceDir}}" +mockname: "Mock{{.InterfaceName}}" +outpkg: "{{.PackageName}}" +filename: "mock_{{.InterfaceName}}.go" +all: True + +boilerplate-file: .ci/mockery_header.txt +# tags are currently broken, see vektra/mockery issue #691 +tags: testing + +packages: + github.com/siemens/wfx/persistence: + config: + tags: testing + recursive: True + interfaces: + Storage: diff --git a/api/northbound.go b/api/northbound.go index 1e48b034..0b76dfa5 100644 --- a/api/northbound.go +++ b/api/northbound.go @@ -189,7 +189,9 @@ func NewNorthboundAPI(storage persistence.Storage) *operations.WorkflowExecutorA err2.Message = err.Error() return northbound.NewPostWorkflowsBadRequest().WithPayload(&model.ErrorResponse{Errors: []*model.Error{&err2}}) case ftag.AlreadyExists: - return northbound.NewPostWorkflowsBadRequest().WithPayload(&model.ErrorResponse{Errors: []*model.Error{&WorkflowNotUnique}}) + err2 := WorkflowNotUnique + err2.Message = fmt.Sprintf("Workflow with name '%s' already exists", params.Workflow.Name) + return northbound.NewPostWorkflowsBadRequest().WithPayload(&model.ErrorResponse{Errors: []*model.Error{&err2}}) default: return northbound.NewPostWorkflowsDefault(http.StatusInternalServerError) } diff --git a/codecov.yml b/codecov.yml index a3a9f21a..731e647a 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,9 +3,14 @@ # SPDX-License-Identifier: Apache-2.0 # # Author: Michael Adler - +# # This file can be validated as follows: # curl -X POST --data-binary @codecov.yml https://codecov.io/validate + +ignore: + # exclude mocks generated by mockery + - "**/mock_*.go" + coverage: status: patch: diff --git a/go.mod b/go.mod index 9fd952b5..4107dc16 100644 --- a/go.mod +++ b/go.mod @@ -98,6 +98,7 @@ require ( github.com/muesli/mango-pflag v0.1.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/tsenart/go-tsz v0.0.0-20180814235614-0bd30b3df1c3 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect go.mongodb.org/mongo-driver v1.11.6 // indirect diff --git a/internal/handler/job/definition/update.go b/internal/handler/job/definition/update.go index 79e272c9..49c0ccd1 100644 --- a/internal/handler/job/definition/update.go +++ b/internal/handler/job/definition/update.go @@ -23,11 +23,10 @@ import ( func Update(ctx context.Context, storage persistence.Storage, jobID string, definition map[string]any) (map[string]any, error) { log := logging.LoggerFromCtx(ctx) contextLogger := log.With().Str("id", jobID).Logger() - contextLogger.Debug().Msg("Updating job definition") job, err := storage.GetJob(ctx, jobID, persistence.FetchParams{History: false}) if err != nil { - contextLogger.Error().Err(err).Msg("Failed to fetch job from database") + contextLogger.Err(err).Msg("Failed to get job from storage") return nil, fault.Wrap(err) } @@ -36,7 +35,7 @@ func Update(ctx context.Context, storage persistence.Storage, jobID string, defi result, err := storage.UpdateJob(ctx, job, persistence.JobUpdate{Status: job.Status, Definition: &job.Definition}) if err != nil { - contextLogger.Error().Err(err).Msg("Failed to update job") + contextLogger.Err(err).Msg("Failed to update job") return nil, fault.Wrap(err) } diff --git a/internal/handler/job/delete.go b/internal/handler/job/delete.go index 4a23f534..a2dca282 100644 --- a/internal/handler/job/delete.go +++ b/internal/handler/job/delete.go @@ -18,6 +18,10 @@ import ( func DeleteJob(ctx context.Context, storage persistence.Storage, jobID string) error { log := logging.LoggerFromCtx(ctx) - log.Info().Str("id", jobID).Msg("Deleting job") - return fault.Wrap(storage.DeleteJob(ctx, jobID)) + if err := storage.DeleteJob(ctx, jobID); err != nil { + log.Err(err).Str("id", jobID).Msg("Failed to delete job") + return fault.Wrap(err) + } + log.Info().Str("id", jobID).Msg("Deleted job") + return nil } diff --git a/internal/handler/job/status/update.go b/internal/handler/job/status/update.go index f4a24258..ef388ea8 100644 --- a/internal/handler/job/status/update.go +++ b/internal/handler/job/status/update.go @@ -21,11 +21,7 @@ import ( ) func Update(ctx context.Context, storage persistence.Storage, jobID string, newStatus *model.JobStatus, actor model.EligibleEnum) (*model.JobStatus, error) { - log := logging.LoggerFromCtx(ctx) - contextLogger := log.With(). - Str("id", jobID). - Str("actor", string(actor)). - Logger() + contextLogger := logging.LoggerFromCtx(ctx).With().Str("id", jobID).Str("actor", string(actor)).Logger() job, err := storage.GetJob(ctx, jobID, persistence.FetchParams{History: false}) if err != nil { @@ -33,7 +29,6 @@ func Update(ctx context.Context, storage persistence.Storage, jobID string, newS } from := job.Status.State - contextLogger.Debug().Str("from", from).Msg("Updating job") // update status to := newStatus.State @@ -57,38 +52,32 @@ func Update(ctx context.Context, storage persistence.Storage, jobID string, newS } if !isAllowed { if !foundTransition { - contextLogger.Info().Msg("Transition does not exist") + contextLogger.Warn().Msg("Transition does not exist") return nil, fault.Wrap(fmt.Errorf("transition from '%s' to '%s' does not exist", from, to), ftag.With(ftag.InvalidArgument)) } - contextLogger.Info().Msg("Transition exists but actor is not allowed to trigger it") + contextLogger.Warn().Msg("Transition exists but actor is not allowed to trigger it") return nil, fault.Wrap(fmt.Errorf("transition from '%s' to '%s' is not allowed for actor '%s'", from, to, actor), ftag.With(ftag.InvalidArgument)) } // transition is allowed, now apply wfx transitions newTo := workflow.FollowImmediateTransitions(job.Workflow, to) if newTo != to { - log.Debug().Str("to", to).Str("newTo", newTo).Msg("Resetting state since we moved the transition forward") + contextLogger.Debug().Str("to", to).Str("newTo", newTo).Msg("Resetting state since we moved the transition forward") newStatus = &model.JobStatus{} } newStatus.State = newTo // override any definitionHash provided by client newStatus.DefinitionHash = job.Status.DefinitionHash - log.Debug(). - Str("message", job.Status.Message). - Str("state", job.Status.State). - Msg("Updating job") - result, err := storage.UpdateJob(ctx, job, persistence.JobUpdate{Status: newStatus}) if err != nil { - log.Error().Err(err).Msg("Failed to persist job update") + contextLogger.Err(err).Msg("Failed to persist job update") return nil, fault.Wrap(err) } - if from != to { - contextLogger.Info().Msg("Updated job status") - } else { - contextLogger.Debug().Msg("Updated job status") - } + contextLogger.Info(). + Str("from", from). + Str("to", newStatus.State). + Msg("Updated job status") return result.Status, nil } diff --git a/internal/handler/job/tags/add.go b/internal/handler/job/tags/add.go index 6571374c..ca10429f 100644 --- a/internal/handler/job/tags/add.go +++ b/internal/handler/job/tags/add.go @@ -18,19 +18,20 @@ import ( func Add(ctx context.Context, storage persistence.Storage, jobID string, tags []string) ([]string, error) { log := logging.LoggerFromCtx(ctx) - contextLogger := log.With().Str("id", jobID).Logger() - contextLogger.Debug().Strs("tags", tags).Msg("Adding tags") + contextLogger := log.With().Str("id", jobID).Strs("tags", tags).Logger() job, err := storage.GetJob(ctx, jobID, persistence.FetchParams{History: false}) if err != nil { + contextLogger.Err(err).Msg("Failed to get job from storage") return nil, fault.Wrap(err) } updatedJob, err := storage.UpdateJob(ctx, job, persistence.JobUpdate{AddTags: &tags}) if err != nil { + contextLogger.Err(err).Msg("Failed to add tags to job") return nil, fault.Wrap(err) } - contextLogger.Info().Msg("Updated job tags") + contextLogger.Info().Msg("Added job tags") return updatedJob.Tags, nil } diff --git a/internal/handler/job/tags/add_test.go b/internal/handler/job/tags/add_test.go index 50ba804e..70ac2f7f 100644 --- a/internal/handler/job/tags/add_test.go +++ b/internal/handler/job/tags/add_test.go @@ -10,6 +10,7 @@ package tags import ( "context" + "errors" "testing" "github.com/siemens/wfx/generated/model" @@ -38,6 +39,33 @@ func TestAdd(t *testing.T) { assert.Equal(t, []string{"bar", "foo"}, actual) } +func TestAdd_FaultyStorageGet(t *testing.T) { + db := persistence.NewMockStorage(t) + ctx := context.Background() + expectedErr := errors.New("mock error") + db.On("GetJob", ctx, "1", persistence.FetchParams{History: false}).Return(nil, expectedErr) + + tags, err := Add(ctx, db, "1", []string{"foo", "bar"}) + assert.Nil(t, tags) + assert.NotNil(t, err) +} + +func TestAdd_FaultyStorageUpdate(t *testing.T) { + db := persistence.NewMockStorage(t) + ctx := context.Background() + + expectedErr := errors.New("mock error") + dummyJob := model.Job{ID: "1"} + tags := []string{"foo", "bar"} + + db.On("GetJob", ctx, "1", persistence.FetchParams{History: false}).Return(&dummyJob, nil) + db.On("UpdateJob", ctx, &dummyJob, persistence.JobUpdate{AddTags: &tags}).Return(nil, expectedErr) + + tags, err := Add(ctx, db, "1", tags) + assert.Nil(t, tags) + assert.NotNil(t, err) +} + func newInMemoryDB(t *testing.T) persistence.Storage { db := &entgo.SQLite{} err := db.Initialize(context.Background(), "file:wfx?mode=memory&cache=shared&_fk=1") diff --git a/internal/handler/job/tags/delete.go b/internal/handler/job/tags/delete.go index 35995fd5..5541bedd 100644 --- a/internal/handler/job/tags/delete.go +++ b/internal/handler/job/tags/delete.go @@ -18,18 +18,19 @@ import ( func Delete(ctx context.Context, storage persistence.Storage, jobID string, tags []string) ([]string, error) { log := logging.LoggerFromCtx(ctx) - contextLogger := log.With().Str("id", jobID).Logger() - contextLogger.Debug().Strs("tags", tags).Msg("Deleting tags") + contextLogger := log.With().Str("id", jobID).Strs("tags", tags).Logger() job, err := storage.GetJob(ctx, jobID, persistence.FetchParams{History: false}) if err != nil { + contextLogger.Err(err).Msg("Failed to get job from storage") return nil, fault.Wrap(err) } updatedJob, err := storage.UpdateJob(ctx, job, persistence.JobUpdate{DelTags: &tags}) if err != nil { + contextLogger.Err(err).Msg("Failed to delete tags to job") return nil, fault.Wrap(err) } - contextLogger.Debug().Msg("Deleted tags") + contextLogger.Info().Msg("Deleted job tags") return updatedJob.Tags, nil } diff --git a/internal/handler/job/tags/delete_test.go b/internal/handler/job/tags/delete_test.go index 6e9365a6..087c0b22 100644 --- a/internal/handler/job/tags/delete_test.go +++ b/internal/handler/job/tags/delete_test.go @@ -10,9 +10,11 @@ package tags import ( "context" + "errors" "testing" "github.com/siemens/wfx/generated/model" + "github.com/siemens/wfx/persistence" "github.com/siemens/wfx/workflow/dau" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,3 +37,30 @@ func TestDelete(t *testing.T) { require.NoError(t, err) assert.Equal(t, []string{"bar"}, tags) } + +func TestDelete_FaultyStorageGet(t *testing.T) { + db := persistence.NewMockStorage(t) + ctx := context.Background() + expectedErr := errors.New("mock error") + db.On("GetJob", ctx, "1", persistence.FetchParams{History: false}).Return(nil, expectedErr) + + tags, err := Delete(ctx, db, "1", []string{"foo", "bar"}) + assert.Nil(t, tags) + assert.NotNil(t, err) +} + +func TestDelete_FaultyStorageUpdate(t *testing.T) { + db := persistence.NewMockStorage(t) + ctx := context.Background() + + expectedErr := errors.New("mock error") + dummyJob := model.Job{ID: "1"} + tags := []string{"foo", "bar"} + + db.On("GetJob", ctx, "1", persistence.FetchParams{History: false}).Return(&dummyJob, nil) + db.On("UpdateJob", ctx, &dummyJob, persistence.JobUpdate{DelTags: &tags}).Return(nil, expectedErr) + + tags, err := Delete(ctx, db, "1", tags) + assert.Nil(t, tags) + assert.NotNil(t, err) +} diff --git a/internal/handler/workflow/create.go b/internal/handler/workflow/create.go index 3b4bf2b1..791d1bdf 100644 --- a/internal/handler/workflow/create.go +++ b/internal/handler/workflow/create.go @@ -28,5 +28,6 @@ func CreateWorkflow(ctx context.Context, storage persistence.Storage, wf *model. log.Error().Err(err).Msg("Failed to create workflow") return nil, fault.Wrap(err) } + log.Info().Str("name", wf.Name).Msg("Created new workflow") return wf, nil } diff --git a/internal/handler/workflow/delete.go b/internal/handler/workflow/delete.go index 2f73a88b..ba4429a7 100644 --- a/internal/handler/workflow/delete.go +++ b/internal/handler/workflow/delete.go @@ -18,6 +18,10 @@ import ( func DeleteWorkflow(ctx context.Context, storage persistence.Storage, name string) error { log := logging.LoggerFromCtx(ctx) - log.Debug().Str("name", name).Msg("Deleting workflow") - return fault.Wrap(storage.DeleteWorkflow(ctx, name)) + if err := storage.DeleteWorkflow(ctx, name); err != nil { + log.Err(err).Str("name", name).Msg("Failed to delete workflow") + return fault.Wrap(err) + } + log.Info().Str("name", name).Msg("Deleted workflow") + return nil } diff --git a/justfile b/justfile index 0bfdb431..5878459d 100644 --- a/justfile +++ b/justfile @@ -112,8 +112,11 @@ _generate-ent: // Code generated by ent, DO NOT EDIT." --feature sql/execquery,sql/versioned-migration ./schema +_generate-mockery: + mockery --all + # Generate code -generate: _generate-swagger _generate-ent +generate: _generate-swagger _generate-ent _generate-mockery # Start PostgreSQL container postgres-start VERSION="15": diff --git a/persistence/.mockery.yaml b/persistence/.mockery.yaml new file mode 100644 index 00000000..cf4115e3 --- /dev/null +++ b/persistence/.mockery.yaml @@ -0,0 +1,19 @@ +with-expecter: True +inpackage: True +dir: "{{.InterfaceDir}}" +mockname: "Mock{{.InterfaceName}}" +outpkg: "{{.PackageName}}" +filename: "mock_{{.InterfaceName}}.go" +all: True + +boilerplate-file: .ci/mockery_header.txt +# tags are currently broken, see vektra/mockery issue #691 +tags: testing + +packages: + github.com/siemens/wfx/persistence: + config: + tags: testing + recursive: True + interfaces: + Storage: diff --git a/persistence/mock_Storage.go b/persistence/mock_Storage.go new file mode 100644 index 00000000..77949723 --- /dev/null +++ b/persistence/mock_Storage.go @@ -0,0 +1,637 @@ +/* + * SPDX-FileCopyrightText: 2023 Siemens AG + * + * SPDX-License-Identifier: Apache-2.0 + * + * Author: Michael Adler + */ + +// Code generated by mockery v2.36.0. DO NOT EDIT. + +package persistence + +import ( + context "context" + + model "github.com/siemens/wfx/generated/model" + mock "github.com/stretchr/testify/mock" +) + +// MockStorage is an autogenerated mock type for the Storage type +type MockStorage struct { + mock.Mock +} + +type MockStorage_Expecter struct { + mock *mock.Mock +} + +func (_m *MockStorage) EXPECT() *MockStorage_Expecter { + return &MockStorage_Expecter{mock: &_m.Mock} +} + +// CheckHealth provides a mock function with given fields: ctx +func (_m *MockStorage) CheckHealth(ctx context.Context) error { + ret := _m.Called(ctx) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStorage_CheckHealth_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckHealth' +type MockStorage_CheckHealth_Call struct { + *mock.Call +} + +// CheckHealth is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockStorage_Expecter) CheckHealth(ctx interface{}) *MockStorage_CheckHealth_Call { + return &MockStorage_CheckHealth_Call{Call: _e.mock.On("CheckHealth", ctx)} +} + +func (_c *MockStorage_CheckHealth_Call) Run(run func(ctx context.Context)) *MockStorage_CheckHealth_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockStorage_CheckHealth_Call) Return(_a0 error) *MockStorage_CheckHealth_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStorage_CheckHealth_Call) RunAndReturn(run func(context.Context) error) *MockStorage_CheckHealth_Call { + _c.Call.Return(run) + return _c +} + +// CreateJob provides a mock function with given fields: ctx, job +func (_m *MockStorage) CreateJob(ctx context.Context, job *model.Job) (*model.Job, error) { + ret := _m.Called(ctx, job) + + var r0 *model.Job + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *model.Job) (*model.Job, error)); ok { + return rf(ctx, job) + } + if rf, ok := ret.Get(0).(func(context.Context, *model.Job) *model.Job); ok { + r0 = rf(ctx, job) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Job) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *model.Job) error); ok { + r1 = rf(ctx, job) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_CreateJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateJob' +type MockStorage_CreateJob_Call struct { + *mock.Call +} + +// CreateJob is a helper method to define mock.On call +// - ctx context.Context +// - job *model.Job +func (_e *MockStorage_Expecter) CreateJob(ctx interface{}, job interface{}) *MockStorage_CreateJob_Call { + return &MockStorage_CreateJob_Call{Call: _e.mock.On("CreateJob", ctx, job)} +} + +func (_c *MockStorage_CreateJob_Call) Run(run func(ctx context.Context, job *model.Job)) *MockStorage_CreateJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*model.Job)) + }) + return _c +} + +func (_c *MockStorage_CreateJob_Call) Return(_a0 *model.Job, _a1 error) *MockStorage_CreateJob_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_CreateJob_Call) RunAndReturn(run func(context.Context, *model.Job) (*model.Job, error)) *MockStorage_CreateJob_Call { + _c.Call.Return(run) + return _c +} + +// CreateWorkflow provides a mock function with given fields: ctx, workflow +func (_m *MockStorage) CreateWorkflow(ctx context.Context, workflow *model.Workflow) (*model.Workflow, error) { + ret := _m.Called(ctx, workflow) + + var r0 *model.Workflow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *model.Workflow) (*model.Workflow, error)); ok { + return rf(ctx, workflow) + } + if rf, ok := ret.Get(0).(func(context.Context, *model.Workflow) *model.Workflow); ok { + r0 = rf(ctx, workflow) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Workflow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *model.Workflow) error); ok { + r1 = rf(ctx, workflow) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_CreateWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateWorkflow' +type MockStorage_CreateWorkflow_Call struct { + *mock.Call +} + +// CreateWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - workflow *model.Workflow +func (_e *MockStorage_Expecter) CreateWorkflow(ctx interface{}, workflow interface{}) *MockStorage_CreateWorkflow_Call { + return &MockStorage_CreateWorkflow_Call{Call: _e.mock.On("CreateWorkflow", ctx, workflow)} +} + +func (_c *MockStorage_CreateWorkflow_Call) Run(run func(ctx context.Context, workflow *model.Workflow)) *MockStorage_CreateWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*model.Workflow)) + }) + return _c +} + +func (_c *MockStorage_CreateWorkflow_Call) Return(_a0 *model.Workflow, _a1 error) *MockStorage_CreateWorkflow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_CreateWorkflow_Call) RunAndReturn(run func(context.Context, *model.Workflow) (*model.Workflow, error)) *MockStorage_CreateWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// DeleteJob provides a mock function with given fields: ctx, jobID +func (_m *MockStorage) DeleteJob(ctx context.Context, jobID string) error { + ret := _m.Called(ctx, jobID) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, jobID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStorage_DeleteJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteJob' +type MockStorage_DeleteJob_Call struct { + *mock.Call +} + +// DeleteJob is a helper method to define mock.On call +// - ctx context.Context +// - jobID string +func (_e *MockStorage_Expecter) DeleteJob(ctx interface{}, jobID interface{}) *MockStorage_DeleteJob_Call { + return &MockStorage_DeleteJob_Call{Call: _e.mock.On("DeleteJob", ctx, jobID)} +} + +func (_c *MockStorage_DeleteJob_Call) Run(run func(ctx context.Context, jobID string)) *MockStorage_DeleteJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockStorage_DeleteJob_Call) Return(_a0 error) *MockStorage_DeleteJob_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStorage_DeleteJob_Call) RunAndReturn(run func(context.Context, string) error) *MockStorage_DeleteJob_Call { + _c.Call.Return(run) + return _c +} + +// DeleteWorkflow provides a mock function with given fields: ctx, name +func (_m *MockStorage) DeleteWorkflow(ctx context.Context, name string) error { + ret := _m.Called(ctx, name) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStorage_DeleteWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteWorkflow' +type MockStorage_DeleteWorkflow_Call struct { + *mock.Call +} + +// DeleteWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockStorage_Expecter) DeleteWorkflow(ctx interface{}, name interface{}) *MockStorage_DeleteWorkflow_Call { + return &MockStorage_DeleteWorkflow_Call{Call: _e.mock.On("DeleteWorkflow", ctx, name)} +} + +func (_c *MockStorage_DeleteWorkflow_Call) Run(run func(ctx context.Context, name string)) *MockStorage_DeleteWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockStorage_DeleteWorkflow_Call) Return(_a0 error) *MockStorage_DeleteWorkflow_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStorage_DeleteWorkflow_Call) RunAndReturn(run func(context.Context, string) error) *MockStorage_DeleteWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// GetJob provides a mock function with given fields: ctx, jobID, fetchParams +func (_m *MockStorage) GetJob(ctx context.Context, jobID string, fetchParams FetchParams) (*model.Job, error) { + ret := _m.Called(ctx, jobID, fetchParams) + + var r0 *model.Job + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, FetchParams) (*model.Job, error)); ok { + return rf(ctx, jobID, fetchParams) + } + if rf, ok := ret.Get(0).(func(context.Context, string, FetchParams) *model.Job); ok { + r0 = rf(ctx, jobID, fetchParams) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Job) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, FetchParams) error); ok { + r1 = rf(ctx, jobID, fetchParams) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_GetJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetJob' +type MockStorage_GetJob_Call struct { + *mock.Call +} + +// GetJob is a helper method to define mock.On call +// - ctx context.Context +// - jobID string +// - fetchParams FetchParams +func (_e *MockStorage_Expecter) GetJob(ctx interface{}, jobID interface{}, fetchParams interface{}) *MockStorage_GetJob_Call { + return &MockStorage_GetJob_Call{Call: _e.mock.On("GetJob", ctx, jobID, fetchParams)} +} + +func (_c *MockStorage_GetJob_Call) Run(run func(ctx context.Context, jobID string, fetchParams FetchParams)) *MockStorage_GetJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(FetchParams)) + }) + return _c +} + +func (_c *MockStorage_GetJob_Call) Return(_a0 *model.Job, _a1 error) *MockStorage_GetJob_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_GetJob_Call) RunAndReturn(run func(context.Context, string, FetchParams) (*model.Job, error)) *MockStorage_GetJob_Call { + _c.Call.Return(run) + return _c +} + +// GetWorkflow provides a mock function with given fields: ctx, name +func (_m *MockStorage) GetWorkflow(ctx context.Context, name string) (*model.Workflow, error) { + ret := _m.Called(ctx, name) + + var r0 *model.Workflow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*model.Workflow, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *model.Workflow); ok { + r0 = rf(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Workflow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_GetWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetWorkflow' +type MockStorage_GetWorkflow_Call struct { + *mock.Call +} + +// GetWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockStorage_Expecter) GetWorkflow(ctx interface{}, name interface{}) *MockStorage_GetWorkflow_Call { + return &MockStorage_GetWorkflow_Call{Call: _e.mock.On("GetWorkflow", ctx, name)} +} + +func (_c *MockStorage_GetWorkflow_Call) Run(run func(ctx context.Context, name string)) *MockStorage_GetWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockStorage_GetWorkflow_Call) Return(_a0 *model.Workflow, _a1 error) *MockStorage_GetWorkflow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_GetWorkflow_Call) RunAndReturn(run func(context.Context, string) (*model.Workflow, error)) *MockStorage_GetWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// Initialize provides a mock function with given fields: ctx, options +func (_m *MockStorage) Initialize(ctx context.Context, options string) error { + ret := _m.Called(ctx, options) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, options) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStorage_Initialize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Initialize' +type MockStorage_Initialize_Call struct { + *mock.Call +} + +// Initialize is a helper method to define mock.On call +// - ctx context.Context +// - options string +func (_e *MockStorage_Expecter) Initialize(ctx interface{}, options interface{}) *MockStorage_Initialize_Call { + return &MockStorage_Initialize_Call{Call: _e.mock.On("Initialize", ctx, options)} +} + +func (_c *MockStorage_Initialize_Call) Run(run func(ctx context.Context, options string)) *MockStorage_Initialize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockStorage_Initialize_Call) Return(_a0 error) *MockStorage_Initialize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStorage_Initialize_Call) RunAndReturn(run func(context.Context, string) error) *MockStorage_Initialize_Call { + _c.Call.Return(run) + return _c +} + +// QueryJobs provides a mock function with given fields: ctx, filterParams, sortParams, paginationParams +func (_m *MockStorage) QueryJobs(ctx context.Context, filterParams FilterParams, sortParams SortParams, paginationParams PaginationParams) (*model.PaginatedJobList, error) { + ret := _m.Called(ctx, filterParams, sortParams, paginationParams) + + var r0 *model.PaginatedJobList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, FilterParams, SortParams, PaginationParams) (*model.PaginatedJobList, error)); ok { + return rf(ctx, filterParams, sortParams, paginationParams) + } + if rf, ok := ret.Get(0).(func(context.Context, FilterParams, SortParams, PaginationParams) *model.PaginatedJobList); ok { + r0 = rf(ctx, filterParams, sortParams, paginationParams) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.PaginatedJobList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, FilterParams, SortParams, PaginationParams) error); ok { + r1 = rf(ctx, filterParams, sortParams, paginationParams) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_QueryJobs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryJobs' +type MockStorage_QueryJobs_Call struct { + *mock.Call +} + +// QueryJobs is a helper method to define mock.On call +// - ctx context.Context +// - filterParams FilterParams +// - sortParams SortParams +// - paginationParams PaginationParams +func (_e *MockStorage_Expecter) QueryJobs(ctx interface{}, filterParams interface{}, sortParams interface{}, paginationParams interface{}) *MockStorage_QueryJobs_Call { + return &MockStorage_QueryJobs_Call{Call: _e.mock.On("QueryJobs", ctx, filterParams, sortParams, paginationParams)} +} + +func (_c *MockStorage_QueryJobs_Call) Run(run func(ctx context.Context, filterParams FilterParams, sortParams SortParams, paginationParams PaginationParams)) *MockStorage_QueryJobs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(FilterParams), args[2].(SortParams), args[3].(PaginationParams)) + }) + return _c +} + +func (_c *MockStorage_QueryJobs_Call) Return(_a0 *model.PaginatedJobList, _a1 error) *MockStorage_QueryJobs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_QueryJobs_Call) RunAndReturn(run func(context.Context, FilterParams, SortParams, PaginationParams) (*model.PaginatedJobList, error)) *MockStorage_QueryJobs_Call { + _c.Call.Return(run) + return _c +} + +// QueryWorkflows provides a mock function with given fields: ctx, paginationParams +func (_m *MockStorage) QueryWorkflows(ctx context.Context, paginationParams PaginationParams) (*model.PaginatedWorkflowList, error) { + ret := _m.Called(ctx, paginationParams) + + var r0 *model.PaginatedWorkflowList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, PaginationParams) (*model.PaginatedWorkflowList, error)); ok { + return rf(ctx, paginationParams) + } + if rf, ok := ret.Get(0).(func(context.Context, PaginationParams) *model.PaginatedWorkflowList); ok { + r0 = rf(ctx, paginationParams) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.PaginatedWorkflowList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, PaginationParams) error); ok { + r1 = rf(ctx, paginationParams) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_QueryWorkflows_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryWorkflows' +type MockStorage_QueryWorkflows_Call struct { + *mock.Call +} + +// QueryWorkflows is a helper method to define mock.On call +// - ctx context.Context +// - paginationParams PaginationParams +func (_e *MockStorage_Expecter) QueryWorkflows(ctx interface{}, paginationParams interface{}) *MockStorage_QueryWorkflows_Call { + return &MockStorage_QueryWorkflows_Call{Call: _e.mock.On("QueryWorkflows", ctx, paginationParams)} +} + +func (_c *MockStorage_QueryWorkflows_Call) Run(run func(ctx context.Context, paginationParams PaginationParams)) *MockStorage_QueryWorkflows_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(PaginationParams)) + }) + return _c +} + +func (_c *MockStorage_QueryWorkflows_Call) Return(_a0 *model.PaginatedWorkflowList, _a1 error) *MockStorage_QueryWorkflows_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_QueryWorkflows_Call) RunAndReturn(run func(context.Context, PaginationParams) (*model.PaginatedWorkflowList, error)) *MockStorage_QueryWorkflows_Call { + _c.Call.Return(run) + return _c +} + +// Shutdown provides a mock function with given fields: +func (_m *MockStorage) Shutdown() { + _m.Called() +} + +// MockStorage_Shutdown_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Shutdown' +type MockStorage_Shutdown_Call struct { + *mock.Call +} + +// Shutdown is a helper method to define mock.On call +func (_e *MockStorage_Expecter) Shutdown() *MockStorage_Shutdown_Call { + return &MockStorage_Shutdown_Call{Call: _e.mock.On("Shutdown")} +} + +func (_c *MockStorage_Shutdown_Call) Run(run func()) *MockStorage_Shutdown_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockStorage_Shutdown_Call) Return() *MockStorage_Shutdown_Call { + _c.Call.Return() + return _c +} + +func (_c *MockStorage_Shutdown_Call) RunAndReturn(run func()) *MockStorage_Shutdown_Call { + _c.Call.Return(run) + return _c +} + +// UpdateJob provides a mock function with given fields: ctx, job, request +func (_m *MockStorage) UpdateJob(ctx context.Context, job *model.Job, request JobUpdate) (*model.Job, error) { + ret := _m.Called(ctx, job, request) + + var r0 *model.Job + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *model.Job, JobUpdate) (*model.Job, error)); ok { + return rf(ctx, job, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *model.Job, JobUpdate) *model.Job); ok { + r0 = rf(ctx, job, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Job) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *model.Job, JobUpdate) error); ok { + r1 = rf(ctx, job, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStorage_UpdateJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateJob' +type MockStorage_UpdateJob_Call struct { + *mock.Call +} + +// UpdateJob is a helper method to define mock.On call +// - ctx context.Context +// - job *model.Job +// - request JobUpdate +func (_e *MockStorage_Expecter) UpdateJob(ctx interface{}, job interface{}, request interface{}) *MockStorage_UpdateJob_Call { + return &MockStorage_UpdateJob_Call{Call: _e.mock.On("UpdateJob", ctx, job, request)} +} + +func (_c *MockStorage_UpdateJob_Call) Run(run func(ctx context.Context, job *model.Job, request JobUpdate)) *MockStorage_UpdateJob_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*model.Job), args[2].(JobUpdate)) + }) + return _c +} + +func (_c *MockStorage_UpdateJob_Call) Return(_a0 *model.Job, _a1 error) *MockStorage_UpdateJob_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStorage_UpdateJob_Call) RunAndReturn(run func(context.Context, *model.Job, JobUpdate) (*model.Job, error)) *MockStorage_UpdateJob_Call { + _c.Call.Return(run) + return _c +} + +// NewMockStorage creates a new instance of MockStorage. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockStorage(t interface { + mock.TestingT + Cleanup(func()) +}) *MockStorage { + mock := &MockStorage{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/shell.nix b/shell.nix index 51eb2638..daf07152 100644 --- a/shell.nix +++ b/shell.nix @@ -23,6 +23,7 @@ mkShell { go-swagger golangci-lint go-tools + go-mockery reuse gofumpt