Skip to content

Commit

Permalink
test: add ut to test the input when creating evict-leader scheduler (#…
Browse files Browse the repository at this point in the history
…8768)

ref #4399

Signed-off-by: okJiang <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
okJiang and ti-chi-bot[bot] authored Nov 7, 2024
1 parent b19cec5 commit 39575d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 6 additions & 1 deletion server/api/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ func (h *schedulerHandler) CreateScheduler(w http.ResponseWriter, r *http.Reques
return
}
case types.GrantLeaderScheduler, types.EvictLeaderScheduler:
storeID, ok := input["store_id"].(float64)
_, ok := input["store_id"]
if !ok {
h.r.JSON(w, http.StatusBadRequest, "missing store id")
return
}
storeID, ok := input["store_id"].(float64)
if !ok {
h.r.JSON(w, http.StatusBadRequest, "please input a right store id")
return
}
var (
exist bool
err error
Expand Down
20 changes: 17 additions & 3 deletions tests/server/api/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,24 @@ func (suite *scheduleTestSuite) checkOriginAPI(cluster *tests.TestCluster) {

input := make(map[string]any)
input["name"] = "evict-leader-scheduler"
input["store_id"] = 1
body, err := json.Marshal(input)
re.NoError(err)
re.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body, tu.StatusOK(re)))
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body,
tu.Status(re, http.StatusBadRequest),
tu.StringEqual(re, "missing store id")),
)
input["store_id"] = "abc" // bad case
body, err = json.Marshal(input)
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body,
tu.Status(re, http.StatusBadRequest),
tu.StringEqual(re, "please input a right store id")),
)

input["store_id"] = 1
body, err = json.Marshal(input)
suite.NoError(err)
suite.NoError(tu.CheckPostJSON(tests.TestDialClient, urlPrefix, body, tu.StatusOK(re)))

suite.assertSchedulerExists(urlPrefix, "evict-leader-scheduler")
resp := make(map[string]any)
Expand Down

0 comments on commit 39575d2

Please sign in to comment.