fix: 校验端默认延迟不超过调度上限
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package admin_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateRejectsDefaultDelayOverMax(t *testing.T) {
|
||||
_, srv, client, _, _ := setupEndpoints(t)
|
||||
body := `{"id":"dly-c","name":"延迟","login_password":"password1","default_delay_seconds":31536001}`
|
||||
res := postJSON(t, client, srv.URL+"/api/admin/endpoints", body, csrfHeaders())
|
||||
env := decodeEnv(t, res)
|
||||
if res.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("want 400 got %d %+v", res.StatusCode, env)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatchRejectsDefaultDelayOverMax(t *testing.T) {
|
||||
_, srv, client, _, _ := setupEndpoints(t)
|
||||
res := postJSON(t, client, srv.URL+"/api/admin/endpoints",
|
||||
`{"id":"dly-p","name":"延迟","login_password":"password1"}`, csrfHeaders())
|
||||
env := decodeEnv(t, res)
|
||||
if res.StatusCode != 200 || !env.OK {
|
||||
t.Fatalf("create: %d %+v", res.StatusCode, env)
|
||||
}
|
||||
res = doReq(t, client, http.MethodPatch, srv.URL+"/api/admin/endpoints/dly-p",
|
||||
`{"default_delay_seconds":31536001}`, csrfHeaders())
|
||||
env = decodeEnv(t, res)
|
||||
if res.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("want 400 got %d %+v", res.StatusCode, env)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportRejectsDefaultDelayOverMax(t *testing.T) {
|
||||
_, srv, client, _, _ := setupEndpoints(t)
|
||||
csvBody := "" +
|
||||
"id,name,login_password,talk_password,default_delay_seconds,remark\n" +
|
||||
"dly-i,甲,password1,,31536001,\n"
|
||||
res := postImportCSV(t, client, srv.URL, csvBody)
|
||||
raw, _ := io.ReadAll(res.Body)
|
||||
_ = res.Body.Close()
|
||||
if res.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("want 400 got %d body=%s", res.StatusCode, raw)
|
||||
}
|
||||
var parsed struct {
|
||||
Data *struct {
|
||||
Errors []struct {
|
||||
Line int `json:"line"`
|
||||
Reason string `json:"reason"`
|
||||
} `json:"errors"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &parsed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if parsed.Data == nil || len(parsed.Data.Errors) == 0 {
|
||||
t.Fatalf("want row error, body=%s", raw)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user