Skip to content

Add github.com/vaquita/mysql driver to the suite. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sqltest/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
_ "github.com/tgulacsi/goracle/godrv"
_ "github.com/vaquita/mysql"
_ "github.com/ziutek/mymysql/godrv"
)
110 changes: 84 additions & 26 deletions src/sqltest/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ type Tester interface {
}

var (
myMysql Tester = &myMysqlDB{}
goMysql Tester = &goMysqlDB{}
sqlite Tester = sqliteDB{}
pq Tester = &pqDB{}
oracle Tester = &oracleDB{}
myMysql Tester = &myMysqlDB{}
goMysql Tester = &goMysqlDB{}
vaqMysql Tester = &vaqMysqlDB{}
sqlite Tester = sqliteDB{}
pq Tester = &pqDB{}
oracle Tester = &oracleDB{}
)

const TablePrefix = "gosqltest_"
Expand Down Expand Up @@ -113,6 +114,22 @@ func (m *goMysqlDB) Running() bool {
return m.running
}

type vaqMysqlDB struct {
once sync.Once // guards init of running
running bool // whether port 3306 is listening
}

func (m *vaqMysqlDB) Running() bool {
m.once.Do(func() {
c, err := net.Dial("tcp", "localhost:3306")
if err == nil {
m.running = true
c.Close()
}
})
return m.running
}

type oracleDB struct {
once sync.Once // guards init of running
running bool // whether port 1521 is listening
Expand Down Expand Up @@ -250,6 +267,43 @@ func (m *goMysqlDB) RunTest(t *testing.T, fn func(params)) {
fn(params)
}

func (m *vaqMysqlDB) RunTest(t *testing.T, fn func(params)) {
if !m.Running() {
t.Logf("skipping test; no MySQL running on localhost:3306")
return
}
user := os.Getenv("GOSQLTEST_MYSQL_USER")
if user == "" {
user = "root"
}
pass, ok := getenvOk("GOSQLTEST_MYSQL_PASS")
if !ok {
pass = "root"
}
dbName := "gosqltest"
db, err := sql.Open("vaquita", fmt.Sprintf("mysql://%s:%s@localhost/%s", user, pass, dbName))
if err != nil {
t.Fatalf("error connecting: %v", err)
}

params := params{vaqMysql, t, db}

// Drop all tables in the test database.
rows, err := db.Query("SHOW TABLES")
if err != nil {
t.Fatalf("failed to enumerate tables: %v", err)
}
for rows.Next() {
var table string
if rows.Scan(&table) == nil &&
strings.HasPrefix(strings.ToLower(table), strings.ToLower(TablePrefix)) {
params.mustExec("DROP TABLE " + table)
}
}

fn(params)
}

func (o *oracleDB) RunTest(t *testing.T, fn func(params)) {
if !o.Running() {
t.Logf("skipping test; no Oracle running on localhost:1521")
Expand Down Expand Up @@ -287,7 +341,7 @@ func (o *oracleDB) RunTest(t *testing.T, fn func(params)) {

func sqlBlobParam(t params, size int) string {
switch t.dbType {
case sqlite:
case sqlite:
return fmt.Sprintf("blob[%d]", size)
case pq:
return "bytea"
Expand All @@ -297,11 +351,12 @@ func sqlBlobParam(t params, size int) string {
return fmt.Sprintf("VARBINARY(%d)", size)
}

func TestBlobs_SQLite(t *testing.T) { sqlite.RunTest(t, testBlobs) }
func TestBlobs_MyMySQL(t *testing.T) { myMysql.RunTest(t, testBlobs) }
func TestBlobs_GoMySQL(t *testing.T) { goMysql.RunTest(t, testBlobs) }
func TestBlobs_PQ(t *testing.T) { pq.RunTest(t, testBlobs) }
func TestBlobs_Oracle(t *testing.T) { oracle.RunTest(t, testBlobs) }
func TestBlobs_SQLite(t *testing.T) { sqlite.RunTest(t, testBlobs) }
func TestBlobs_MyMySQL(t *testing.T) { myMysql.RunTest(t, testBlobs) }
func TestBlobs_GoMySQL(t *testing.T) { goMysql.RunTest(t, testBlobs) }
func TestBlobs_VaqMySQL(t *testing.T) { vaqMysql.RunTest(t, testBlobs) }
func TestBlobs_PQ(t *testing.T) { pq.RunTest(t, testBlobs) }
func TestBlobs_Oracle(t *testing.T) { oracle.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 All @@ -328,11 +383,12 @@ func testBlobs(t params) {
}
}

func TestManyQueryRow_SQLite(t *testing.T) { sqlite.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_MyMySQL(t *testing.T) { myMysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_GoMySQL(t *testing.T) { goMysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_PQ(t *testing.T) { pq.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_Oracle(t *testing.T) { oracle.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_SQLite(t *testing.T) { sqlite.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_MyMySQL(t *testing.T) { myMysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_GoMySQL(t *testing.T) { goMysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_VaqMySQL(t *testing.T) { vaqMysql.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_PQ(t *testing.T) { pq.RunTest(t, testManyQueryRow) }
func TestManyQueryRow_Oracle(t *testing.T) { oracle.RunTest(t, testManyQueryRow) }

func testManyQueryRow(t params) {
if testing.Short() {
Expand All @@ -350,11 +406,12 @@ func testManyQueryRow(t params) {
}
}

func TestTxQuery_SQLite(t *testing.T) { sqlite.RunTest(t, testTxQuery) }
func TestTxQuery_MyMySQL(t *testing.T) { myMysql.RunTest(t, testTxQuery) }
func TestTxQuery_GoMySQL(t *testing.T) { goMysql.RunTest(t, testTxQuery) }
func TestTxQuery_PQ(t *testing.T) { pq.RunTest(t, testTxQuery) }
func TestTxQuery_Oracle(t *testing.T) { oracle.RunTest(t, testTxQuery) }
func TestTxQuery_SQLite(t *testing.T) { sqlite.RunTest(t, testTxQuery) }
func TestTxQuery_MyMySQL(t *testing.T) { myMysql.RunTest(t, testTxQuery) }
func TestTxQuery_GoMySQL(t *testing.T) { goMysql.RunTest(t, testTxQuery) }
func TestTxQuery_VaqMySQL(t *testing.T) { vaqMysql.RunTest(t, testTxQuery) }
func TestTxQuery_PQ(t *testing.T) { pq.RunTest(t, testTxQuery) }
func TestTxQuery_Oracle(t *testing.T) { oracle.RunTest(t, testTxQuery) }

func testTxQuery(t params) {
tx, err := t.Begin()
Expand Down Expand Up @@ -393,11 +450,12 @@ func testTxQuery(t params) {
}
}

func TestPreparedStmt_SQLite(t *testing.T) { sqlite.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_MyMySQL(t *testing.T) { myMysql.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_GoMySQL(t *testing.T) { goMysql.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_PQ(t *testing.T) { pq.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_Oracle(t *testing.T) { oracle.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_SQLite(t *testing.T) { sqlite.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_MyMySQL(t *testing.T) { myMysql.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_GoMySQL(t *testing.T) { goMysql.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_VaqMySQL(t *testing.T) { vaqMysql.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_PQ(t *testing.T) { pq.RunTest(t, testPreparedStmt) }
func TestPreparedStmt_Oracle(t *testing.T) { oracle.RunTest(t, testPreparedStmt) }

func testPreparedStmt(t params) {
t.mustExec("CREATE TABLE " + TablePrefix + "t (count INT)")
Expand Down