Skip to content

Commit

Permalink
add more tests for Sync2 (go-xorm#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored May 4, 2018
1 parent ae0364a commit 12e0367
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions session_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions session_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 12e0367

Please sign in to comment.