From 19b1270f7b904bd7db9716518c019f59d0b8b203 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 30 May 2017 20:29:15 +0800 Subject: [PATCH] fix tests --- engine.go | 7 ++++++- session_find_test.go | 15 +++++++++++---- test_mysql.sh | 1 + test_postgres.sh | 1 + test_sqlite.sh | 1 + 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100755 test_mysql.sh create mode 100755 test_postgres.sh create mode 100755 test_sqlite.sh diff --git a/engine.go b/engine.go index 3fdbfcc3..5b087b37 100644 --- a/engine.go +++ b/engine.go @@ -143,7 +143,6 @@ func (engine *Engine) Quote(value string) string { // QuoteTo quotes string and writes into the buffer func (engine *Engine) QuoteTo(buf *bytes.Buffer, value string) { - if buf == nil { return } @@ -781,6 +780,12 @@ func (engine *Engine) Having(conditions string) *Session { return session.Having(conditions) } +func (engine *Engine) unMapType(t reflect.Type) { + engine.mutex.Lock() + defer engine.mutex.Unlock() + delete(engine.Tables, t) +} + func (engine *Engine) autoMapType(v reflect.Value) (*core.Table, error) { t := v.Type() engine.mutex.Lock() diff --git a/session_find_test.go b/session_find_test.go index e76be073..25928da9 100644 --- a/session_find_test.go +++ b/session_find_test.go @@ -273,10 +273,14 @@ func TestHaving(t *testing.T) { func TestOrderSameMapper(t *testing.T) { assert.NoError(t, prepareEngine()) + testEngine.unMapType(rValue(new(Userinfo)).Type()) + mapper := testEngine.TableMapper - testEngine.SetTableMapper(core.SameMapper{}) + testEngine.SetMapper(core.SameMapper{}) + defer func() { - testEngine.SetTableMapper(mapper) + testEngine.unMapType(rValue(new(Userinfo)).Type()) + testEngine.SetMapper(mapper) }() assertSync(t, new(Userinfo)) @@ -300,10 +304,13 @@ func TestOrderSameMapper(t *testing.T) { func TestHavingSameMapper(t *testing.T) { assert.NoError(t, prepareEngine()) + testEngine.unMapType(rValue(new(Userinfo)).Type()) + mapper := testEngine.TableMapper - testEngine.SetTableMapper(core.SameMapper{}) + testEngine.SetMapper(core.SameMapper{}) defer func() { - testEngine.SetTableMapper(mapper) + testEngine.unMapType(rValue(new(Userinfo)).Type()) + testEngine.SetMapper(mapper) }() assertSync(t, new(Userinfo)) diff --git a/test_mysql.sh b/test_mysql.sh new file mode 100755 index 00000000..650e4ee1 --- /dev/null +++ b/test_mysql.sh @@ -0,0 +1 @@ +go test -db=mysql -conn_str="root:@/xorm_test" \ No newline at end of file diff --git a/test_postgres.sh b/test_postgres.sh new file mode 100755 index 00000000..dc1152e0 --- /dev/null +++ b/test_postgres.sh @@ -0,0 +1 @@ +go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable" \ No newline at end of file diff --git a/test_sqlite.sh b/test_sqlite.sh new file mode 100755 index 00000000..6352b5cb --- /dev/null +++ b/test_sqlite.sh @@ -0,0 +1 @@ +go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \ No newline at end of file