From 18c1807f4f635aed1023c26ec5a333261c8223a4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 1 Sep 2022 01:19:49 +0200 Subject: [PATCH] Create mock for store and add unit tests for cron (#1146) * pass remote on init as argument like store * mock store * TestCreateBuild --- cmd/server/server.go | 2 +- server/cron/cron.go | 14 +- server/cron/cron_test.go | 46 +- server/store/mocks/store.go | 1559 +++++++++++++++++++++++++++++++++++ server/store/store.go | 3 + 5 files changed, 1606 insertions(+), 18 deletions(-) create mode 100644 server/store/mocks/store.go diff --git a/cmd/server/server.go b/cmd/server/server.go index fc15a9fb7..658c13b9e 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -187,7 +187,7 @@ func run(c *cli.Context) error { setupMetrics(&g, _store) g.Go(func() error { - return cron.Start(c.Context, _store) + return cron.Start(c.Context, _store, _remote) }) // start the server with tls enabled diff --git a/server/cron/cron.go b/server/cron/cron.go index 461d86e13..4e3679fb5 100644 --- a/server/cron/cron.go +++ b/server/cron/cron.go @@ -22,9 +22,9 @@ import ( "github.com/robfig/cron" "github.com/rs/zerolog/log" - "github.com/woodpecker-ci/woodpecker/server" "github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/pipeline" + "github.com/woodpecker-ci/woodpecker/server/remote" "github.com/woodpecker-ci/woodpecker/server/store" ) @@ -37,7 +37,7 @@ const ( ) // Start starts the cron scheduler loop -func Start(ctx context.Context, store store.Store) error { +func Start(ctx context.Context, store store.Store, remote remote.Remote) error { for { select { case <-ctx.Done(): @@ -54,7 +54,7 @@ func Start(ctx context.Context, store store.Store) error { } for _, cron := range crons { - if err := runCron(cron, store, now); err != nil { + if err := runCron(store, remote, cron, now); err != nil { log.Error().Err(err).Int64("cronID", cron.ID).Msg("run cron failed") } } @@ -77,7 +77,7 @@ func CalcNewNext(schedule string, now time.Time) (time.Time, error) { return c.Next(now), nil } -func runCron(cron *model.Cron, store store.Store, now time.Time) error { +func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time.Time) error { log.Trace().Msgf("Cron: run id[%d]", cron.ID) ctx := context.Background() @@ -96,7 +96,7 @@ func runCron(cron *model.Cron, store store.Store, now time.Time) error { return nil } - repo, newBuild, err := createBuild(ctx, cron, store) + repo, newBuild, err := createBuild(ctx, store, remote, cron) if err != nil { return err } @@ -105,9 +105,7 @@ func runCron(cron *model.Cron, store store.Store, now time.Time) error { return err } -func createBuild(ctx context.Context, cron *model.Cron, store store.Store) (*model.Repo, *model.Build, error) { - remote := server.Config.Services.Remote - +func createBuild(ctx context.Context, store store.Store, remote remote.Remote, cron *model.Cron) (*model.Repo, *model.Build, error) { repo, err := store.GetRepo(cron.RepoID) if err != nil { return nil, nil, err diff --git a/server/cron/cron_test.go b/server/cron/cron_test.go index cd78a855e..a441cd0b3 100644 --- a/server/cron/cron_test.go +++ b/server/cron/cron_test.go @@ -15,24 +15,52 @@ package cron import ( + "context" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" - "github.com/woodpecker-ci/woodpecker/server" - "github.com/woodpecker-ci/woodpecker/server/remote/mocks" + "github.com/woodpecker-ci/woodpecker/server/model" + mocks_remote "github.com/woodpecker-ci/woodpecker/server/remote/mocks" + mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks" ) func TestCreateBuild(t *testing.T) { - rOld := server.Config.Services.Remote - defer func() { - server.Config.Services.Remote = rOld - }() - server.Config.Services.Remote = mocks.NewRemote(t) + remote := mocks_remote.NewRemote(t) + store := mocks_store.NewStore(t) + ctx := context.Background() - // TODO: mockStore - // createBuild(context.TODO(), &model.Cron{}, mockStore) + creator := &model.User{ + ID: 1, + Login: "user1", + } + repo1 := &model.Repo{ + ID: 1, + Name: "repo1", + Owner: "owner1", + FullName: "repo1/owner1", + Branch: "default", + } + + // mock things + store.On("GetRepo", mock.Anything).Return(repo1, nil) + store.On("GetUser", mock.Anything).Return(creator, nil) + remote.On("BranchHead", mock.Anything, creator, repo1, "default").Return("sha1", nil) + + _, build, err := createBuild(ctx, store, remote, &model.Cron{ + Name: "test", + }) + assert.NoError(t, err) + assert.EqualValues(t, &model.Build{ + Event: "cron", + Commit: "sha1", + Branch: "default", + Ref: "refs/heads/default", + Message: "test", + Sender: "test", + }, build) } func TestCalcNewNext(t *testing.T) { diff --git a/server/store/mocks/store.go b/server/store/mocks/store.go new file mode 100644 index 000000000..8f4ba4f8b --- /dev/null +++ b/server/store/mocks/store.go @@ -0,0 +1,1559 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + io "io" + + mock "github.com/stretchr/testify/mock" + model "github.com/woodpecker-ci/woodpecker/server/model" +) + +// Store is an autogenerated mock type for the Store type +type Store struct { + mock.Mock +} + +// BuildConfigCreate provides a mock function with given fields: _a0 +func (_m *Store) BuildConfigCreate(_a0 *model.BuildConfig) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.BuildConfig) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Close provides a mock function with given fields: +func (_m *Store) Close() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ConfigCreate provides a mock function with given fields: _a0 +func (_m *Store) ConfigCreate(_a0 *model.Config) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Config) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ConfigFindApproved provides a mock function with given fields: _a0 +func (_m *Store) ConfigFindApproved(_a0 *model.Config) (bool, error) { + ret := _m.Called(_a0) + + var r0 bool + if rf, ok := ret.Get(0).(func(*model.Config) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Config) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConfigFindIdentical provides a mock function with given fields: repoID, hash +func (_m *Store) ConfigFindIdentical(repoID int64, hash string) (*model.Config, error) { + ret := _m.Called(repoID, hash) + + var r0 *model.Config + if rf, ok := ret.Get(0).(func(int64, string) *model.Config); ok { + r0 = rf(repoID, hash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Config) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64, string) error); ok { + r1 = rf(repoID, hash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConfigsForBuild provides a mock function with given fields: buildID +func (_m *Store) ConfigsForBuild(buildID int64) ([]*model.Config, error) { + ret := _m.Called(buildID) + + var r0 []*model.Config + if rf, ok := ret.Get(0).(func(int64) []*model.Config); ok { + r0 = rf(buildID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Config) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(buildID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateBuild provides a mock function with given fields: _a0, _a1 +func (_m *Store) CreateBuild(_a0 *model.Build, _a1 ...*model.Proc) error { + _va := make([]interface{}, len(_a1)) + for _i := range _a1 { + _va[_i] = _a1[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Build, ...*model.Proc) error); ok { + r0 = rf(_a0, _a1...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateRepo provides a mock function with given fields: _a0 +func (_m *Store) CreateRepo(_a0 *model.Repo) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateUser provides a mock function with given fields: _a0 +func (_m *Store) CreateUser(_a0 *model.User) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.User) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CronCreate provides a mock function with given fields: _a0 +func (_m *Store) CronCreate(_a0 *model.Cron) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Cron) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CronDelete provides a mock function with given fields: _a0, _a1 +func (_m *Store) CronDelete(_a0 *model.Repo, _a1 int64) error { + ret := _m.Called(_a0, _a1) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo, int64) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CronFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) CronFind(_a0 *model.Repo, _a1 int64) (*model.Cron, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Cron + if rf, ok := ret.Get(0).(func(*model.Repo, int64) *model.Cron); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Cron) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, int64) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CronGetLock provides a mock function with given fields: _a0, _a1 +func (_m *Store) CronGetLock(_a0 *model.Cron, _a1 int64) (bool, error) { + ret := _m.Called(_a0, _a1) + + var r0 bool + if rf, ok := ret.Get(0).(func(*model.Cron, int64) bool); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(bool) + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Cron, int64) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CronList provides a mock function with given fields: _a0 +func (_m *Store) CronList(_a0 *model.Repo) ([]*model.Cron, error) { + ret := _m.Called(_a0) + + var r0 []*model.Cron + if rf, ok := ret.Get(0).(func(*model.Repo) []*model.Cron); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Cron) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CronListNextExecute provides a mock function with given fields: _a0, _a1 +func (_m *Store) CronListNextExecute(_a0 int64, _a1 int64) ([]*model.Cron, error) { + ret := _m.Called(_a0, _a1) + + var r0 []*model.Cron + if rf, ok := ret.Get(0).(func(int64, int64) []*model.Cron); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Cron) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64, int64) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CronUpdate provides a mock function with given fields: _a0, _a1 +func (_m *Store) CronUpdate(_a0 *model.Repo, _a1 *model.Cron) error { + ret := _m.Called(_a0, _a1) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo, *model.Cron) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeleteRepo provides a mock function with given fields: _a0 +func (_m *Store) DeleteRepo(_a0 *model.Repo) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeleteUser provides a mock function with given fields: _a0 +func (_m *Store) DeleteUser(_a0 *model.User) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.User) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// FileCreate provides a mock function with given fields: _a0, _a1 +func (_m *Store) FileCreate(_a0 *model.File, _a1 io.Reader) error { + ret := _m.Called(_a0, _a1) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.File, io.Reader) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// FileFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) FileFind(_a0 *model.Proc, _a1 string) (*model.File, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.File + if rf, ok := ret.Get(0).(func(*model.Proc, string) *model.File); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.File) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Proc, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FileList provides a mock function with given fields: _a0 +func (_m *Store) FileList(_a0 *model.Build) ([]*model.File, error) { + ret := _m.Called(_a0) + + var r0 []*model.File + if rf, ok := ret.Get(0).(func(*model.Build) []*model.File); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.File) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Build) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FileRead provides a mock function with given fields: _a0, _a1 +func (_m *Store) FileRead(_a0 *model.Proc, _a1 string) (io.ReadCloser, error) { + ret := _m.Called(_a0, _a1) + + var r0 io.ReadCloser + if rf, ok := ret.Get(0).(func(*model.Proc, string) io.ReadCloser); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Proc, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetActiveBuildList provides a mock function with given fields: repo, page +func (_m *Store) GetActiveBuildList(repo *model.Repo, page int) ([]*model.Build, error) { + ret := _m.Called(repo, page) + + var r0 []*model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, int) []*model.Build); ok { + r0 = rf(repo, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, int) error); ok { + r1 = rf(repo, page) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuild provides a mock function with given fields: _a0 +func (_m *Store) GetBuild(_a0 int64) (*model.Build, error) { + ret := _m.Called(_a0) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(int64) *model.Build); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildCommit provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Store) GetBuildCommit(_a0 *model.Repo, _a1 string, _a2 string) (*model.Build, error) { + ret := _m.Called(_a0, _a1, _a2) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, string, string) *model.Build); ok { + r0 = rf(_a0, _a1, _a2) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string, string) error); ok { + r1 = rf(_a0, _a1, _a2) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildCount provides a mock function with given fields: +func (_m *Store) GetBuildCount() (int64, error) { + ret := _m.Called() + + var r0 int64 + if rf, ok := ret.Get(0).(func() int64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int64) + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildLast provides a mock function with given fields: _a0, _a1 +func (_m *Store) GetBuildLast(_a0 *model.Repo, _a1 string) (*model.Build, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, string) *model.Build); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildLastBefore provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Store) GetBuildLastBefore(_a0 *model.Repo, _a1 string, _a2 int64) (*model.Build, error) { + ret := _m.Called(_a0, _a1, _a2) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, string, int64) *model.Build); ok { + r0 = rf(_a0, _a1, _a2) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string, int64) error); ok { + r1 = rf(_a0, _a1, _a2) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildList provides a mock function with given fields: _a0, _a1 +func (_m *Store) GetBuildList(_a0 *model.Repo, _a1 int) ([]*model.Build, error) { + ret := _m.Called(_a0, _a1) + + var r0 []*model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, int) []*model.Build); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, int) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildNumber provides a mock function with given fields: _a0, _a1 +func (_m *Store) GetBuildNumber(_a0 *model.Repo, _a1 int64) (*model.Build, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, int64) *model.Build); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, int64) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildQueue provides a mock function with given fields: +func (_m *Store) GetBuildQueue() ([]*model.Feed, error) { + ret := _m.Called() + + var r0 []*model.Feed + if rf, ok := ret.Get(0).(func() []*model.Feed); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Feed) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetBuildRef provides a mock function with given fields: _a0, _a1 +func (_m *Store) GetBuildRef(_a0 *model.Repo, _a1 string) (*model.Build, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Build + if rf, ok := ret.Get(0).(func(*model.Repo, string) *model.Build); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Build) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetRepo provides a mock function with given fields: _a0 +func (_m *Store) GetRepo(_a0 int64) (*model.Repo, error) { + ret := _m.Called(_a0) + + var r0 *model.Repo + if rf, ok := ret.Get(0).(func(int64) *model.Repo); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Repo) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetRepoCount provides a mock function with given fields: +func (_m *Store) GetRepoCount() (int64, error) { + ret := _m.Called() + + var r0 int64 + if rf, ok := ret.Get(0).(func() int64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int64) + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetRepoName provides a mock function with given fields: _a0 +func (_m *Store) GetRepoName(_a0 string) (*model.Repo, error) { + ret := _m.Called(_a0) + + var r0 *model.Repo + if rf, ok := ret.Get(0).(func(string) *model.Repo); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Repo) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUser provides a mock function with given fields: _a0 +func (_m *Store) GetUser(_a0 int64) (*model.User, error) { + ret := _m.Called(_a0) + + var r0 *model.User + if rf, ok := ret.Get(0).(func(int64) *model.User); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.User) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserCount provides a mock function with given fields: +func (_m *Store) GetUserCount() (int64, error) { + ret := _m.Called() + + var r0 int64 + if rf, ok := ret.Get(0).(func() int64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int64) + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserList provides a mock function with given fields: +func (_m *Store) GetUserList() ([]*model.User, error) { + ret := _m.Called() + + var r0 []*model.User + if rf, ok := ret.Get(0).(func() []*model.User); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.User) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserLogin provides a mock function with given fields: _a0 +func (_m *Store) GetUserLogin(_a0 string) (*model.User, error) { + ret := _m.Called(_a0) + + var r0 *model.User + if rf, ok := ret.Get(0).(func(string) *model.User); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.User) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GlobalSecretFind provides a mock function with given fields: _a0 +func (_m *Store) GlobalSecretFind(_a0 string) (*model.Secret, error) { + ret := _m.Called(_a0) + + var r0 *model.Secret + if rf, ok := ret.Get(0).(func(string) *model.Secret); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GlobalSecretList provides a mock function with given fields: +func (_m *Store) GlobalSecretList() ([]*model.Secret, error) { + ret := _m.Called() + + var r0 []*model.Secret + if rf, ok := ret.Get(0).(func() []*model.Secret); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LogFind provides a mock function with given fields: _a0 +func (_m *Store) LogFind(_a0 *model.Proc) (io.ReadCloser, error) { + ret := _m.Called(_a0) + + var r0 io.ReadCloser + if rf, ok := ret.Get(0).(func(*model.Proc) io.ReadCloser); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Proc) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LogSave provides a mock function with given fields: _a0, _a1 +func (_m *Store) LogSave(_a0 *model.Proc, _a1 io.Reader) error { + ret := _m.Called(_a0, _a1) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Proc, io.Reader) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Migrate provides a mock function with given fields: +func (_m *Store) Migrate() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// OrgSecretFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) OrgSecretFind(_a0 string, _a1 string) (*model.Secret, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Secret + if rf, ok := ret.Get(0).(func(string, string) *model.Secret); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OrgSecretList provides a mock function with given fields: _a0 +func (_m *Store) OrgSecretList(_a0 string) ([]*model.Secret, error) { + ret := _m.Called(_a0) + + var r0 []*model.Secret + if rf, ok := ret.Get(0).(func(string) []*model.Secret); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PermDelete provides a mock function with given fields: perm +func (_m *Store) PermDelete(perm *model.Perm) error { + ret := _m.Called(perm) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Perm) error); ok { + r0 = rf(perm) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// PermFind provides a mock function with given fields: user, repo +func (_m *Store) PermFind(user *model.User, repo *model.Repo) (*model.Perm, error) { + ret := _m.Called(user, repo) + + var r0 *model.Perm + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo) *model.Perm); ok { + r0 = rf(user, repo) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Perm) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.User, *model.Repo) error); ok { + r1 = rf(user, repo) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PermFlush provides a mock function with given fields: user, before +func (_m *Store) PermFlush(user *model.User, before int64) error { + ret := _m.Called(user, before) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.User, int64) error); ok { + r0 = rf(user, before) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// PermUpsert provides a mock function with given fields: perm +func (_m *Store) PermUpsert(perm *model.Perm) error { + ret := _m.Called(perm) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Perm) error); ok { + r0 = rf(perm) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Ping provides a mock function with given fields: +func (_m *Store) Ping() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ProcChild provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Store) ProcChild(_a0 *model.Build, _a1 int, _a2 string) (*model.Proc, error) { + ret := _m.Called(_a0, _a1, _a2) + + var r0 *model.Proc + if rf, ok := ret.Get(0).(func(*model.Build, int, string) *model.Proc); ok { + r0 = rf(_a0, _a1, _a2) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Proc) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Build, int, string) error); ok { + r1 = rf(_a0, _a1, _a2) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcClear provides a mock function with given fields: _a0 +func (_m *Store) ProcClear(_a0 *model.Build) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Build) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ProcCreate provides a mock function with given fields: _a0 +func (_m *Store) ProcCreate(_a0 []*model.Proc) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func([]*model.Proc) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ProcFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) ProcFind(_a0 *model.Build, _a1 int) (*model.Proc, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Proc + if rf, ok := ret.Get(0).(func(*model.Build, int) *model.Proc); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Proc) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Build, int) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcList provides a mock function with given fields: _a0 +func (_m *Store) ProcList(_a0 *model.Build) ([]*model.Proc, error) { + ret := _m.Called(_a0) + + var r0 []*model.Proc + if rf, ok := ret.Get(0).(func(*model.Build) []*model.Proc); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Proc) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Build) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcLoad provides a mock function with given fields: _a0 +func (_m *Store) ProcLoad(_a0 int64) (*model.Proc, error) { + ret := _m.Called(_a0) + + var r0 *model.Proc + if rf, ok := ret.Get(0).(func(int64) *model.Proc); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Proc) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcUpdate provides a mock function with given fields: _a0 +func (_m *Store) ProcUpdate(_a0 *model.Proc) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Proc) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RegistryCreate provides a mock function with given fields: _a0 +func (_m *Store) RegistryCreate(_a0 *model.Registry) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Registry) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RegistryDelete provides a mock function with given fields: repo, addr +func (_m *Store) RegistryDelete(repo *model.Repo, addr string) error { + ret := _m.Called(repo, addr) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo, string) error); ok { + r0 = rf(repo, addr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RegistryFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) RegistryFind(_a0 *model.Repo, _a1 string) (*model.Registry, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Registry + if rf, ok := ret.Get(0).(func(*model.Repo, string) *model.Registry); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Registry) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// RegistryList provides a mock function with given fields: _a0 +func (_m *Store) RegistryList(_a0 *model.Repo) ([]*model.Registry, error) { + ret := _m.Called(_a0) + + var r0 []*model.Registry + if rf, ok := ret.Get(0).(func(*model.Repo) []*model.Registry); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Registry) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// RegistryUpdate provides a mock function with given fields: _a0 +func (_m *Store) RegistryUpdate(_a0 *model.Registry) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Registry) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RepoBatch provides a mock function with given fields: _a0 +func (_m *Store) RepoBatch(_a0 []*model.Repo) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func([]*model.Repo) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RepoList provides a mock function with given fields: user, owned +func (_m *Store) RepoList(user *model.User, owned bool) ([]*model.Repo, error) { + ret := _m.Called(user, owned) + + var r0 []*model.Repo + if rf, ok := ret.Get(0).(func(*model.User, bool) []*model.Repo); ok { + r0 = rf(user, owned) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Repo) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.User, bool) error); ok { + r1 = rf(user, owned) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// RepoListLatest provides a mock function with given fields: _a0 +func (_m *Store) RepoListLatest(_a0 *model.User) ([]*model.Feed, error) { + ret := _m.Called(_a0) + + var r0 []*model.Feed + if rf, ok := ret.Get(0).(func(*model.User) []*model.Feed); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Feed) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.User) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SecretCreate provides a mock function with given fields: _a0 +func (_m *Store) SecretCreate(_a0 *model.Secret) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Secret) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SecretDelete provides a mock function with given fields: _a0 +func (_m *Store) SecretDelete(_a0 *model.Secret) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Secret) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SecretFind provides a mock function with given fields: _a0, _a1 +func (_m *Store) SecretFind(_a0 *model.Repo, _a1 string) (*model.Secret, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.Secret + if rf, ok := ret.Get(0).(func(*model.Repo, string) *model.Secret); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, string) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SecretList provides a mock function with given fields: _a0, _a1 +func (_m *Store) SecretList(_a0 *model.Repo, _a1 bool) ([]*model.Secret, error) { + ret := _m.Called(_a0, _a1) + + var r0 []*model.Secret + if rf, ok := ret.Get(0).(func(*model.Repo, bool) []*model.Secret); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Secret) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Repo, bool) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SecretUpdate provides a mock function with given fields: _a0 +func (_m *Store) SecretUpdate(_a0 *model.Secret) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Secret) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ServerConfigGet provides a mock function with given fields: _a0 +func (_m *Store) ServerConfigGet(_a0 string) (string, error) { + ret := _m.Called(_a0) + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(string) + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ServerConfigSet provides a mock function with given fields: _a0, _a1 +func (_m *Store) ServerConfigSet(_a0 string, _a1 string) error { + ret := _m.Called(_a0, _a1) + + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// TaskDelete provides a mock function with given fields: _a0 +func (_m *Store) TaskDelete(_a0 string) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// TaskInsert provides a mock function with given fields: _a0 +func (_m *Store) TaskInsert(_a0 *model.Task) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Task) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// TaskList provides a mock function with given fields: +func (_m *Store) TaskList() ([]*model.Task, error) { + ret := _m.Called() + + var r0 []*model.Task + if rf, ok := ret.Get(0).(func() []*model.Task); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Task) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateBuild provides a mock function with given fields: _a0 +func (_m *Store) UpdateBuild(_a0 *model.Build) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Build) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateRepo provides a mock function with given fields: _a0 +func (_m *Store) UpdateRepo(_a0 *model.Repo) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateUser provides a mock function with given fields: _a0 +func (_m *Store) UpdateUser(_a0 *model.User) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*model.User) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UserFeed provides a mock function with given fields: _a0 +func (_m *Store) UserFeed(_a0 *model.User) ([]*model.Feed, error) { + ret := _m.Called(_a0) + + var r0 []*model.Feed + if rf, ok := ret.Get(0).(func(*model.User) []*model.Feed); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Feed) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.User) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewStore interface { + mock.TestingT + Cleanup(func()) +} + +// NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewStore(t mockConstructorTestingTNewStore) *Store { + mock := &Store{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/server/store/store.go b/server/store/store.go index c27be443b..b2a666f3d 100644 --- a/server/store/store.go +++ b/server/store/store.go @@ -14,6 +14,9 @@ package store +//go:generate go install github.com/vektra/mockery/v2@latest +//go:generate mockery --name Store --output mocks --case underscore + import ( "io"