Skip to content

Commit

Permalink
fix test in Go 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Mar 2, 2018
1 parent 97bab0d commit f9fce2d
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions proxy_go110_test.go
Expand Up @@ -411,8 +411,8 @@ func TestFakeDB(t *testing.T) {
opt: &fakeConnOption{
Name: "queryAll",
},
hooksLog: "[PreOpen]\n" +
"[Open]\n[PostOpen]\n[PreQuery]\n[Query]\n[PostQuery]\n",
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreQuery]\n[Query]\n[PostQuery]\n",
f: func(db *sql.DB) error {
_, err := db.Query("SELECT * FROM test WHERE id = ?", 123456789)
return err
Expand Down Expand Up @@ -630,8 +630,10 @@ func TestFakeDB(t *testing.T) {
Name: "execAll-ctx",
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n" +
"[Open]\n[PostOpen]\n[PreExec]\n[Exec]\n[PostExec]\n",
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreExec]\n[Exec]\n[PostExec]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
_, err := db.Exec("CREATE TABLE t1 (id INTEGER PRIMARY KEY)", 123456789)
return err
Expand All @@ -642,8 +644,10 @@ func TestFakeDB(t *testing.T) {
Name: "execAll-NamedValue-ctx",
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n" +
"[Open]\n[PostOpen]\n[PreExec]\n[Exec]\n[PostExec]\n",
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreExec]\n[Exec]\n[PostExec]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
_, err := db.Exec("CREATE TABLE t1 (id INTEGER PRIMARY KEY)", sql.Named("foo", 123456789))
return err
Expand All @@ -654,8 +658,8 @@ func TestFakeDB(t *testing.T) {
Name: "queryAll-ctx",
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n" +
"[Open]\n[PostOpen]\n[PreQuery]\n[Query]\n[PostQuery]\n",
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreQuery]\n[Query]\n[PostQuery]\n",
f: func(db *sql.DB) error {
_, err := db.Query("SELECT * FROM test WHERE id = ?", 123456789)
return err
Expand All @@ -667,7 +671,10 @@ func TestFakeDB(t *testing.T) {
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreExec]\n[Exec]\n[PostExec]\n",
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreExec]\n[Exec]\n[PostExec]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
stmt, err := db.Prepare("CREATE TABLE t1 (id INTEGER PRIMARY KEY)")
if err != nil {
Expand All @@ -684,6 +691,7 @@ func TestFakeDB(t *testing.T) {
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreQuery]\n[Query]\n[PostQuery]\n",
f: func(db *sql.DB) error {
stmt, err := db.Prepare("SELECT * FROM test WHERE id = ?")
Expand All @@ -709,7 +717,9 @@ func TestFakeDB(t *testing.T) {
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreBegin]\n[Begin]\n[PostBegin]\n" +
"[PreCommit]\n[Commit]\n[PostCommit]\n",
"[PreCommit]\n[Commit]\n[PostCommit]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
tx, err := db.Begin()
if err != nil {
Expand All @@ -725,7 +735,9 @@ func TestFakeDB(t *testing.T) {
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreBegin]\n[Begin]\n[PostBegin]\n" +
"[PreRollback]\n[Rollback]\n[PostRollback]\n",
"[PreRollback]\n[Rollback]\n[PostRollback]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
tx, err := db.Begin()
if err != nil {
Expand All @@ -741,7 +753,9 @@ func TestFakeDB(t *testing.T) {
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreBegin]\n[Begin]\n[PostBegin]\n" +
"[PreCommit]\n[Commit]\n[PostCommit]\n",
"[PreCommit]\n[Commit]\n[PostCommit]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -761,7 +775,9 @@ func TestFakeDB(t *testing.T) {
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n" +
"[PreBegin]\n[Begin]\n[PostBegin]\n" +
"[PreCommit]\n[Commit]\n[PostCommit]\n",
"[PreCommit]\n[Commit]\n[PostCommit]\n" +
"[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -779,7 +795,8 @@ func TestFakeDB(t *testing.T) {
Name: "context-with-no-hooks",
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n",
hooksLog: "[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
// remove the hooks from the current context.
// Exec will not be logged.
Expand All @@ -793,7 +810,8 @@ func TestFakeDB(t *testing.T) {
Name: "context-with-hooks",
ConnType: "fakeConnCtx",
},
hooksLog: "[PreOpen]\n[Open]\n[PostOpen]\n",
hooksLog: "[PreResetSession]\n[ResetSession]\n[PostResetSession]\n" +
"[PreClose]\n[Close]\n[PostClose]\n",
f: func(db *sql.DB) error {
buf := &bytes.Buffer{}
ctx := context.WithValue(context.Background(), contextHooksKey{}, newLoggingHook(buf))
Expand All @@ -803,7 +821,7 @@ func TestFakeDB(t *testing.T) {
}
if _, ok := db.Driver().(*Proxy); ok {
got := buf.String()
want := "[PreExec]\n[Exec]\n[PostExec]\n"
want := "[PreOpen]\n[Open]\n[PostOpen]\n[PreExec]\n[Exec]\n[PostExec]\n"
if got != want {
return fmt.Errorf("want %s, got %s", want, got)
}
Expand Down

0 comments on commit f9fce2d

Please sign in to comment.