Skip to content

Commit

Permalink
Remove unused methods of DB/Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
arsham committed Aug 16, 2020
1 parent e5a0793 commit 73b50ca
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 60 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@



<a name="v0.4.1"></a>
## [v0.4.1] - 2020-08-16

### Remove
- Remove unused methods of DB/Pool


<a name="v0.4.0"></a>
## [v0.4.0] - 2020-08-16

Expand Down Expand Up @@ -51,7 +58,8 @@



[Unreleased]: https://github.com/arsham/dbtools/compare/v0.4.0...HEAD
[Unreleased]: https://github.com/arsham/dbtools/compare/v0.4.1...HEAD
[v0.4.1]: https://github.com/arsham/dbtools/compare/v0.4.0...v0.4.1
[v0.4.0]: https://github.com/arsham/dbtools/compare/v0.3.2...v0.4.0
[v0.3.2]: https://github.com/arsham/dbtools/compare/v0.3.1...v0.3.2
[v0.3.1]: https://github.com/arsham/dbtools/compare/v0.3.0...v0.3.1
Expand Down
6 changes: 0 additions & 6 deletions contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
// DB is the contract for beginning a transaction with a *sql.DB object.
//go:generate mockery -name DB -filename db_mock.go
type DB interface {
Begin() (Tx, error)
BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
}

Expand All @@ -29,7 +28,6 @@ type DB interface {
//go:generate mockery -name Pool -filename pool_mock.go
type Pool interface {
Begin(ctx context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
}

//nolint:unused // only used for mocking.
Expand Down Expand Up @@ -86,10 +84,6 @@ type dbWrapper struct {
db *sql.DB
}

func (d *dbWrapper) Begin() (Tx, error) {
return d.db.Begin()
}

func (d *dbWrapper) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) {
return d.db.BeginTx(ctx, opts)
}
3 changes: 0 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func NewTransaction(conn interface{}, conf ...ConfigFunc) (*Transaction, error)
for _, fn := range conf {
fn(t)
}
if t.db == nil && t.pool == nil {
return nil, ErrEmptyDatabase
}
if t.retries < 1 {
t.retries = 1
}
Expand Down
9 changes: 5 additions & 4 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestNewTransaction(t *testing.T) {
"pool": {&mocks.Pool{}, nil, nil},
"sql.DB": {db, nil, nil},
"low attempts": {db, []dbtools.ConfigFunc{dbtools.RetryCount(-1)}, nil},
"delay method": {db, []dbtools.ConfigFunc{dbtools.DelayMethod(retry.IncrementalDelay)}, nil},
}
for name, tc := range tcs {
tc := tc
Expand All @@ -60,7 +61,7 @@ func TestTransaction(t *testing.T) {

func testTransactionPGX(t *testing.T) {
t.Run("NilDatabase", testTransactionPGXNilDatabase)
t.Run("BeingError", testTransactionPGXBeingError)
t.Run("BeginError", testTransactionPGXBeginError)
t.Run("CancelledContext", testTransactionPGXCancelledContext)
t.Run("Panic", testTransactionPGXPanic)
t.Run("AnError", testTransactionPGXAnError)
Expand Down Expand Up @@ -96,7 +97,7 @@ func testTransactionPGXNilDatabase(t *testing.T) {
assertInError(t, err, dbtools.ErrEmptyDatabase)
}

func testTransactionPGXBeingError(t *testing.T) {
func testTransactionPGXBeginError(t *testing.T) {
t.Parallel()
db := &mocks.Pool{}
defer db.AssertExpectations(t)
Expand Down Expand Up @@ -451,7 +452,7 @@ func testTransactionPGXRealDatabase(t *testing.T) {

func testTransactionDB(t *testing.T) {
t.Run("NilDatabase", testTransactionDBNilDatabase)
t.Run("BeingError", testTransactionDBBeingError)
t.Run("BeginError", testTransactionDBBeginError)
t.Run("CancelledContext", testTransactionDBCancelledContext)
t.Run("Panic", testTransactionDBPanic)
t.Run("AnError", testTransactionDBAnError)
Expand Down Expand Up @@ -487,7 +488,7 @@ func testTransactionDBNilDatabase(t *testing.T) {
assertInError(t, err, dbtools.ErrEmptyDatabase)
}

func testTransactionDBBeingError(t *testing.T) {
func testTransactionDBBeginError(t *testing.T) {
t.Parallel()
db := &mocks.DB{}
defer db.AssertExpectations(t)
Expand Down
23 changes: 0 additions & 23 deletions mocks/db_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions mocks/pool_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73b50ca

Please sign in to comment.