Add scripts to test all dialects

This commit is contained in:
Jinzhu 2013-12-04 12:06:50 +08:00
parent 0e8f9011bf
commit 204df61a8b
3 changed files with 21 additions and 8 deletions

View File

@ -19,7 +19,7 @@ func (s *mysql) SupportLastInsertId() bool {
func (d *mysql) SqlTag(column interface{}, size int) string {
switch column.(type) {
case time.Time:
return "timestamp"
return "datetime"
case bool, sql.NullBool:
return "boolean"
case int, int8, int16, int32, uint, uint8, uint16, uint32:

View File

@ -8,6 +8,7 @@ import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"os"
"reflect"
"strconv"
"testing"
@ -84,13 +85,20 @@ var (
func init() {
var err error
db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
// CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm';
// CREATE DATABASE 'gorm';
// GRANT ALL ON gorm.* TO 'gorm'@'localhost';
// db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")
// db, err = Open("sqlite3", "/tmp/gorm.db")
switch os.Getenv("GORM_DIALECT") {
case "mysql":
// CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm';
// CREATE DATABASE 'gorm';
// GRANT ALL ON gorm.* TO 'gorm'@'localhost';
fmt.Println("testing mysql...")
db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")
case "sqlite":
fmt.Println("testing sqlite3...")
db, err = Open("sqlite3", "/tmp/gorm.db")
default:
fmt.Println("testing postgres...")
db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
}
// db.SetLogger(log.New(os.Stdout, "\r\n", 0))
// db.LogMode(true)

5
test_all.sh Executable file
View File

@ -0,0 +1,5 @@
dialects=("postgres" "mysql" "sqlite")
for dialect in "${dialects[@]}" ; do
GORM_DIALECT=${dialect} go test
done