enhance test

This commit is contained in:
6543 2023-08-06 19:12:31 +02:00
parent 884358aecd
commit 5c957acce4
No known key found for this signature in database
GPG Key ID: B8BE6D610E61C862
1 changed files with 18 additions and 2 deletions

View File

@ -702,13 +702,21 @@ func TestSyncWithOptions(t *testing.T) {
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{}) result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{})
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, result) assert.NotNil(t, result)
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 2) indices = getIndicesOfBeanFromDB(t, &SyncWithOpts1{})
assert.Len(t, indices, 2)
assert.ElementsMatch(t, []string{"ttt", "index"}, getKeysFromMap(indices))
// only ignore constrains // only ignore constrains
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{}) result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{})
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, result) assert.NotNil(t, result)
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 4) indices = getIndicesOfBeanFromDB(t, &SyncWithOpts1{})
assert.Len(t, indices, 4)
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
tableInfoFromStruct, _ := testEngine.TableInfo(&SyncWithOpts1{})
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
} }
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index { func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
@ -728,3 +736,11 @@ func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.
} }
return tSchema.Indexes return tSchema.Indexes
} }
func getKeysFromMap(m map[string]*schemas.Index) []string {
var ss []string
for k := range m {
ss = append(ss, k)
}
return ss
}