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

Function TestOpenAI_CreateInterceptor

provider/openai_test.go:198–326  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

196}
197
198func TestOpenAI_CreateInterceptor(t *testing.T) {
199 t.Parallel()
200
201 tests := []struct {
202 name string
203 route string
204 requestBody string
205 responseBody string
206 setHeaders map[string]string
207 wantAuthorization string
208 wantCredentialKind intercept.CredentialKind
209 wantCredentialHint string
210 }{
211 {
212 name: "ChatCompletions_BYOK",
213 route: routeChatCompletions,
214 requestBody: `{"model": "gpt-4", "messages": [{"role": "user", "content": "hello"}], "stream": false}`,
215 responseBody: chatCompletionResponse,
216 setHeaders: map[string]string{"Authorization": "Bearer user-token"},
217 wantAuthorization: "Bearer user-token",
218 wantCredentialKind: intercept.CredentialKindBYOK,
219 wantCredentialHint: "us...en",
220 },
221 {
222 name: "ChatCompletions_Centralized",
223 route: routeChatCompletions,
224 requestBody: `{"model": "gpt-4", "messages": [{"role": "user", "content": "hello"}], "stream": false}`,
225 responseBody: chatCompletionResponse,
226 setHeaders: map[string]string{},
227 wantAuthorization: "Bearer centralized-key",
228 wantCredentialKind: intercept.CredentialKindCentralized,
229 wantCredentialHint: "ce...ey",
230 },
231 {
232 name: "Responses_BYOK",
233 route: routeResponses,
234 requestBody: `{"model": "gpt-5", "input": "hello", "stream": false}`,
235 responseBody: responsesAPIResponse,
236 setHeaders: map[string]string{"Authorization": "Bearer user-token"},
237 wantAuthorization: "Bearer user-token",
238 wantCredentialKind: intercept.CredentialKindBYOK,
239 wantCredentialHint: "us...en",
240 },
241 {
242 name: "Responses_Centralized",
243 route: routeResponses,
244 requestBody: `{"model": "gpt-5", "input": "hello", "stream": false}`,
245 responseBody: responsesAPIResponse,
246 setHeaders: map[string]string{},
247 wantAuthorization: "Bearer centralized-key",
248 wantCredentialKind: intercept.CredentialKindCentralized,
249 wantCredentialHint: "ce...ey",
250 },
251 // X-Api-Key should not appear in production since clients use Authorization,
252 // but ensure it is stripped if it does arrive.
253 {
254 name: "ChatCompletions_BYOK_XApiKeyStripped",
255 route: routeChatCompletions,

Callers

nothing calls this directly

Calls 10

RoutePrefixMethod · 0.95
CreateInterceptorMethod · 0.95
NewOpenAIFunction · 0.85
HeaderMethod · 0.80
GetMethod · 0.80
CredentialMethod · 0.65
SetupMethod · 0.65
ProcessRequestMethod · 0.65
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected