Skip to content

Commit

Permalink
1. Fixed redis naming
Browse files Browse the repository at this point in the history
2. Run tests for all submodules
  • Loading branch information
iasergunin committed Dec 3, 2023
1 parent d55cb25 commit 7dda220
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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)

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)

Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package go_transaction_manager
package trm

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions drivers/go-redis-v8/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions drivers/go-redis-v8/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/transaction.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
Expand Down
2 changes: 1 addition & 1 deletion drivers/go-redis-v8/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Example_watch() {
)
fmt.Println(err)

// Output: transaction: commit; go-redis-v9: transaction failed
// Output: transaction: commit; redis: transaction failed
// <nil>
}

Expand Down
2 changes: 1 addition & 1 deletion manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package go_transaction_manager
package trm

//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock

Expand Down
2 changes: 1 addition & 1 deletion manager_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package go_transaction_manager
package trm

import (
"errors"
Expand Down
4 changes: 3 additions & 1 deletion mock/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion settings.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package go_transaction_manager
package trm

//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock

Expand Down
25 changes: 25 additions & 0 deletions sh/go.test.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion transaction.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 7dda220

Please sign in to comment.