From dbb2220ce745351bc65fb4255b61b57ffa28b495 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 16 Oct 2017 14:29:50 +0800 Subject: [PATCH] fix some tests --- interface.go | 4 ++++ session_insert_test.go | 4 ++-- session_update_test.go | 40 ++++++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/interface.go b/interface.go index 31180486..4f94750b 100644 --- a/interface.go +++ b/interface.go @@ -23,6 +23,7 @@ type Interface interface { CreateIndexes(bean interface{}) error CreateUniques(bean interface{}) error Decr(column string, arg ...interface{}) *Session + Desc(...string) *Session Delete(interface{}) (int64, error) Distinct(columns ...string) *Session DropIndexes(bean interface{}) error @@ -40,6 +41,7 @@ type Interface interface { IsTableExist(beanOrTableName interface{}) (bool, error) Iterate(interface{}, IterFunc) error Limit(int, ...int) *Session + NoAutoCondition(...bool) *Session NotIn(string, ...interface{}) *Session Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session Omit(columns ...string) *Session @@ -58,6 +60,7 @@ type Interface interface { Table(tableNameOrBean interface{}) *Session Unscoped() *Session Update(bean interface{}, condiBeans ...interface{}) (int64, error) + UseBool(...string) *Session Where(interface{}, ...interface{}) *Session } @@ -86,6 +89,7 @@ type EngineInterface interface { SetTZDatabase(tz *time.Location) SetTZLocation(tz *time.Location) ShowSQL(show ...bool) + Sync(...interface{}) error Sync2(...interface{}) error StoreEngine(storeEngine string) *Session TableInfo(bean interface{}) *Table diff --git a/session_insert_test.go b/session_insert_test.go index d4878af6..05a3d3bf 100644 --- a/session_insert_test.go +++ b/session_insert_test.go @@ -219,7 +219,7 @@ func TestInsertDefault(t *testing.T) { } var di2 = DefaultInsert{Name: "test"} - _, err = testEngine.Omit(testEngine.ColumnMapper.Obj2Table("Status")).Insert(&di2) + _, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("Status")).Insert(&di2) if err != nil { t.Error(err) } @@ -267,7 +267,7 @@ func TestInsertDefault2(t *testing.T) { } var di2 = DefaultInsert2{Name: "test"} - _, err = testEngine.Omit(testEngine.ColumnMapper.Obj2Table("CheckTime")).Insert(&di2) + _, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("CheckTime")).Insert(&di2) if err != nil { t.Error(err) } diff --git a/session_update_test.go b/session_update_test.go index 690bd106..a978e566 100644 --- a/session_update_test.go +++ b/session_update_test.go @@ -83,7 +83,7 @@ type ForUpdate struct { Name string } -func setupForUpdate(engine *Engine) error { +func setupForUpdate(engine EngineInterface) error { v := new(ForUpdate) err := testEngine.DropTables(v) if err != nil { @@ -110,7 +110,7 @@ func setupForUpdate(engine *Engine) error { } func TestForUpdate(t *testing.T) { - if testEngine.DriverName() != "mysql" && testEngine.DriverName() != "mymysql" { + if testEngine.Dialect().DriverName() != "mysql" && testEngine.Dialect().DriverName() != "mymysql" { return } @@ -517,8 +517,8 @@ func TestUpdate1(t *testing.T) { } col2 := &UpdateMustCols{col1.Id, true, ""} - boolStr := testEngine.ColumnMapper.Obj2Table("Bool") - stringStr := testEngine.ColumnMapper.Obj2Table("String") + boolStr := testEngine.GetColumnMapper().Obj2Table("Bool") + stringStr := testEngine.GetColumnMapper().Obj2Table("String") _, err = testEngine.ID(col2.Id).MustCols(boolStr, stringStr).Update(col2) if err != nil { t.Error(err) @@ -559,7 +559,7 @@ func TestUpdateIncrDecr(t *testing.T) { _, err := testEngine.Insert(col1) assert.NoError(t, err) - colName := testEngine.ColumnMapper.Obj2Table("Cnt") + colName := testEngine.GetColumnMapper().Obj2Table("Cnt") cnt, err := testEngine.ID(col1.Id).Incr(colName).Update(col1) assert.NoError(t, err) @@ -759,21 +759,21 @@ func TestUpdateUpdated(t *testing.T) { func TestUpdateSameMapper(t *testing.T) { assert.NoError(t, prepareEngine()) - oldMapper := testEngine.ColumnMapper - testEngine.unMapType(rValue(new(Userinfo)).Type()) - testEngine.unMapType(rValue(new(Condi)).Type()) - testEngine.unMapType(rValue(new(Article)).Type()) - testEngine.unMapType(rValue(new(UpdateAllCols)).Type()) - testEngine.unMapType(rValue(new(UpdateMustCols)).Type()) - testEngine.unMapType(rValue(new(UpdateIncr)).Type()) + oldMapper := testEngine.GetColumnMapper() + testEngine.UnMapType(rValue(new(Userinfo)).Type()) + testEngine.UnMapType(rValue(new(Condi)).Type()) + testEngine.UnMapType(rValue(new(Article)).Type()) + testEngine.UnMapType(rValue(new(UpdateAllCols)).Type()) + testEngine.UnMapType(rValue(new(UpdateMustCols)).Type()) + testEngine.UnMapType(rValue(new(UpdateIncr)).Type()) testEngine.SetMapper(core.SameMapper{}) defer func() { - testEngine.unMapType(rValue(new(Userinfo)).Type()) - testEngine.unMapType(rValue(new(Condi)).Type()) - testEngine.unMapType(rValue(new(Article)).Type()) - testEngine.unMapType(rValue(new(UpdateAllCols)).Type()) - testEngine.unMapType(rValue(new(UpdateMustCols)).Type()) - testEngine.unMapType(rValue(new(UpdateIncr)).Type()) + testEngine.UnMapType(rValue(new(Userinfo)).Type()) + testEngine.UnMapType(rValue(new(Condi)).Type()) + testEngine.UnMapType(rValue(new(Article)).Type()) + testEngine.UnMapType(rValue(new(UpdateAllCols)).Type()) + testEngine.UnMapType(rValue(new(UpdateMustCols)).Type()) + testEngine.UnMapType(rValue(new(UpdateIncr)).Type()) testEngine.SetMapper(oldMapper) }() @@ -943,8 +943,8 @@ func TestUpdateSameMapper(t *testing.T) { } col2 := &UpdateMustCols{col1.Id, true, ""} - boolStr := testEngine.ColumnMapper.Obj2Table("Bool") - stringStr := testEngine.ColumnMapper.Obj2Table("String") + boolStr := testEngine.GetColumnMapper().Obj2Table("Bool") + stringStr := testEngine.GetColumnMapper().Obj2Table("String") _, err = testEngine.ID(col2.Id).MustCols(boolStr, stringStr).Update(col2) if err != nil { t.Error(err)