Skip to content

Commit

Permalink
Make sure tx are working
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Chain committed Apr 22, 2016
1 parent 135f73d commit 7e93ab8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -67,4 +67,4 @@ sqlhooks will intercept Query and Exec functions and instead run your hooks, out
- [ ] `Hooks{}` should be an interface instead of a struct
- [ ] Exec and Query hooks should return `(func(), error)`
- [ ] Arguments should be pointers so queries can be modified
- [ ] Implement hooks on Tx
- [x] Implement hooks on Tx
24 changes: 24 additions & 0 deletions sqlhooks_test.go
Expand Up @@ -50,6 +50,8 @@ func TestHooks(t *testing.T) {
{"query", "SELECT|t|f1|", []interface{}{}},
{"stmt.query", "SELECT|t|f1|", nil},
{"stmt.exec", "INSERT|t|f1=?", []interface{}{"x"}},
{"tx.query", "SELECT|t|f1|", nil},
{"tx.exec", "INSERT|t|f1=?", []interface{}{"x"}},
}

for _, test := range tests {
Expand Down Expand Up @@ -105,6 +107,28 @@ func TestHooks(t *testing.T) {
t.Errorf("prepared exec: %v", err)
}
}
case "tx.query":
tx, err := db.Begin()
if err != nil {
t.Errorf("[%s] begin: %v", test.op, err)
}
if _, err := tx.Query(test.query, test.args...); err != nil {
t.Errorf("[%s] query: %v", test.op, err)
}
if err := tx.Commit(); err != nil {
t.Errorf("[%s] commit: %v", test.op, err)
}
case "tx.exec":
tx, err := db.Begin()
if err != nil {
t.Errorf("[%s] begin: %v", test.op, err)
}
if _, err := tx.Exec(test.query, test.args...); err != nil {
t.Errorf("[%s] exec: %v", test.op, err)
}
if err := tx.Commit(); err != nil {
t.Errorf("[%s] commit: %v", test.op, err)
}
}

if done == false {
Expand Down

0 comments on commit 7e93ab8

Please sign in to comment.