diff --git a/.golangci.yml b/.golangci.yml index b90103c..f8aa846 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,7 +44,10 @@ linters-settings: govet: check-shadowing: false gci: - local-prefixes: github.com/sv-tools/mongoifc + sections: + - standard + - default + - prefix(github.com/sv-tools/mongoifc) gocognit: min-complexity: 15 gocyclo: diff --git a/Makefile b/Makefile index 7036e1b..0b29271 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ go-install: @echo "$(OK_COLOR)==> Checking and installing dependencies using go install...$(NO_COLOR)" @go install github.com/golang/mock/mockgen@v1 @go install github.com/vektra/mockery/v2@v2 + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest run-test: @echo "$(OK_COLOR)==> Testing...$(NO_COLOR)" @@ -59,6 +60,9 @@ run-mockgen: @mockgen -destination=mocks/gomock/mocks.go -package mocks . ChangeStream,Client,Collection,Cursor,Database,IndexView,Session,SingleResult,SessionContext run-mockery: - @mockery --all --output mocks/mockery --disable-version-string --case underscore + @mockery --all --srcpkg github.com/sv-tools/mongoifc --output mocks/mockery --disable-version-string --case underscore -generate-mocks: run-mockgen run-mockery +clean-mocks: + @rm -rf mocks + +generate-mocks: clean-mocks run-mockgen run-mockery diff --git a/mocks/mockery/change_stream.go b/mocks/mockery/change_stream.go index de39726..158cd6f 100644 --- a/mocks/mockery/change_stream.go +++ b/mocks/mockery/change_stream.go @@ -8,8 +8,6 @@ import ( bson "go.mongodb.org/mongo-driver/bson" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // ChangeStream is an autogenerated mock type for the ChangeStream type @@ -133,8 +131,13 @@ func (_m *ChangeStream) TryNext(ctx context.Context) bool { return r0 } -// NewChangeStream creates a new instance of ChangeStream. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewChangeStream(t testing.TB) *ChangeStream { +type NewChangeStreamT interface { + mock.TestingT + Cleanup(func()) +} + +// NewChangeStream creates a new instance of ChangeStream. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewChangeStream(t NewChangeStreamT) *ChangeStream { mock := &ChangeStream{} mock.Mock.Test(t) diff --git a/mocks/mockery/client.go b/mocks/mockery/client.go index 05d84b7..a98ab06 100644 --- a/mocks/mockery/client.go +++ b/mocks/mockery/client.go @@ -13,8 +13,6 @@ import ( options "go.mongodb.org/mongo-driver/mongo/options" readpref "go.mongodb.org/mongo-driver/mongo/readpref" - - testing "testing" ) // Client is an autogenerated mock type for the Client type @@ -246,8 +244,13 @@ func (_m *Client) Watch(ctx context.Context, pipeline interface{}, opts ...*opti return r0, r1 } -// NewClient creates a new instance of Client. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewClient(t testing.TB) *Client { +type NewClientT interface { + mock.TestingT + Cleanup(func()) +} + +// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewClient(t NewClientT) *Client { mock := &Client{} mock.Mock.Test(t) diff --git a/mocks/mockery/collection.go b/mocks/mockery/collection.go index 07f7844..dc18eea 100644 --- a/mocks/mockery/collection.go +++ b/mocks/mockery/collection.go @@ -11,8 +11,6 @@ import ( mongoifc "github.com/sv-tools/mongoifc" options "go.mongodb.org/mongo-driver/mongo/options" - - testing "testing" ) // Collection is an autogenerated mock type for the Collection type @@ -647,8 +645,13 @@ func (_m *Collection) Watch(ctx context.Context, pipeline interface{}, opts ...* return r0, r1 } -// NewCollection creates a new instance of Collection. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewCollection(t testing.TB) *Collection { +type NewCollectionT interface { + mock.TestingT + Cleanup(func()) +} + +// NewCollection creates a new instance of Collection. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCollection(t NewCollectionT) *Collection { mock := &Collection{} mock.Mock.Test(t) diff --git a/mocks/mockery/cursor.go b/mocks/mockery/cursor.go index 7e9f9e7..7fba308 100644 --- a/mocks/mockery/cursor.go +++ b/mocks/mockery/cursor.go @@ -8,8 +8,6 @@ import ( bson "go.mongodb.org/mongo-driver/bson" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // Cursor is an autogenerated mock type for the Cursor type @@ -145,8 +143,13 @@ func (_m *Cursor) TryNext(ctx context.Context) bool { return r0 } -// NewCursor creates a new instance of Cursor. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewCursor(t testing.TB) *Cursor { +type NewCursorT interface { + mock.TestingT + Cleanup(func()) +} + +// NewCursor creates a new instance of Cursor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCursor(t NewCursorT) *Cursor { mock := &Cursor{} mock.Mock.Test(t) diff --git a/mocks/mockery/database.go b/mocks/mockery/database.go index 0f1edf6..10c1b99 100644 --- a/mocks/mockery/database.go +++ b/mocks/mockery/database.go @@ -16,8 +16,6 @@ import ( readpref "go.mongodb.org/mongo-driver/mongo/readpref" - testing "testing" - writeconcern "go.mongodb.org/mongo-driver/mongo/writeconcern" ) @@ -386,8 +384,13 @@ func (_m *Database) WriteConcern() *writeconcern.WriteConcern { return r0 } -// NewDatabase creates a new instance of Database. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewDatabase(t testing.TB) *Database { +type NewDatabaseT interface { + mock.TestingT + Cleanup(func()) +} + +// NewDatabase creates a new instance of Database. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewDatabase(t NewDatabaseT) *Database { mock := &Database{} mock.Mock.Test(t) diff --git a/mocks/mockery/index_view.go b/mocks/mockery/index_view.go index 1b853e1..ee30499 100644 --- a/mocks/mockery/index_view.go +++ b/mocks/mockery/index_view.go @@ -14,8 +14,6 @@ import ( mongoifc "github.com/sv-tools/mongoifc" options "go.mongodb.org/mongo-driver/mongo/options" - - testing "testing" ) // IndexView is an autogenerated mock type for the IndexView type @@ -201,8 +199,13 @@ func (_m *IndexView) ListSpecifications(ctx context.Context, opts ...*options.Li return r0, r1 } -// NewIndexView creates a new instance of IndexView. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewIndexView(t testing.TB) *IndexView { +type NewIndexViewT interface { + mock.TestingT + Cleanup(func()) +} + +// NewIndexView creates a new instance of IndexView. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewIndexView(t NewIndexViewT) *IndexView { mock := &IndexView{} mock.Mock.Test(t) diff --git a/mocks/mockery/session.go b/mocks/mockery/session.go index 24d1529..4dadaba 100644 --- a/mocks/mockery/session.go +++ b/mocks/mockery/session.go @@ -14,8 +14,6 @@ import ( options "go.mongodb.org/mongo-driver/mongo/options" primitive "go.mongodb.org/mongo-driver/bson/primitive" - - testing "testing" ) // Session is an autogenerated mock type for the Session type @@ -198,8 +196,13 @@ func (_m *Session) WithTransaction(ctx context.Context, fn func(mongoifc.Session return r0, r1 } -// NewSession creates a new instance of Session. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewSession(t testing.TB) *Session { +type NewSessionT interface { + mock.TestingT + Cleanup(func()) +} + +// NewSession creates a new instance of Session. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSession(t NewSessionT) *Session { mock := &Session{} mock.Mock.Test(t) diff --git a/mocks/mockery/session_context.go b/mocks/mockery/session_context.go index 64048fc..6af1a2b 100644 --- a/mocks/mockery/session_context.go +++ b/mocks/mockery/session_context.go @@ -15,8 +15,6 @@ import ( primitive "go.mongodb.org/mongo-driver/bson/primitive" - testing "testing" - time "time" ) @@ -267,8 +265,13 @@ func (_m *SessionContext) WithTransaction(ctx context.Context, fn func(mongoifc. return r0, r1 } -// NewSessionContext creates a new instance of SessionContext. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewSessionContext(t testing.TB) *SessionContext { +type NewSessionContextT interface { + mock.TestingT + Cleanup(func()) +} + +// NewSessionContext creates a new instance of SessionContext. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSessionContext(t NewSessionContextT) *SessionContext { mock := &SessionContext{} mock.Mock.Test(t) diff --git a/mocks/mockery/single_result.go b/mocks/mockery/single_result.go index 8b5b90b..eacda2d 100644 --- a/mocks/mockery/single_result.go +++ b/mocks/mockery/single_result.go @@ -5,8 +5,6 @@ package mocks import ( mock "github.com/stretchr/testify/mock" bson "go.mongodb.org/mongo-driver/bson" - - testing "testing" ) // SingleResult is an autogenerated mock type for the SingleResult type @@ -65,8 +63,13 @@ func (_m *SingleResult) Err() error { return r0 } -// NewSingleResult creates a new instance of SingleResult. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewSingleResult(t testing.TB) *SingleResult { +type NewSingleResultT interface { + mock.TestingT + Cleanup(func()) +} + +// NewSingleResult creates a new instance of SingleResult. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSingleResult(t NewSingleResultT) *SingleResult { mock := &SingleResult{} mock.Mock.Test(t)