mirror of https://github.com/go-gorm/gorm.git
rename gorm_test to main_test
This commit is contained in:
parent
a2edf56c58
commit
4c368be254
|
@ -1,4 +1,4 @@
|
||||||
package gorm
|
package gorm_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
@ -7,8 +7,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -87,7 +89,7 @@ type Product struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
db DB
|
db gorm.DB
|
||||||
t1, t2, t3, t4, t5 time.Time
|
t1, t2, t3, t4, t5 time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,13 +101,13 @@ func init() {
|
||||||
// CREATE DATABASE gorm;
|
// CREATE DATABASE gorm;
|
||||||
// GRANT ALL ON gorm.* TO 'gorm'@'localhost';
|
// GRANT ALL ON gorm.* TO 'gorm'@'localhost';
|
||||||
fmt.Println("testing mysql...")
|
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":
|
case "sqlite":
|
||||||
fmt.Println("testing sqlite3...")
|
fmt.Println("testing sqlite3...")
|
||||||
db, err = Open("sqlite3", "/tmp/gorm.db")
|
db, err = gorm.Open("sqlite3", "/tmp/gorm.db")
|
||||||
default:
|
default:
|
||||||
fmt.Println("testing postgres...")
|
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)})
|
// db.SetLogger(Logger{log.New(os.Stdout, "\r\n", 0)})
|
||||||
|
@ -230,7 +232,7 @@ func TestCreateAndUpdate(t *testing.T) {
|
||||||
|
|
||||||
user.Name = new_name
|
user.Name = new_name
|
||||||
db.Save(&user)
|
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")
|
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
|
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})
|
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"})
|
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"})
|
return d.Where("name in (?)", []string{"2", "3"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NameIn(names []string) func(d *DB) *DB {
|
func NameIn(names []string) func(d *gorm.DB) *gorm.DB {
|
||||||
return func(d *DB) *DB {
|
return func(d *gorm.DB) *gorm.DB {
|
||||||
return d.Where("name in (?)", names)
|
return d.Where("name in (?)", names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1680,7 +1682,7 @@ func TestHaving(t *testing.T) {
|
||||||
|
|
||||||
func TestExecRawSql(t *testing.T) {
|
func TestExecRawSql(t *testing.T) {
|
||||||
db.Exec("update users set name=? where name in (?)", "jinzhu", []string{"1", "2", "3"})
|
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")
|
t.Error("Raw sql should be able to parse argument")
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue