mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 22:00:55 +00:00
orm: add inline struct test case
This commit is contained in:
parent
85f55fcb41
commit
64e0858d44
@ -25,7 +25,6 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
// As tidb can't use go get, so disable the tidb testing now
|
// As tidb can't use go get, so disable the tidb testing now
|
||||||
// _ "github.com/pingcap/tidb"
|
// _ "github.com/pingcap/tidb"
|
||||||
)
|
)
|
||||||
@ -352,6 +351,30 @@ type GroupPermissions struct {
|
|||||||
Permission *Permission `orm:"rel(fk)"`
|
Permission *Permission `orm:"rel(fk)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModelID struct {
|
||||||
|
Id int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type ModelBase struct {
|
||||||
|
ModelID
|
||||||
|
|
||||||
|
Created time.Time `orm:"auto_now_add;type(datetime)"`
|
||||||
|
Updated time.Time `orm:"auto_now;type(datetime)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InLine struct {
|
||||||
|
// Common Fields
|
||||||
|
ModelBase
|
||||||
|
|
||||||
|
// Other Fields
|
||||||
|
Name string `orm:"unique"`
|
||||||
|
Email string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInLine() *InLine {
|
||||||
|
return new(InLine)
|
||||||
|
}
|
||||||
|
|
||||||
var DBARGS = struct {
|
var DBARGS = struct {
|
||||||
Driver string
|
Driver string
|
||||||
Source string
|
Source string
|
||||||
|
@ -187,6 +187,7 @@ func TestSyncDb(t *testing.T) {
|
|||||||
RegisterModel(new(Group))
|
RegisterModel(new(Group))
|
||||||
RegisterModel(new(Permission))
|
RegisterModel(new(Permission))
|
||||||
RegisterModel(new(GroupPermissions))
|
RegisterModel(new(GroupPermissions))
|
||||||
|
RegisterModel(new(InLine))
|
||||||
|
|
||||||
err := RunSyncdb("default", true, Debug)
|
err := RunSyncdb("default", true, Debug)
|
||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
@ -206,6 +207,7 @@ func TestRegisterModels(t *testing.T) {
|
|||||||
RegisterModel(new(Group))
|
RegisterModel(new(Group))
|
||||||
RegisterModel(new(Permission))
|
RegisterModel(new(Permission))
|
||||||
RegisterModel(new(GroupPermissions))
|
RegisterModel(new(GroupPermissions))
|
||||||
|
RegisterModel(new(InLine))
|
||||||
|
|
||||||
BootStrap()
|
BootStrap()
|
||||||
|
|
||||||
@ -1928,3 +1930,25 @@ func TestReadOrCreate(t *testing.T) {
|
|||||||
|
|
||||||
dORM.Delete(u)
|
dORM.Delete(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInLine(t *testing.T) {
|
||||||
|
name := "inline"
|
||||||
|
email := "hello@go.com"
|
||||||
|
inline := NewInLine()
|
||||||
|
inline.Name = name
|
||||||
|
inline.Email = email
|
||||||
|
|
||||||
|
id, err := dORM.Insert(inline)
|
||||||
|
throwFail(t, err)
|
||||||
|
throwFail(t, AssertIs(id, 1))
|
||||||
|
|
||||||
|
il := NewInLine()
|
||||||
|
il.Id = 1
|
||||||
|
err = dORM.Read(il)
|
||||||
|
throwFail(t, err)
|
||||||
|
|
||||||
|
throwFail(t, AssertIs(il.Name, name))
|
||||||
|
throwFail(t, AssertIs(il.Email, email))
|
||||||
|
throwFail(t, AssertIs(il.Created.In(DefaultTimeLoc), inline.Created.In(DefaultTimeLoc), testDate))
|
||||||
|
throwFail(t, AssertIs(il.Updated.In(DefaultTimeLoc), inline.Updated.In(DefaultTimeLoc), testDateTime))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user