-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from kanmu/support_connector
Support driver.Connector
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,36 @@ func TestShouldRunWithinTransaction(t *testing.T) { | |
} | ||
} | ||
|
||
func TestShouldRunWithinTransactionForOpenDB(t *testing.T) { | ||
t.Parallel() | ||
var count int | ||
db1 := sql.OpenDB(pgtxdb.NewConnector("one", "pgx", "postgres://pgtxdbtest@localhost:5432/pgtxdbtest?sslmode=disable")) | ||
defer db1.Close() | ||
|
||
_, err := db1.Exec(`INSERT INTO app_user(username, email) VALUES('txdb', '[email protected]')`) | ||
if err != nil { | ||
t.Fatalf("failed to insert an app_user: %s", err) | ||
} | ||
err = db1.QueryRow("SELECT COUNT(id) FROM app_user").Scan(&count) | ||
if err != nil { | ||
t.Fatalf("failed to count users: %s", err) | ||
} | ||
if count != 1 { | ||
t.Fatalf("expected 1 user to be in database, but got %d", count) | ||
} | ||
|
||
db2 := sql.OpenDB(pgtxdb.NewConnector("two", "pgx", "postgres://pgtxdbtest@localhost:5432/pgtxdbtest?sslmode=disable")) | ||
defer db2.Close() | ||
|
||
err = db2.QueryRow("SELECT COUNT(id) FROM app_user").Scan(&count) | ||
if err != nil { | ||
t.Fatalf("failed to count app_user: %s", err) | ||
} | ||
if count != 0 { | ||
t.Fatalf("expected 0 user to be in database, but got %d", count) | ||
} | ||
} | ||
|
||
func TestShouldNotHoldConnectionForRows(t *testing.T) { | ||
t.Parallel() | ||
db, err := sql.Open("pgtxdb", "three") | ||
|