diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d4c4858..6c327e0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -56,10 +56,10 @@ jobs: pull-requests: write services: redis: - image: go-redis-v9 + image: redis ports: - 6379:6379 - # Set health checks to wait until go-redis-v9 has started + # Set health checks to wait until redis has started options: >- --health-cmd "redis-cli ping" --health-interval 10s diff --git a/Makefile b/Makefile index 9bcb20e..be253c4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ -CVPKG=go list ./... | grep -v mocks | grep -v internal/ -GO_TEST=go test `$(CVPKG)` -race +GO_TEST=cd ./sh && sh ./go.test.sh GO_TEST_WITH_REAL_DB=$(GO_TEST) --tags=with_real_db -COVERAGE_FILE="coverage.out" + +DIR=$(PWD) +COVERAGE_FILE=`echo $(DIR)/coverage.out` test: $(GO_TEST) @@ -9,6 +10,7 @@ test: test.with_real_db: $(GO_TEST_WITH_REAL_DB) +# TODO see in https://gist.github.com/skarllot/13ebe8220822bc19494c8b076aabe9fc test.coverage: $(GO_TEST) -covermode=atomic -coverprofile=$(COVERAGE_FILE) @@ -25,12 +27,8 @@ generate: go generate ./... -go.update: go.tidy go.vendor - -go.prepare: go.vendor - -go.tidy: - ./sh/go.mod.tidy.sh +go.mod.tidy: + cd sh && sh ./go.mod.tidy.sh -go.vendor: - ./sh/go.mod.vendor.sh +go.mod.vendor: + cd sh && sh ./go.mod.vendor.sh diff --git a/README.md b/README.md index 76774a8..ef2f006 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Compatibility beyond that is not guaranteed. * [jmoiron/sqlx](drivers/sqlx/example_test.go) * [gorm](drivers/gorm/example_test.go) * [mongo-go-driver](drivers/mongo/example_test.go) -* [go-redis/redis](drivers/go-redis-v9/example_test.go) +* [go-redis/redis](drivers/go-redis-v8/example_test.go) * [pgx_v4](drivers/pgxv4/example_test.go) * [pgx_v5](drivers/pgxv5/example_test.go) diff --git a/context.go b/context.go index 623ce80..367ccac 100644 --- a/context.go +++ b/context.go @@ -1,4 +1,4 @@ -package go_transaction_manager +package trm import ( "context" diff --git a/drivers/go-redis-v8/context.go b/drivers/go-redis-v8/context.go index bb3b8ac..dc7cc96 100644 --- a/drivers/go-redis-v8/context.go +++ b/drivers/go-redis-v8/context.go @@ -12,7 +12,7 @@ import ( // DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey. var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager) -// CtxGetter gets go-redis-v9.Pipeliner from trm.СtxManager by casting trm.Transaction to go-redis-v9.UniversalClient. +// CtxGetter gets go-redis-v8.Pipeliner from trm.СtxManager by casting trm.Transaction to redis.UniversalClient. type CtxGetter struct { ctxManager trm.СtxManager } @@ -22,7 +22,7 @@ func NewCtxGetter(c trm.СtxManager) *CtxGetter { return &CtxGetter{ctxManager: c} } -// DefaultTrOrDB returns Cmdable from context.Context or DB(go-redis-v9.Cmdable) otherwise. +// DefaultTrOrDB returns Cmdable from context.Context or DB(go-redis-v8.Cmdable) otherwise. func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db redis.Cmdable) redis.Cmdable { if tr := c.ctxManager.Default(ctx); tr != nil { return c.convert(tr) @@ -31,7 +31,7 @@ func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db redis.Cmdable) redis.C return db } -// TrOrDB returns Cmdable from context.Context by trm.CtxKey or DB(go-redis-v9.Cmdable) otherwise. +// TrOrDB returns Cmdable from context.Context by trm.CtxKey or DB(go-redis-v8.Cmdable) otherwise. func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db redis.Cmdable) redis.Cmdable { if tr := c.ctxManager.ByKey(ctx, key); tr != nil { return c.convert(tr) diff --git a/drivers/go-redis-v8/example_test.go b/drivers/go-redis-v8/example_test.go index b07e62a..38be219 100644 --- a/drivers/go-redis-v8/example_test.go +++ b/drivers/go-redis-v8/example_test.go @@ -119,7 +119,7 @@ type user struct { } type userRecord struct { - Username string `go-redis-v9:"username"` + Username string `redis:"username"` } func (r userRecord) MarshalBinary() (data []byte, err error) { diff --git a/drivers/go-redis-v8/factory.go b/drivers/go-redis-v8/factory.go index bb4c463..426a43f 100644 --- a/drivers/go-redis-v8/factory.go +++ b/drivers/go-redis-v8/factory.go @@ -8,7 +8,7 @@ import ( trm "github.com/avito-tech/go-transaction-manager/v2" ) -// NewDefaultFactory creates default trm.Transaction(go-redis-v9.UniversalClient). +// NewDefaultFactory creates default trm.Transaction(redis.UniversalClient). func NewDefaultFactory(db redis.UniversalClient) trm.TrFactory { return func(ctx context.Context, trms trm.Settings) (context.Context, trm.Transaction, error) { s, _ := trms.(Settings) diff --git a/drivers/go-redis-v8/option.go b/drivers/go-redis-v8/option.go index c3e7a48..9ab72c6 100644 --- a/drivers/go-redis-v8/option.go +++ b/drivers/go-redis-v8/option.go @@ -29,7 +29,7 @@ func WithTxDecorator(in TxDecorator) Opt { } } -// WithRet sets link on []go-redis-v9.Cmder to get responses of commands in Transaction +// WithRet sets link on []redis.Cmder to get responses of commands in Transaction // WARNING: Responses don't clean automatically, use WithRet only with DoWithSettings of trm.Manager. func WithRet(in *[]redis.Cmder) Opt { return func(s *Settings) error { diff --git a/drivers/go-redis-v8/settings.go b/drivers/go-redis-v8/settings.go index 059fd86..23f1017 100644 --- a/drivers/go-redis-v8/settings.go +++ b/drivers/go-redis-v8/settings.go @@ -14,7 +14,7 @@ const ( // Opt is a type to configure Settings. type Opt func(*Settings) error -// Settings contains settings for go-redis-v9.Transaction. +// Settings contains settings for redis.Transaction. type Settings struct { trm.Settings isMulti *bool @@ -78,7 +78,7 @@ func (s Settings) EnrichBy(in trm.Settings) trm.Settings { return s } -// IsMulti - true uses go-redis-v9 MULTI cmd. +// IsMulti - true uses redis MULTI cmd. func (s Settings) IsMulti() bool { if s.isMulti == nil { return DefaultMulti @@ -135,12 +135,12 @@ func (s Settings) setTxDecorator(in ...TxDecorator) Settings { return s } -// Return returns []go-redis-v9.Cmder from Transaction. +// Return returns []redis.Cmder from Transaction. func (s Settings) Return() *[]redis.Cmder { return s.ret } -// SetReturn sets link to save []go-redis-v9.Cmder from Transaction. +// SetReturn sets link to save []redis.Cmder from Transaction. func (s Settings) SetReturn(in *[]redis.Cmder) Settings { return s.setReturn(in) } diff --git a/drivers/go-redis-v8/transaction.go b/drivers/go-redis-v8/transaction.go index ec00e4a..53a8cdd 100644 --- a/drivers/go-redis-v8/transaction.go +++ b/drivers/go-redis-v8/transaction.go @@ -1,4 +1,4 @@ -// Package go-redis-v9 is an implementation of trm.Transaction interface by Transaction for go-redis-v9.UniversalClient. +// Package go_redis_v8 is an implementation of trm.Transaction interface by Transaction for redis.UniversalClient. package go_redis_v8 import ( diff --git a/drivers/go-redis-v8/transaction_test.go b/drivers/go-redis-v8/transaction_test.go index 9d41504..512592f 100644 --- a/drivers/go-redis-v8/transaction_test.go +++ b/drivers/go-redis-v8/transaction_test.go @@ -82,7 +82,7 @@ func TestTransaction(t *testing.T) { ctx: context.Background(), }, wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.ErrorContains(t, err, "go-redis-v9: nil") && + return assert.ErrorContains(t, err, "redis: nil") && assert.ErrorIs(t, err, trm.ErrCommit) }, }, diff --git a/drivers/go-redis-v8/watcher_test.go b/drivers/go-redis-v8/watcher_test.go index 4b54b47..b5ae0a7 100644 --- a/drivers/go-redis-v8/watcher_test.go +++ b/drivers/go-redis-v8/watcher_test.go @@ -78,7 +78,7 @@ func Example_watch() { ) fmt.Println(err) - // Output: transaction: commit; go-redis-v9: transaction failed + // Output: transaction: commit; redis: transaction failed // } diff --git a/manager.go b/manager.go index 4bddb37..186917e 100644 --- a/manager.go +++ b/manager.go @@ -1,4 +1,4 @@ -package go_transaction_manager +package trm //go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock diff --git a/manager_test.go b/manager_test.go index 0ee175f..f383f3c 100644 --- a/manager_test.go +++ b/manager_test.go @@ -1,4 +1,4 @@ -package go_transaction_manager +package trm import ( "errors" diff --git a/mock/log.go b/mock/log.go index 7b2041d..daf08c1 100644 --- a/mock/log.go +++ b/mock/log.go @@ -14,7 +14,9 @@ type Log struct { // NewLog create mock Log. func NewLog() *Log { - return &Log{} + return &Log{ + Logged: nil, + } } func (l *Log) Warning(_ context.Context, msg string) { diff --git a/settings.go b/settings.go index 42eea60..ca92fa8 100644 --- a/settings.go +++ b/settings.go @@ -1,4 +1,4 @@ -package go_transaction_manager +package trm //go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock diff --git a/sh/go.test.sh b/sh/go.test.sh new file mode 100644 index 0000000..d14c676 --- /dev/null +++ b/sh/go.test.sh @@ -0,0 +1,25 @@ +cd ../ + +ROOT=$(pwd) + +golist() { + go list ./... | grep -v mock | grep -v internal/ +} + +gotest() { + cd $driver + + go test $(golist) -race "$@" + + cd $ROOT +} + +go test $(golist) -race "$@" + +for driver in ./drivers/*; do + if [ -d "$driver" ]; then + gotest "$@" & + fi +done + +wait diff --git a/transaction.go b/transaction.go index d1b3ac7..265be90 100644 --- a/transaction.go +++ b/transaction.go @@ -1,5 +1,5 @@ // Package trm contains of interfaces to programmatic transaction management. -package go_transaction_manager +package trm //go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock