补充AI下次时间接口异常入参与验证记录
This commit is contained in:
@@ -75,7 +75,11 @@ func (h *SmokeHandler) GetNextSmokeTime(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
mode := strings.ToLower(strings.TrimSpace(c.DefaultQuery("mode", "auto")))
|
||||
mode, ok := resolveNextSmokeMode(c.Query("mode"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "mode 参数错误,应为 auto|ai|default"))
|
||||
return
|
||||
}
|
||||
|
||||
formatPtr := func(t *time.Time) string {
|
||||
if t == nil {
|
||||
@@ -194,6 +198,20 @@ func dateOnlyLocal(t time.Time) time.Time {
|
||||
return time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, time.Local)
|
||||
}
|
||||
|
||||
func resolveNextSmokeMode(raw string) (string, bool) {
|
||||
mode := strings.ToLower(strings.TrimSpace(raw))
|
||||
if mode == "" {
|
||||
return "auto", true
|
||||
}
|
||||
|
||||
switch mode {
|
||||
case "auto", "ai", "default":
|
||||
return mode, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
type nextSmokeDefaultResponse struct {
|
||||
LastSmokeAt string `json:"last_smoke_at,omitempty"`
|
||||
NextSmokeAt string `json:"next_smoke_at,omitempty"`
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package handler
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestResolveNextSmokeMode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
mode string
|
||||
ok bool
|
||||
}{
|
||||
{name: "默认值", input: "", mode: "auto", ok: true},
|
||||
{name: "自动模式", input: "auto", mode: "auto", ok: true},
|
||||
{name: "AI模式", input: "ai", mode: "ai", ok: true},
|
||||
{name: "默认策略模式", input: "default", mode: "default", ok: true},
|
||||
{name: "大小写兼容", input: "AI", mode: "ai", ok: true},
|
||||
{name: "非法值", input: "fast", mode: "", ok: false},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
gotMode, gotOK := resolveNextSmokeMode(tc.input)
|
||||
if gotMode != tc.mode || gotOK != tc.ok {
|
||||
t.Fatalf("resolveNextSmokeMode(%q)=(%q,%v), want=(%q,%v)", tc.input, gotMode, gotOK, tc.mode, tc.ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user