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

Function TestNewRequestPayload

intercept/responses/reqpayload_test.go:19–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewRequestPayload(t *testing.T) {
20 t.Parallel()
21
22 payloadWithWrongTypes := []byte(`{"model":123,"stream":"yes","input":42,"background":"nope"}`)
23 tests := []struct {
24 name string
25 raw []byte
26 want []byte
27 model string
28 stream bool
29 background bool
30 err string
31 }{
32 {
33 name: "empty payload",
34 raw: nil,
35 want: nil,
36 err: "empty request body",
37 },
38 {
39 name: "invalid json",
40 raw: []byte(`{broken`),
41 want: nil,
42 err: "invalid JSON payload",
43 },
44 {
45 // RequestPayload just checks for JSON validity,
46 // schema errors are not surfaced here and
47 // the original body is preserved for upstream handling
48 // similar to how reverse proxy would behave.
49 name: "wrong field types still wrap",
50 raw: payloadWithWrongTypes,
51 want: payloadWithWrongTypes,
52 model: "123",
53 stream: false,
54 background: false,
55 },
56 }
57
58 for _, tc := range tests {
59 t.Run(tc.name, func(t *testing.T) {
60 t.Parallel()
61
62 payload, err := NewRequestPayload(tc.raw)
63
64 if tc.err != "" {
65 require.ErrorContains(t, err, tc.err)
66 assert.Nil(t, payload)
67 return
68 }
69
70 require.NoError(t, err)
71 require.NotNil(t, payload)
72 assert.EqualValues(t, tc.want, payload)
73 assert.Equal(t, tc.model, payload.model())
74 assert.Equal(t, tc.stream, payload.Stream())
75 assert.Equal(t, tc.background, payload.background())
76 })

Callers

nothing calls this directly

Calls 4

modelMethod · 0.95
StreamMethod · 0.95
backgroundMethod · 0.95
NewRequestPayloadFunction · 0.70

Tested by

no test coverage detected