Skip to content

Commit

Permalink
start of making it work on postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfitz committed Feb 14, 2012
1 parent 2ad2dfc commit d8a02ec
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/sqltest/sql_test.go
Expand Up @@ -29,23 +29,23 @@ type pqDB struct {

func (p *pqDB) RunTest(t *testing.T, fn func(params)) {
if !p.Running() {
fmt.Printf("skipping test; no MySQL running on localhost:3306")
fmt.Printf("skipping test; no Postgres running on localhost:5432")
return
}
user := os.Getenv("GOSQLTEST_PQ_USER")
if user == "" {
user = os.Getenv("USER")
}
dbName := "gosqltest"
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s@localhost:5432/%s", user, dbName))
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:gosqltest@localhost:5432/%s", user, dbName))
if err != nil {
t.Fatalf("error connecting: %v", err)
}

params := params{pq, t, db}

// Drop all tables in the test database.
rows, err := db.Query("SHOW TABLES")
rows, err := db.Query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
if err != nil {
t.Fatalf("failed to enumerate tables: %v", err)
}
Expand All @@ -70,7 +70,6 @@ func (p *pqDB) Running() bool {
return p.running
}


type sqliteDB struct{}

type mysqlDB struct {
Expand Down Expand Up @@ -161,7 +160,7 @@ func sqlBlobParam(t params, size int) string {

func TestBlobs_SQLite(t *testing.T) { sqlite.RunTest(t, testBlobs) }
func TestBlobs_MySQL(t *testing.T) { mysql.RunTest(t, testBlobs) }
func TestBlobs_PQ(t *testing.T) { pq.RunTest(t, testBlobs) }
func TestBlobs_PQ(t *testing.T) { pq.RunTest(t, testBlobs) }

func testBlobs(t params) {
var blob = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
Expand Down Expand Up @@ -190,9 +189,13 @@ func testBlobs(t params) {

func TestManyQueryRow_SQLite(t *testing.T) { sqlite.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_MySQL(t *testing.T) { mysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_PQ(t *testing.T) { pq.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_PQ(t *testing.T) { pq.RunTest(t, testManyQueryRow) }

func testManyQueryRow(t params) {
if testing.Short() {
t.Logf("skipping in short mode")
return
}
t.mustExec("create table foo (id integer primary key, name varchar(50))")
t.mustExec("insert into foo (id, name) values(?,?)", 1, "bob")
var name string
Expand All @@ -204,9 +207,8 @@ func testManyQueryRow(t params) {
}
}


func TestTxQuery_SQLite(t *testing.T) { sqlite.RunTest(t, testTxQuery) }
func TestTxQuery_PQ(t *testing.T) { pq.RunTest(t, testTxQuery) }
func TestTxQuery_PQ(t *testing.T) { pq.RunTest(t, testTxQuery) }

func testTxQuery(t params) {
tx, err := t.Begin()
Expand Down

0 comments on commit d8a02ec

Please sign in to comment.