mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-07 09:41:06 +08:00
add bulk delete interface
This commit is contained in:
@@ -55,6 +55,12 @@ func newUserExampleHandler() *gotest.Handler {
|
||||
Path: "/userExample/:id",
|
||||
HandlerFunc: h.IHandler.(UserExampleHandler).DeleteByID,
|
||||
},
|
||||
{
|
||||
FuncName: "DeleteByIDs",
|
||||
Method: http.MethodPost,
|
||||
Path: "/userExamples/delete/ids",
|
||||
HandlerFunc: h.IHandler.(UserExampleHandler).DeleteByIDs,
|
||||
},
|
||||
{
|
||||
FuncName: "UpdateByID",
|
||||
Method: http.MethodPut,
|
||||
@@ -161,6 +167,35 @@ func Test_userExampleHandler_DeleteByID(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func Test_userExampleHandler_DeleteByIDs(t *testing.T) {
|
||||
h := newUserExampleHandler()
|
||||
defer h.Close()
|
||||
testData := h.TestData.(*model.UserExample)
|
||||
|
||||
h.MockDao.SQLMock.ExpectBegin()
|
||||
h.MockDao.SQLMock.ExpectExec("UPDATE .*").
|
||||
WithArgs(h.MockDao.AnyTime, testData.ID). // adjusted for the amount of test data
|
||||
WillReturnResult(sqlmock.NewResult(int64(testData.ID), 1))
|
||||
h.MockDao.SQLMock.ExpectCommit()
|
||||
|
||||
result := &gohttp.StdResult{}
|
||||
err := gohttp.Post(result, h.GetRequestURL("DeleteByIDs"), &types.DeleteUserExamplesByIDsRequest{IDs: []uint64{testData.ID}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
t.Fatalf("%+v", result)
|
||||
}
|
||||
|
||||
// zero id error test
|
||||
err = gohttp.Post(result, h.GetRequestURL("DeleteByIDs"), nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// get error test
|
||||
err = gohttp.Post(result, h.GetRequestURL("DeleteByIDs"), &types.DeleteUserExamplesByIDsRequest{IDs: []uint64{111}})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func Test_userExampleHandler_UpdateByID(t *testing.T) {
|
||||
h := newUserExampleHandler()
|
||||
defer h.Close()
|
||||
|
Reference in New Issue
Block a user