From 33fa76baefa294f575511a23253f3f4d0ac20f29 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Fri, 26 Mar 2021 23:55:32 +0100 Subject: [PATCH] add mock package --- go.sum | 1 + mocks/internal/action/GTSAction.go | 32 ++ mocks/internal/cache/Cache.go | 47 +++ mocks/internal/config/KeyedFlags.go | 66 ++++ mocks/internal/db/DB.go | 350 ++++++++++++++++++++++ mocks/internal/distributor/Distributor.go | 70 +++++ mocks/internal/gotosocial/Gotosocial.go | 28 ++ mocks/internal/media/API.go | 10 + mocks/internal/module/ClientAPIModule.go | 28 ++ mocks/internal/oauth/Server.go | 90 ++++++ mocks/internal/router/Router.go | 44 +++ 11 files changed, 766 insertions(+) create mode 100644 mocks/internal/action/GTSAction.go create mode 100644 mocks/internal/cache/Cache.go create mode 100644 mocks/internal/config/KeyedFlags.go create mode 100644 mocks/internal/db/DB.go create mode 100644 mocks/internal/distributor/Distributor.go create mode 100644 mocks/internal/gotosocial/Gotosocial.go create mode 100644 mocks/internal/media/API.go create mode 100644 mocks/internal/module/ClientAPIModule.go create mode 100644 mocks/internal/oauth/Server.go create mode 100644 mocks/internal/router/Router.go diff --git a/go.sum b/go.sum index d10e242ad..a5f9eec25 100644 --- a/go.sum +++ b/go.sum @@ -177,6 +177,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/mocks/internal/action/GTSAction.go b/mocks/internal/action/GTSAction.go new file mode 100644 index 000000000..c2eb07617 --- /dev/null +++ b/mocks/internal/action/GTSAction.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + config "github.com/gotosocial/gotosocial/internal/config" + + logrus "github.com/sirupsen/logrus" + + mock "github.com/stretchr/testify/mock" +) + +// GTSAction is an autogenerated mock type for the GTSAction type +type GTSAction struct { + mock.Mock +} + +// Execute provides a mock function with given fields: _a0, _a1, _a2 +func (_m *GTSAction) Execute(_a0 context.Context, _a1 *config.Config, _a2 *logrus.Logger) error { + ret := _m.Called(_a0, _a1, _a2) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *config.Config, *logrus.Logger) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/mocks/internal/cache/Cache.go b/mocks/internal/cache/Cache.go new file mode 100644 index 000000000..ddec2ded9 --- /dev/null +++ b/mocks/internal/cache/Cache.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Cache is an autogenerated mock type for the Cache type +type Cache struct { + mock.Mock +} + +// Fetch provides a mock function with given fields: k +func (_m *Cache) Fetch(k string) (interface{}, error) { + ret := _m.Called(k) + + var r0 interface{} + if rf, ok := ret.Get(0).(func(string) interface{}); ok { + r0 = rf(k) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(k) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store provides a mock function with given fields: k, v +func (_m *Cache) Store(k string, v interface{}) error { + ret := _m.Called(k, v) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}) error); ok { + r0 = rf(k, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/mocks/internal/config/KeyedFlags.go b/mocks/internal/config/KeyedFlags.go new file mode 100644 index 000000000..a6022b0f9 --- /dev/null +++ b/mocks/internal/config/KeyedFlags.go @@ -0,0 +1,66 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// KeyedFlags is an autogenerated mock type for the KeyedFlags type +type KeyedFlags struct { + mock.Mock +} + +// Bool provides a mock function with given fields: k +func (_m *KeyedFlags) Bool(k string) bool { + ret := _m.Called(k) + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(k) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// Int provides a mock function with given fields: k +func (_m *KeyedFlags) Int(k string) int { + ret := _m.Called(k) + + var r0 int + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(k) + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// IsSet provides a mock function with given fields: k +func (_m *KeyedFlags) IsSet(k string) bool { + ret := _m.Called(k) + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(k) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// String provides a mock function with given fields: k +func (_m *KeyedFlags) String(k string) string { + ret := _m.Called(k) + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(k) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} diff --git a/mocks/internal/db/DB.go b/mocks/internal/db/DB.go new file mode 100644 index 000000000..5b91b227c --- /dev/null +++ b/mocks/internal/db/DB.go @@ -0,0 +1,350 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mastotypes "github.com/gotosocial/gotosocial/pkg/mastotypes" + + mock "github.com/stretchr/testify/mock" + + model "github.com/gotosocial/gotosocial/internal/db/model" + + net "net" + + pub "github.com/go-fed/activity/pub" +) + +// DB is an autogenerated mock type for the DB type +type DB struct { + mock.Mock +} + +// AccountToMastoSensitive provides a mock function with given fields: account +func (_m *DB) AccountToMastoSensitive(account *model.Account) (*mastotypes.Account, error) { + ret := _m.Called(account) + + var r0 *mastotypes.Account + if rf, ok := ret.Get(0).(func(*model.Account) *mastotypes.Account); ok { + r0 = rf(account) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*mastotypes.Account) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*model.Account) error); ok { + r1 = rf(account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateTable provides a mock function with given fields: i +func (_m *DB) CreateTable(i interface{}) error { + ret := _m.Called(i) + + var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { + r0 = rf(i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeleteByID provides a mock function with given fields: id, i +func (_m *DB) DeleteByID(id string, i interface{}) error { + ret := _m.Called(id, i) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}) error); ok { + r0 = rf(id, i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeleteWhere provides a mock function with given fields: key, value, i +func (_m *DB) DeleteWhere(key string, value interface{}, i interface{}) error { + ret := _m.Called(key, value, i) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}, interface{}) error); ok { + r0 = rf(key, value, i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DropTable provides a mock function with given fields: i +func (_m *DB) DropTable(i interface{}) error { + ret := _m.Called(i) + + var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { + r0 = rf(i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Federation provides a mock function with given fields: +func (_m *DB) Federation() pub.Database { + ret := _m.Called() + + var r0 pub.Database + if rf, ok := ret.Get(0).(func() pub.Database); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pub.Database) + } + } + + return r0 +} + +// GetAccountByUserID provides a mock function with given fields: userID, account +func (_m *DB) GetAccountByUserID(userID string, account *model.Account) error { + ret := _m.Called(userID, account) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *model.Account) error); ok { + r0 = rf(userID, account) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetAll provides a mock function with given fields: i +func (_m *DB) GetAll(i interface{}) error { + ret := _m.Called(i) + + var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { + r0 = rf(i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetByID provides a mock function with given fields: id, i +func (_m *DB) GetByID(id string, i interface{}) error { + ret := _m.Called(id, i) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}) error); ok { + r0 = rf(id, i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetFollowersByAccountID provides a mock function with given fields: accountID, followers +func (_m *DB) GetFollowersByAccountID(accountID string, followers *[]model.Follow) error { + ret := _m.Called(accountID, followers) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *[]model.Follow) error); ok { + r0 = rf(accountID, followers) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetFollowingByAccountID provides a mock function with given fields: accountID, following +func (_m *DB) GetFollowingByAccountID(accountID string, following *[]model.Follow) error { + ret := _m.Called(accountID, following) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *[]model.Follow) error); ok { + r0 = rf(accountID, following) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetLastStatusForAccountID provides a mock function with given fields: accountID, status +func (_m *DB) GetLastStatusForAccountID(accountID string, status *model.Status) error { + ret := _m.Called(accountID, status) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *model.Status) error); ok { + r0 = rf(accountID, status) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetStatusesByAccountID provides a mock function with given fields: accountID, statuses +func (_m *DB) GetStatusesByAccountID(accountID string, statuses *[]model.Status) error { + ret := _m.Called(accountID, statuses) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *[]model.Status) error); ok { + r0 = rf(accountID, statuses) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetStatusesByTimeDescending provides a mock function with given fields: accountID, statuses, limit +func (_m *DB) GetStatusesByTimeDescending(accountID string, statuses *[]model.Status, limit int) error { + ret := _m.Called(accountID, statuses, limit) + + var r0 error + if rf, ok := ret.Get(0).(func(string, *[]model.Status, int) error); ok { + r0 = rf(accountID, statuses, limit) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetWhere provides a mock function with given fields: key, value, i +func (_m *DB) GetWhere(key string, value interface{}, i interface{}) error { + ret := _m.Called(key, value, i) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}, interface{}) error); ok { + r0 = rf(key, value, i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// IsEmailAvailable provides a mock function with given fields: email +func (_m *DB) IsEmailAvailable(email string) error { + ret := _m.Called(email) + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(email) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// IsHealthy provides a mock function with given fields: ctx +func (_m *DB) IsHealthy(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 +} + +// IsUsernameAvailable provides a mock function with given fields: username +func (_m *DB) IsUsernameAvailable(username string) error { + ret := _m.Called(username) + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(username) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewSignup provides a mock function with given fields: username, reason, requireApproval, email, password, signUpIP, locale +func (_m *DB) NewSignup(username string, reason string, requireApproval bool, email string, password string, signUpIP net.IP, locale string) (*model.User, error) { + ret := _m.Called(username, reason, requireApproval, email, password, signUpIP, locale) + + var r0 *model.User + if rf, ok := ret.Get(0).(func(string, string, bool, string, string, net.IP, string) *model.User); ok { + r0 = rf(username, reason, requireApproval, email, password, signUpIP, locale) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.User) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, string, bool, string, string, net.IP, string) error); ok { + r1 = rf(username, reason, requireApproval, email, password, signUpIP, locale) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Put provides a mock function with given fields: i +func (_m *DB) Put(i interface{}) error { + ret := _m.Called(i) + + var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { + r0 = rf(i) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Stop provides a mock function with given fields: ctx +func (_m *DB) Stop(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 +} + +// UpdateByID provides a mock function with given fields: id, i +func (_m *DB) UpdateByID(id string, i interface{}) error { + ret := _m.Called(id, i) + + var r0 error + if rf, ok := ret.Get(0).(func(string, interface{}) error); ok { + r0 = rf(id, i) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/mocks/internal/distributor/Distributor.go b/mocks/internal/distributor/Distributor.go new file mode 100644 index 000000000..0dda09357 --- /dev/null +++ b/mocks/internal/distributor/Distributor.go @@ -0,0 +1,70 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Distributor is an autogenerated mock type for the Distributor type +type Distributor struct { + mock.Mock +} + +// ClientAPIIn provides a mock function with given fields: +func (_m *Distributor) ClientAPIIn() chan interface{} { + ret := _m.Called() + + var r0 chan interface{} + if rf, ok := ret.Get(0).(func() chan interface{}); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(chan interface{}) + } + } + + return r0 +} + +// ClientAPIOut provides a mock function with given fields: +func (_m *Distributor) ClientAPIOut() chan interface{} { + ret := _m.Called() + + var r0 chan interface{} + if rf, ok := ret.Get(0).(func() chan interface{}); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(chan interface{}) + } + } + + return r0 +} + +// Start provides a mock function with given fields: +func (_m *Distributor) Start() 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 +} + +// Stop provides a mock function with given fields: +func (_m *Distributor) Stop() 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 +} diff --git a/mocks/internal/gotosocial/Gotosocial.go b/mocks/internal/gotosocial/Gotosocial.go new file mode 100644 index 000000000..295837fe9 --- /dev/null +++ b/mocks/internal/gotosocial/Gotosocial.go @@ -0,0 +1,28 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// Gotosocial is an autogenerated mock type for the Gotosocial type +type Gotosocial struct { + mock.Mock +} + +// Start provides a mock function with given fields: _a0 +func (_m *Gotosocial) Start(_a0 context.Context) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/mocks/internal/media/API.go b/mocks/internal/media/API.go new file mode 100644 index 000000000..b892669e7 --- /dev/null +++ b/mocks/internal/media/API.go @@ -0,0 +1,10 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// API is an autogenerated mock type for the API type +type API struct { + mock.Mock +} diff --git a/mocks/internal/module/ClientAPIModule.go b/mocks/internal/module/ClientAPIModule.go new file mode 100644 index 000000000..ea7c1932e --- /dev/null +++ b/mocks/internal/module/ClientAPIModule.go @@ -0,0 +1,28 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + router "github.com/gotosocial/gotosocial/internal/router" +) + +// ClientAPIModule is an autogenerated mock type for the ClientAPIModule type +type ClientAPIModule struct { + mock.Mock +} + +// Route provides a mock function with given fields: s +func (_m *ClientAPIModule) Route(s router.Router) error { + ret := _m.Called(s) + + var r0 error + if rf, ok := ret.Get(0).(func(router.Router) error); ok { + r0 = rf(s) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/mocks/internal/oauth/Server.go b/mocks/internal/oauth/Server.go new file mode 100644 index 000000000..21ae2f7d4 --- /dev/null +++ b/mocks/internal/oauth/Server.go @@ -0,0 +1,90 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + http "net/http" + + mock "github.com/stretchr/testify/mock" + + oauth2 "github.com/gotosocial/oauth2/v4" +) + +// Server is an autogenerated mock type for the Server type +type Server struct { + mock.Mock +} + +// GenerateUserAccessToken provides a mock function with given fields: ti, clientSecret, userID +func (_m *Server) GenerateUserAccessToken(ti oauth2.TokenInfo, clientSecret string, userID string) (oauth2.TokenInfo, error) { + ret := _m.Called(ti, clientSecret, userID) + + var r0 oauth2.TokenInfo + if rf, ok := ret.Get(0).(func(oauth2.TokenInfo, string, string) oauth2.TokenInfo); ok { + r0 = rf(ti, clientSecret, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(oauth2.TokenInfo) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(oauth2.TokenInfo, string, string) error); ok { + r1 = rf(ti, clientSecret, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HandleAuthorizeRequest provides a mock function with given fields: w, r +func (_m *Server) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error { + ret := _m.Called(w, r) + + var r0 error + if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok { + r0 = rf(w, r) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// HandleTokenRequest provides a mock function with given fields: w, r +func (_m *Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error { + ret := _m.Called(w, r) + + var r0 error + if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok { + r0 = rf(w, r) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ValidationBearerToken provides a mock function with given fields: r +func (_m *Server) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error) { + ret := _m.Called(r) + + var r0 oauth2.TokenInfo + if rf, ok := ret.Get(0).(func(*http.Request) oauth2.TokenInfo); ok { + r0 = rf(r) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(oauth2.TokenInfo) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*http.Request) error); ok { + r1 = rf(r) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} diff --git a/mocks/internal/router/Router.go b/mocks/internal/router/Router.go new file mode 100644 index 000000000..c94b8f2a3 --- /dev/null +++ b/mocks/internal/router/Router.go @@ -0,0 +1,44 @@ +// Code generated by mockery v2.7.4. DO NOT EDIT. + +package mocks + +import ( + context "context" + + gin "github.com/gin-gonic/gin" + mock "github.com/stretchr/testify/mock" +) + +// Router is an autogenerated mock type for the Router type +type Router struct { + mock.Mock +} + +// AttachHandler provides a mock function with given fields: method, path, f +func (_m *Router) AttachHandler(method string, path string, f gin.HandlerFunc) { + _m.Called(method, path, f) +} + +// AttachMiddleware provides a mock function with given fields: handler +func (_m *Router) AttachMiddleware(handler gin.HandlerFunc) { + _m.Called(handler) +} + +// Start provides a mock function with given fields: +func (_m *Router) Start() { + _m.Called() +} + +// Stop provides a mock function with given fields: ctx +func (_m *Router) Stop(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 +}