add tests for get interface (#1194)

This commit is contained in:
Lunny Xiao 2019-01-20 11:09:37 +08:00 committed by GitHub
parent 5750e3f90a
commit 58b4f7f109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -386,3 +386,37 @@ func TestContextGet2(t *testing.T) {
assert.EqualValues(t, 1, c3.Id)
assert.EqualValues(t, "1", c3.Name)
}
type GetCustomTableInterface interface {
TableName() string
}
type MyGetCustomTableImpletation struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
const getCustomTableName = "GetCustomTableInterface"
func (m *MyGetCustomTableImpletation) TableName() string {
return getCustomTableName
}
func TestGetCustomTableInterface(t *testing.T) {
assert.NoError(t, prepareEngine())
assert.NoError(t, testEngine.Table(getCustomTableName).Sync2(new(MyGetCustomTableImpletation)))
exist, err := testEngine.IsTableExist(getCustomTableName)
assert.NoError(t, err)
assert.True(t, exist)
_, err = testEngine.Insert(&MyGetCustomTableImpletation{
Name: "xlw",
})
assert.NoError(t, err)
var c GetCustomTableInterface = new(MyGetCustomTableImpletation)
has, err := testEngine.Get(c)
assert.NoError(t, err)
assert.True(t, has)
}