rename gorm_test to main_test

This commit is contained in:
Jinzhu 2014-01-28 16:21:02 +08:00
parent a2edf56c58
commit 4c368be254
1 changed files with 14 additions and 12 deletions

View File

@ -1,4 +1,4 @@
package gorm
package gorm_test
import (
"database/sql"
@ -7,8 +7,10 @@ import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3"
"os"
"reflect"
@ -87,7 +89,7 @@ type Product struct {
}
var (
db DB
db gorm.DB
t1, t2, t3, t4, t5 time.Time
)
@ -99,13 +101,13 @@ func init() {
// 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")
db, err = gorm.Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")
case "sqlite":
fmt.Println("testing sqlite3...")
db, err = Open("sqlite3", "/tmp/gorm.db")
db, err = gorm.Open("sqlite3", "/tmp/gorm.db")
default:
fmt.Println("testing postgres...")
db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
db, err = gorm.Open("postgres", "user=gorm dbname=gorm sslmode=disable")
}
// db.SetLogger(Logger{log.New(os.Stdout, "\r\n", 0)})
@ -230,7 +232,7 @@ func TestCreateAndUpdate(t *testing.T) {
user.Name = new_name
db.Save(&user)
if db.Where("name = ?", name).First(&User{}).Error != RecordNotFound {
if db.Where("name = ?", name).First(&User{}).Error != gorm.RecordNotFound {
t.Errorf("Should raise RecordNotFound error when looking with an outdated name")
}
@ -629,7 +631,7 @@ func (s *Product) AfterFind() {
s.AfterFindCallTimes = s.AfterFindCallTimes + 1
}
func (s *Product) AfterCreate(db *DB) {
func (s *Product) AfterCreate(db *gorm.DB) {
db.Model(s).UpdateColumn(Product{AfterCreateCallTimes: s.AfterCreateCallTimes + 1})
}
@ -1624,16 +1626,16 @@ func TestJoins(t *testing.T) {
}
}
func NameIn1And2(d *DB) *DB {
func NameIn1And2(d *gorm.DB) *gorm.DB {
return d.Where("name in (?)", []string{"1", "2"})
}
func NameIn2And3(d *DB) *DB {
func NameIn2And3(d *gorm.DB) *gorm.DB {
return d.Where("name in (?)", []string{"2", "3"})
}
func NameIn(names []string) func(d *DB) *DB {
return func(d *DB) *DB {
func NameIn(names []string) func(d *gorm.DB) *gorm.DB {
return func(d *gorm.DB) *gorm.DB {
return d.Where("name in (?)", names)
}
}
@ -1680,7 +1682,7 @@ func TestHaving(t *testing.T) {
func TestExecRawSql(t *testing.T) {
db.Exec("update users set name=? where name in (?)", "jinzhu", []string{"1", "2", "3"})
if db.Where("name in (?)", []string{"1", "2", "3"}).First(&User{}).Error != RecordNotFound {
if db.Where("name in (?)", []string{"1", "2", "3"}).First(&User{}).Error != gorm.RecordNotFound {
t.Error("Raw sql should be able to parse argument")
}
}