test(gateway): satisfy errcheck in request JSON tests

This commit is contained in:
lishuangqiang committed 2026-11-11 13:54:37 +08:00
1 parent 71ef577054
commit a8481f0dec
2 files changed
+26 -26

No files matched your search

@@ -11,27 +11,27 @@ import (
// 20 tools, a system prompt, and 40 messages with 4 content blocks each.
func claudeCodeLikeBody(cacheControls int, with1h bool) []byte {
var b strings.Builder
b.WriteString(`{"model":"claude-sonnet-5-5","max_tokens":32000,"stream":true,"tools":[`)
_, _ = b.WriteString(`{"model":"claude-sonnet-5-5","max_tokens":32000,"stream":true,"tools":[`)
for i := 0; i < 20; i++ {
if i > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
fmt.Fprintf(&b, `{"name":"tool_%d","description":"%s","input_schema":{"type":"object","properties":{"path":{"type":"string"}}}`, i, strings.Repeat("d", 40))
if i == 19 && cacheControls > 0 {
b.WriteString(`,"cache_control":{"type":"ephemeral"}`)
_, _ = b.WriteString(`,"cache_control":{"type":"ephemeral"}`)
cacheControls--
}
b.WriteByte('}')
_ = b.WriteByte('}')
}
b.WriteString(`],"system":[{"type":"text","text":"You are Claude Code, Anthropic's official CLI for Claude."`)
_, _ = b.WriteString(`],"system":[{"type":"text","text":"You are Claude Code, Anthropic's official CLI for Claude."`)
if cacheControls > 0 {
b.WriteString(`,"cache_control":{"type":"ephemeral"}`)
_, _ = b.WriteString(`,"cache_control":{"type":"ephemeral"}`)
cacheControls--
}
b.WriteString(`}],"messages":[`)
_, _ = b.WriteString(`}],"messages":[`)
for m := 0; m < 40; m++ {
if m > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
role := "user"
if m%2 == 1 {
@@ -40,7 +40,7 @@ func claudeCodeLikeBody(cacheControls int, with1h bool) []byte {
fmt.Fprintf(&b, `{"role":%q,"content":[`, role)
for c := 0; c < 4; c++ {
if c > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
fmt.Fprintf(&b, `{"type":"text","text":"%s"`, strings.Repeat("x", 120))
if m >= 38 && c == 3 && cacheControls > 0 {
@@ -51,11 +51,11 @@ func claudeCodeLikeBody(cacheControls int, with1h bool) []byte {
fmt.Fprintf(&b, `,"cache_control":{"type":"ephemeral"%s}`, ttl)
cacheControls--
}
b.WriteByte('}')
_ = b.WriteByte('}')
}
b.WriteString(`]}`)
_, _ = b.WriteString(`]}`)
}
b.WriteString(`]}`)
_, _ = b.WriteString(`]}`)
return []byte(b.String())
}
@@ -145,43 +145,43 @@ func randomCacheControlBody(rng *rand.Rand) []byte {
}
}
var b bytes.Buffer
b.WriteString(`{"model":"claude-sonnet"`)
_, _ = b.WriteString(`{"model":"claude-sonnet"`)
if rng.Intn(5) == 0 {
b.WriteString(`,"cache_control":{"type":"ephemeral","ttl":"1h"}`)
_, _ = b.WriteString(`,"cache_control":{"type":"ephemeral","ttl":"1h"}`)
}
if rng.Intn(2) == 0 {
b.WriteString(`,"tools":[`)
_, _ = b.WriteString(`,"tools":[`)
n := rng.Intn(4)
for i := 0; i < n; i++ {
if i > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
fmt.Fprintf(&b, `{"name":"tool_%d"%s}`, i, cc())
}
b.WriteByte(']')
_ = b.WriteByte(']')
}
if rng.Intn(2) == 0 {
b.WriteString(`,"system":[`)
_, _ = b.WriteString(`,"system":[`)
n := rng.Intn(3)
for i := 0; i < n; i++ {
if i > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
fmt.Fprintf(&b, `{"type":"text","text":"sys %d"%s}`, i, cc())
}
b.WriteByte(']')
_ = b.WriteByte(']')
}
b.WriteString(`,"messages":[`)
_, _ = b.WriteString(`,"messages":[`)
m := rng.Intn(4)
for i := 0; i < m; i++ {
if i > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
b.WriteString(`{"role":"user","content":[`)
_, _ = b.WriteString(`{"role":"user","content":[`)
c := rng.Intn(3) + 1
for j := 0; j < c; j++ {
if j > 0 {
b.WriteByte(',')
_ = b.WriteByte(',')
}
blockType := "text"
if rng.Intn(6) == 0 {
@@ -189,9 +189,9 @@ func randomCacheControlBody(rng *rand.Rand) []byte {
}
fmt.Fprintf(&b, `{"type":%q,"text":"m%d-%d"%s}`, blockType, i, j, cc())
}
b.WriteString(`]}`)
_, _ = b.WriteString(`]}`)
}
b.WriteString(`]}`)
_, _ = b.WriteString(`]}`)
return b.Bytes()
}