Browse Source

Add tests for tidb (#1207)

* add tests for tidb

* ignore select for update tests
tags/v.0.7.3
Lunny Xiao GitHub 10 months ago
parent
commit
1bcc25420d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 24 deletions
  1. +5
    -1
      .circleci/config.yml
  2. +1
    -1
      session_update_test.go
  3. +1
    -0
      test_tidb.sh
  4. +31
    -22
      xorm_test.go

+ 5
- 1
.circleci/config.yml View File

@@ -28,6 +28,8 @@ jobs:
SA_PASSWORD: yourStrong(!)Password
MSSQL_PID: Developer

- image: pingcap/tidb:v2.1.2

working_directory: /go/src/github.com/go-xorm/xorm
steps:
- checkout
@@ -52,6 +54,8 @@ jobs:
- run: go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic
- run: go test -v -race -db="mssql" -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" -coverprofile=coverage6-1.txt -covermode=atomic
- run: go test -v -race -db="mssql" -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic
- run: gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt > coverage.txt
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -coverprofile=coverage7-1.txt -covermode=atomic
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -cache=true -coverprofile=coverage7-2.txt -covermode=atomic
- run: gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt

- run: bash <(curl -s https://codecov.io/bash)

+ 1
- 1
session_update_test.go View File

@@ -110,7 +110,7 @@ func setupForUpdate(engine EngineInterface) error {
}

func TestForUpdate(t *testing.T) {
if testEngine.Dialect().DriverName() != "mysql" && testEngine.Dialect().DriverName() != "mymysql" {
if *ignoreSelectUpdate {
return
}



+ 1
- 0
test_tidb.sh View File

@@ -0,0 +1 @@
go test -db=mysql -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true

+ 31
- 22
xorm_test.go View File

@@ -26,14 +26,15 @@ var (
dbType string
connString string

db = flag.String("db", "sqlite3", "the tested database")
showSQL = flag.Bool("show_sql", true, "show generated SQLs")
ptrConnStr = flag.String("conn_str", "./test.db?cache=shared&mode=rwc", "test database connection string")
mapType = flag.String("map_type", "snake", "indicate the name mapping")
cache = flag.Bool("cache", false, "if enable cache")
cluster = flag.Bool("cluster", false, "if this is a cluster")
splitter = flag.String("splitter", ";", "the splitter on connstr for cluster")
schema = flag.String("schema", "", "specify the schema")
db = flag.String("db", "sqlite3", "the tested database")
showSQL = flag.Bool("show_sql", true, "show generated SQLs")
ptrConnStr = flag.String("conn_str", "./test.db?cache=shared&mode=rwc", "test database connection string")
mapType = flag.String("map_type", "snake", "indicate the name mapping")
cache = flag.Bool("cache", false, "if enable cache")
cluster = flag.Bool("cluster", false, "if this is a cluster")
splitter = flag.String("splitter", ";", "the splitter on connstr for cluster")
schema = flag.String("schema", "", "specify the schema")
ignoreSelectUpdate = flag.Bool("ignore_select_update", false, "ignore select update if implementation difference, only for tidb")
)

func createEngine(dbType, connStr string) error {
@@ -41,25 +42,22 @@ func createEngine(dbType, connStr string) error {
var err error

if !*cluster {
// create databases if not exist
var db *sql.DB
var err error
if strings.ToLower(dbType) != core.MSSQL {
db, err = sql.Open(dbType, connStr)
} else {
db, err = sql.Open(dbType, strings.Replace(connStr, "xorm_test", "master", -1))
}

if err != nil {
return err
}

switch strings.ToLower(dbType) {
case core.MSSQL:
db, err := sql.Open(dbType, strings.Replace(connStr, "xorm_test", "master", -1))
if err != nil {
return err
}
if _, err = db.Exec("If(db_id(N'xorm_test') IS NULL) BEGIN CREATE DATABASE xorm_test; END;"); err != nil {
return fmt.Errorf("db.Exec: %v", err)
}
db.Close()
*ignoreSelectUpdate = true
case core.POSTGRES:
db, err := sql.Open(dbType, connStr)
if err != nil {
return err
}
rows, err := db.Query(fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = 'xorm_test'"))
if err != nil {
return fmt.Errorf("db.Query: %v", err)
@@ -76,16 +74,27 @@ func createEngine(dbType, connStr string) error {
return fmt.Errorf("CREATE SCHEMA: %v", err)
}
}
db.Close()
*ignoreSelectUpdate = true
case core.MYSQL:
db, err := sql.Open(dbType, strings.Replace(connStr, "xorm_test", "mysql", -1))
if err != nil {
return err
}
if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS xorm_test"); err != nil {
return fmt.Errorf("db.Exec: %v", err)
}
db.Close()
default:
*ignoreSelectUpdate = true
}
db.Close()

testEngine, err = NewEngine(dbType, connStr)
} else {
testEngine, err = NewEngineGroup(dbType, strings.Split(connStr, *splitter))
if dbType != "mysql" && dbType != "mymysql" {
*ignoreSelectUpdate = true
}
}
if err != nil {
return err


Loading…
Cancel
Save