feat: deliver authenticated task APIs, SDK and P1 regression
This commit is contained in:
42
pulse/service/service_test.go
Normal file
42
pulse/service/service_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||||
pulse "git.yuntuo.hk/k2safe/orbit/pulse/model"
|
||||
)
|
||||
|
||||
func TestSubmitNormalizationAndBounds(t *testing.T) {
|
||||
base := SubmitInput{QueueID: core.ID(strings.Repeat("1", 32)), Handler: "file.convert", HandlerVersion: "v1", PayloadVersion: "v1", Payload: json.RawMessage(`{"v":9007199254740993}`)}
|
||||
out, err := NormalizeSubmit(base)
|
||||
if err != nil || out.RecoverySafety != pulse.RecoveryReconcileOnly || out.Retry.MaxAttempts != 1 || out.TaskTimeoutMS != 86400000 {
|
||||
t.Fatalf("defaults %+v %v", out, err)
|
||||
}
|
||||
for name, change := range map[string]func(*SubmitInput){
|
||||
"missing queue": func(v *SubmitInput) { v.QueueID = "" },
|
||||
"missing handler version": func(v *SubmitInput) { v.HandlerVersion = "" },
|
||||
"null payload": func(v *SubmitInput) { v.Payload = json.RawMessage("null") },
|
||||
"oversize payload": func(v *SubmitInput) { v.Payload = json.RawMessage(`"` + strings.Repeat("a", 256<<10) + `"`) },
|
||||
"unbounded attempts": func(v *SubmitInput) { v.Retry.MaxAttempts = 101 },
|
||||
"unknown recovery policy": func(v *SubmitInput) { v.RecoverySafety = "UNKNOWN" },
|
||||
"excess timeout": func(v *SubmitInput) { v.TaskTimeoutMS = 30*86400000 + 1 },
|
||||
"sub-microsecond time": func(v *SubmitInput) { now := time.Date(2026, 1, 1, 0, 0, 0, 1, time.UTC); v.AvailableAt = &now },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
in := base
|
||||
change(&in)
|
||||
if _, err := NormalizeSubmit(in); err == nil {
|
||||
t.Fatal("accepted invalid input")
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, key := range []string{"", strings.Repeat("a", 129), "with space", "带中文", "line\n"} {
|
||||
if ValidateKey(key) == nil {
|
||||
t.Fatal("accepted invalid key")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user