Files
CLIProxyAPI/internal/util/gjson_test.go
Luis Pater 53c1e7e2dd perf(util): introduce GetGJSONBytesNoCopy for efficient JSON parsing without data duplication
- Added `GetGJSONBytesNoCopy` in `internal/util` for safe, no-copy JSON parse operations leveraging `unsafe`.
- Replaced `gjson.GetBytes` with the new helper in key payload processing paths (`kimi_executor`, `vertex_payload_helpers`, etc.) to improve performance.
- Added unit tests for behavior validation, including edge cases with empty input.
2026-07-20 15:37:55 +08:00

18 lines
546 B
Go

package util
import "testing"
func TestGetGJSONBytesNoCopy(t *testing.T) {
input := []byte(`{"request":{"contents":[{"role":"user"}]}}`)
contents := GetGJSONBytesNoCopy(input, "request.contents")
if !contents.IsArray() || contents.Get("0.role").String() != "user" {
t.Fatalf("request.contents = %s, want user content array", contents.Raw)
}
}
func TestGetGJSONBytesNoCopyEmptyInput(t *testing.T) {
if result := GetGJSONBytesNoCopy(nil, "contents"); result.Exists() {
t.Fatalf("empty input result = %s, want missing", result.Raw)
}
}