MCPcopy Create free account
hub / github.com/coder/aibridge / TestPrettyPrintJSON

Function TestPrettyPrintJSON

intercept/apidump/apidump_test.go:226–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

224}
225
226func TestPrettyPrintJSON(t *testing.T) {
227 t.Parallel()
228
229 tests := []struct {
230 name string
231 input []byte
232 expected string
233 }{
234 {
235 name: "empty",
236 input: []byte{},
237 expected: "",
238 },
239 {
240 name: "valid JSON",
241 input: []byte(`{"key":"value"}`),
242 expected: "{\n \"key\": \"value\"\n}\n",
243 },
244 {
245 name: "invalid JSON returns as-is",
246 input: []byte("not json"),
247 expected: "not json",
248 },
249 // see: https://github.com/tidwall/pretty/blob/9090695766b652478676cc3e55bc3187056b1ff0/pretty.go#L117
250 // for input starting with "t" it would change it to "true", eg. "t_rest_of_the_string_is_discarded" -> "true"
251 // similar for inputs startrting with "f" and "n"
252 {
253 name: "invalid JSON edge case t",
254 input: []byte("test"),
255 expected: "test",
256 },
257 {
258 name: "invalid JSON edge case f",
259 input: []byte("f"),
260 expected: "f",
261 },
262 }
263
264 for _, tc := range tests {
265 t.Run(tc.name, func(t *testing.T) {
266 t.Parallel()
267 result := prettyPrintJSON(tc.input)
268 require.Equal(t, tc.expected, string(result))
269 })
270 }
271}
272
273func TestBridgedMiddleware_AllSensitiveRequestHeaders(t *testing.T) {
274 t.Parallel()

Callers

nothing calls this directly

Calls 1

prettyPrintJSONFunction · 0.85

Tested by

no test coverage detected