Skip to content

Commit

Permalink
orm: add inline struct test case
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclesu committed Mar 8, 2016
1 parent 85f55fc commit 64e0858
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
25 changes: 24 additions & 1 deletion orm/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"

// As tidb can't use go get, so disable the tidb testing now
// _ "github.com/pingcap/tidb"
)
Expand Down Expand Up @@ -352,6 +351,30 @@ type GroupPermissions struct {
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 {
Driver string
Source string
Expand Down
24 changes: 24 additions & 0 deletions orm/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func TestSyncDb(t *testing.T) {
RegisterModel(new(Group))
RegisterModel(new(Permission))
RegisterModel(new(GroupPermissions))
RegisterModel(new(InLine))

err := RunSyncdb("default", true, Debug)
throwFail(t, err)
Expand All @@ -206,6 +207,7 @@ func TestRegisterModels(t *testing.T) {
RegisterModel(new(Group))
RegisterModel(new(Permission))
RegisterModel(new(GroupPermissions))
RegisterModel(new(InLine))

BootStrap()

Expand Down Expand Up @@ -1928,3 +1930,25 @@ func TestReadOrCreate(t *testing.T) {

dORM.Delete(u)
}

func TestInLine(t *testing.T) {
name := "inline"
email := "[email protected]"
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))
}

0 comments on commit 64e0858

Please sign in to comment.