Test: model.Tags / modifications

This commit is contained in:
HFO4
2020-02-12 13:19:25 +08:00
parent 15f4b1819b
commit bb63ea7142
17 changed files with 352 additions and 55 deletions

View File

@@ -62,6 +62,15 @@ func TestDownload_AfterFind(t *testing.T) {
asserts.Error(err)
asserts.Equal("", download.StatusInfo.Gid)
}
// 关联任务
{
mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id", "error"}).AddRow(1, "error"))
download := Download{TaskID: 1}
download.BeforeSave()
asserts.NoError(mock.ExpectationsWereMet())
asserts.Equal("error", download.Task.Error)
}
}
func TestDownload_Save(t *testing.T) {
@@ -140,3 +149,23 @@ func TestDownload_GetOwner(t *testing.T) {
asserts.Equal("nick", user.Nick)
}
}
func TestGetDownloadsByStatusAndUser(t *testing.T) {
asserts := assert.New(t)
// 列出全部
{
mock.ExpectQuery("SELECT(.+)").WithArgs(1, 1, 2).WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(2).AddRow(3))
res := GetDownloadsByStatusAndUser(0, 1, 1, 2)
asserts.NoError(mock.ExpectationsWereMet())
asserts.Len(res, 2)
}
// 列出全部,分页
{
mock.ExpectQuery("SELECT(.+)DESC(.+)").WithArgs(1, 1, 2).WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(2).AddRow(3))
res := GetDownloadsByStatusAndUser(2, 1, 1, 2)
asserts.NoError(mock.ExpectationsWereMet())
asserts.Len(res, 2)
}
}