MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestProfilingOutputCompaction

Function TestProfilingOutputCompaction

duckdbservice/profiling_test.go:25–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23 }
24 return nil
25}
26
27func TestProfilingOutputCompaction(t *testing.T) {
28 // Simulate pretty-printed DuckDB profiling JSON with newlines
29 prettyJSON := `{
30 "latency": 0.5,
31 "cpu_time": 0.3,
32 "rows_returned": 42,
33 "children": [
34 {
35 "operator_name": "SEQ_SCAN",
36 "operator_timing": 0.2
37 }
38 ]
39}`
40
41 // Compact it like sendProfilingMetadata does
42 var compact bytes.Buffer
43 if err := json.Compact(&compact, []byte(prettyJSON)); err != nil {
44 t.Fatalf("json.Compact: %v", err)
45 }
46
47 result := compact.String()
48
49 // Must not contain newlines (gRPC metadata requirement)
50 if strings.Contains(result, "\n") {
51 t.Errorf("compacted JSON still contains newlines: %s", result)
52 }
53
54 // Must be valid JSON
55 var parsed map[string]interface{}
56 if err := json.Unmarshal([]byte(result), &parsed); err != nil {
57 t.Errorf("compacted JSON is not valid: %v", err)
58 }
59
60 // Must be safe for gRPC metadata
61 if err := validateGRPCMetadataValue(result); err != nil {
62 t.Errorf("compacted JSON is not gRPC-safe: %v", err)
63 }
64
65 // Key fields must survive compaction
66 if parsed["latency"] != 0.5 {
67 t.Errorf("expected latency 0.5, got %v", parsed["latency"])
68 }
69 if parsed["rows_returned"] != float64(42) {
70 t.Errorf("expected rows_returned 42, got %v", parsed["rows_returned"])
71 }
72}
73

Callers

nothing calls this directly

Calls 2

StringMethod · 0.45

Tested by

no test coverage detected