Skip to content

Commit

Permalink
v0.3.1
Browse files Browse the repository at this point in the history
* Fixed issue setting Logger when starting a new transaction.
  • Loading branch information
doug-martin committed Mar 15, 2015
1 parent 3ecfc3f commit 041935c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.3.1

* Fixed issue setting Logger when starting a new transaction.

## v0.3.0

* Changed sql generation methods to use a common naming convention. `To(Sql|Insert|Update|Delete)`
Expand Down
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (me *Database) Begin() (*TxDatabase, error) {
if err != nil {
return nil, err
}
return &TxDatabase{Dialect: me.Dialect, Tx: tx}, nil
return &TxDatabase{Dialect: me.Dialect, Tx: tx, logger: me.logger}, nil
}

//used internally to create a new Adapter for a dataset
Expand Down
35 changes: 34 additions & 1 deletion database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package goqu

import (
"fmt"
"testing"

"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)

type testActionItem struct {
Expand Down Expand Up @@ -275,6 +276,38 @@ func (me *txDatabaseTest) TestLogger() {
})
}

func (me *txDatabaseTest) TestLogger_FromDb() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectBegin()
sqlmock.ExpectQuery(`SELECT \* FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1\n211 Test Addr,Test2"))

sqlmock.ExpectExec(`SELECT \* FROM "items" WHERE "id" = ?`).
WithArgs(1).
WillReturnResult(sqlmock.NewResult(0, 0))
sqlmock.ExpectCommit()

db := New("db-mock", mDb)
logger := new(dbTestMockLogger)
db.Logger(logger)
tx, err := db.Begin()
assert.NoError(t, err)

var items []testActionItem
assert.NoError(t, tx.ScanStructs(&items, `SELECT * FROM "items"`))
_, err = tx.Exec(`SELECT * FROM "items" WHERE "id" = ?`, 1)
assert.NoError(t, err)
tx.Commit()
assert.Equal(t, logger.Messages, []string{
"[goqu - transaction] QUERY [query:=`SELECT * FROM \"items\"`] ",
"[goqu - transaction] EXEC [query:=`SELECT * FROM \"items\" WHERE \"id\" = ?` args:=[1]] ",
"[goqu - transaction] COMMIT",
})
}

func (me *txDatabaseTest) TestCommit() {
t := me.T()
mDb, err := sqlmock.New()
Expand Down

0 comments on commit 041935c

Please sign in to comment.