Feat: API for getting object property

This commit is contained in:
HFO4
2021-03-11 14:50:02 +08:00
parent a93b964d8b
commit 1f1bc056e3
8 changed files with 201 additions and 1 deletions

View File

@@ -530,3 +530,37 @@ func TestFolder_FileInfoInterface(t *testing.T) {
asserts.True(folder.IsDir())
asserts.Equal("/test", folder.GetPosition())
}
func TestTraceRoot(t *testing.T) {
asserts := assert.New(t)
var parentId uint
parentId = 5
folder := Folder{
ParentID: &parentId,
OwnerID: 1,
Name: "test_name",
}
// 成功
{
mock.ExpectQuery("SELECT(.+)").WithArgs(5, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "parent_id"}).AddRow(5, "parent", 1))
mock.ExpectQuery("SELECT(.+)").WithArgs(1, 0).
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(5, "/"))
asserts.NoError(folder.TraceRoot())
asserts.Equal("/parent", folder.Position)
asserts.NoError(mock.ExpectationsWereMet())
}
// 出现错误
// 成功
{
mock.ExpectQuery("SELECT(.+)").WithArgs(5, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "parent_id"}).AddRow(5, "parent", 1))
mock.ExpectQuery("SELECT(.+)").WithArgs(1, 0).
WillReturnError(errors.New("error"))
asserts.Error(folder.TraceRoot())
asserts.Equal("parent", folder.Position)
asserts.NoError(mock.ExpectationsWereMet())
}
}