Fix: failed unit test due to missing mock.ExpectWereMatch()

This commit is contained in:
HFO4
2019-12-08 13:03:08 +08:00
parent 6eff13c80a
commit a445da5286
4 changed files with 38 additions and 20 deletions

View File

@@ -411,7 +411,7 @@ func TestFileSystem_Copy(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
// 1
mock.ExpectQuery("SELECT(.+)").
WithArgs(1, 1, "src").
WithArgs(1, 1, "dst").
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
// 根目录
mock.ExpectQuery("SELECT(.+)").
@@ -419,17 +419,17 @@ func TestFileSystem_Copy(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
// 1
mock.ExpectQuery("SELECT(.+)").
WithArgs(1, 1, "dst").
WithArgs(1, 1, "src").
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
err := fs.Copy(ctx, []uint{1}, []uint{}, "/src", "/dst")
asserts.Error(err)
asserts.NoError(mock.ExpectationsWereMet())
}
}
func TestFileSystem_Move(t *testing.T) {
conf.DatabaseConfig.Type = "mysql"
asserts := assert.New(t)
fs := &FileSystem{User: &model.User{
Model: gorm.Model{
@@ -458,7 +458,7 @@ func TestFileSystem_Move(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
// 1
mock.ExpectQuery("SELECT(.+)").
WithArgs(1, 1, "src").
WithArgs(1, 1, "dst").
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
// 根目录
mock.ExpectQuery("SELECT(.+)").
@@ -466,9 +466,10 @@ func TestFileSystem_Move(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
// 1
mock.ExpectQuery("SELECT(.+)").
WithArgs(1, 1, "dst").
WithArgs(1, 1, "src").
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
err := fs.Move(ctx, []uint{1}, []uint{}, "/src", "/dst")
asserts.Error(err)
asserts.NoError(mock.ExpectationsWereMet())
}
}