MCPcopy
hub / github.com/QuantumNous/new-api / newAuthenticatedContext

Function newAuthenticatedContext

controller/token_test.go:184–206  ·  view source on GitHub ↗
(t *testing.T, method string, target string, body any, userID int)

Source from the content-addressed store, hash-verified

182}
183
184func newAuthenticatedContext(t *testing.T, method string, target string, body any, userID int) (*gin.Context, *httptest.ResponseRecorder) {
185 t.Helper()
186
187 var requestBody *bytes.Reader
188 if body != nil {
189 payload, err := common.Marshal(body)
190 if err != nil {
191 t.Fatalf("failed to marshal request body: %v", err)
192 }
193 requestBody = bytes.NewReader(payload)
194 } else {
195 requestBody = bytes.NewReader(nil)
196 }
197
198 recorder := httptest.NewRecorder()
199 ctx, _ := gin.CreateTestContext(recorder)
200 ctx.Request = httptest.NewRequest(method, target, requestBody)
201 if body != nil {
202 ctx.Request.Header.Set("Content-Type", "application/json")
203 }
204 ctx.Set("id", userID)
205 return ctx, recorder
206}
207
208func decodeAPIResponse(t *testing.T, recorder *httptest.ResponseRecorder) tokenAPIResponse {
209 t.Helper()

Calls 2

MarshalFunction · 0.92
SetMethod · 0.80

Tested by

no test coverage detected