Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
34 lines
815 B
Go
34 lines
815 B
Go
package book
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestBindIDsAcceptsDocumentedIdsArrayQuery(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
ctx, _ := gin.CreateTestContext(httptest.NewRecorder())
|
|
ctx.Request = httptest.NewRequest("DELETE", "/book/deleteBookByIds?ids[]=1&ids[]=2", nil)
|
|
|
|
ids, ok := bindIDs(ctx)
|
|
if !ok {
|
|
t.Fatal("bindIDs() ok = false, want true")
|
|
}
|
|
if len(ids.Ids) != 2 || ids.Ids[0] != 1 || ids.Ids[1] != 2 {
|
|
t.Fatalf("ids = %#v, want [1 2]", ids.Ids)
|
|
}
|
|
}
|
|
|
|
func TestBindIDsRejectsEmptyIDList(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
ctx, _ := gin.CreateTestContext(httptest.NewRecorder())
|
|
ctx.Request = httptest.NewRequest("DELETE", "/book/deleteBookByIds", nil)
|
|
|
|
_, ok := bindIDs(ctx)
|
|
if ok {
|
|
t.Fatal("bindIDs() ok = true, want false")
|
|
}
|
|
}
|