From 12e0367559e6a20ac5ac50a87fc3793c51cae279 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 4 May 2018 10:51:34 +0800 Subject: [PATCH] add more tests for Sync2 (#925) --- engine.go | 2 +- session_schema.go | 6 +++--- session_schema_test.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/engine.go b/engine.go index 93a8d8dac..08e2ace5c 100644 --- a/engine.go +++ b/engine.go @@ -1188,7 +1188,7 @@ func (engine *Engine) Sync(beans ...interface{}) error { for _, bean := range beans { v := rValue(bean) - tableNameNoSchema := engine.tbNameNoSchema(v.Interface()) + tableNameNoSchema := engine.TableName(bean) table, err := engine.autoMapType(v) if err != nil { return err diff --git a/session_schema.go b/session_schema.go index 659988683..369ec72a4 100644 --- a/session_schema.go +++ b/session_schema.go @@ -122,7 +122,7 @@ func (session *Session) DropTable(beanOrTableName interface{}) error { } func (session *Session) dropTable(beanOrTableName interface{}) error { - tableName := session.engine.tbNameNoSchema(beanOrTableName) + tableName := session.engine.TableName(beanOrTableName) var needDrop = true if !session.engine.dialect.SupportDropIfExists() { sqlStr, args := session.engine.dialect.TableCheckSql(tableName) @@ -147,7 +147,7 @@ func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error) defer session.Close() } - tableName := session.engine.tbNameNoSchema(beanOrTableName) + tableName := session.engine.TableName(beanOrTableName) return session.isTableExist(tableName) } @@ -163,7 +163,7 @@ func (session *Session) IsTableEmpty(bean interface{}) (bool, error) { if session.isAutoClose { defer session.Close() } - return session.isTableEmpty(session.engine.tbNameNoSchema(bean)) + return session.isTableEmpty(session.engine.TableName(bean)) } func (session *Session) isTableEmpty(tableName string) (bool, error) { diff --git a/session_schema_test.go b/session_schema_test.go index 100133ae2..5a0fca2e1 100644 --- a/session_schema_test.go +++ b/session_schema_test.go @@ -289,8 +289,21 @@ func TestSync2_2(t *testing.T) { assert.NoError(t, prepareEngine()) + var tableNames = make(map[string]bool) for i := 0; i < 10; i++ { tableName := fmt.Sprintf("test_sync2_index_%d", i) + tableNames[tableName] = true assert.NoError(t, testEngine.Table(tableName).Sync2(new(TestSync2Index))) + + exist, err := testEngine.IsTableExist(tableName) + assert.NoError(t, err) + assert.True(t, exist) + } + + tables, err := testEngine.DBMetas() + assert.NoError(t, err) + + for _, table := range tables { + assert.True(t, tableNames[table.Name]) } }