This commit is contained in:
Lunny Xiao 2019-01-21 21:24:23 +08:00
parent c2c3aab10a
commit 7ecdf5b255
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 10 additions and 4 deletions

View File

@ -19,7 +19,7 @@ jobs:
# CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/ # CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/
- image: circleci/postgres:9.6.2-alpine - image: circleci/postgres:9.6.2-alpine
environment: environment:
POSTGRES_USER: root POSTGRES_USER: circleci
POSTGRES_DB: xorm_test POSTGRES_DB: xorm_test
- image: microsoft/mssql-server-linux:latest - image: microsoft/mssql-server-linux:latest

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -41,7 +42,7 @@ func createEngine(dbType, connStr string) error {
if err != nil { if err != nil {
return err return err
} }
switch strings.ToUpper(dbType) { switch strings.ToLower(dbType) {
case core.MSSQL: case core.MSSQL:
if _, err = db.Exec("If(db_id(N'xorm_test') IS NULL) BEGIN CREATE DATABASE xorm_test; END;"); err != nil { 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) return fmt.Errorf("db.Exec: %v", err)
@ -59,6 +60,11 @@ func createEngine(dbType, connStr string) error {
if _, err = db.Exec("CREATE DATABASE xorm_test"); err != nil { if _, err = db.Exec("CREATE DATABASE xorm_test"); err != nil {
return fmt.Errorf("db.Exec: %v", err) return fmt.Errorf("db.Exec: %v", err)
} }
if schema != nil {
if _, err = db.Exec("CREATE SCHEMA " + *schema); err != nil {
return fmt.Errorf("db.Exec: %v", err)
}
}
case core.MYSQL: case core.MYSQL:
if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS xorm_test"); err != nil { if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS xorm_test"); err != nil {
return fmt.Errorf("db.Exec: %v", err) return fmt.Errorf("db.Exec: %v", err)
@ -126,7 +132,7 @@ func TestMain(m *testing.M) {
} }
} else { } else {
if ptrConnStr == nil { if ptrConnStr == nil {
fmt.Println("you should indicate conn string") log.Fatal("you should indicate conn string")
return return
} }
connString = *ptrConnStr connString = *ptrConnStr
@ -143,7 +149,7 @@ func TestMain(m *testing.M) {
fmt.Println("testing", dbType, connString) fmt.Println("testing", dbType, connString)
if err := prepareEngine(); err != nil { if err := prepareEngine(); err != nil {
fmt.Println(err) log.Fatal(err)
return return
} }