From 4c368be2544560efe897c2f497dd110b1b56e918 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 28 Jan 2014 16:21:02 +0800 Subject: [PATCH] rename gorm_test to main_test --- gorm_test.go => main_test.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) rename gorm_test.go => main_test.go (98%) diff --git a/gorm_test.go b/main_test.go similarity index 98% rename from gorm_test.go rename to main_test.go index c90631f4..398bb159 100644 --- a/gorm_test.go +++ b/main_test.go @@ -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") } }