MCPcopy Index your code
hub / github.com/coder/coder / TestOpenAI_CreateInterceptor

Function TestOpenAI_CreateInterceptor

aibridge/provider/openai_internal_test.go:201–333  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

RoutePrefixMethod · 0.95
CreateInterceptorMethod · 0.95
NewOpenAIFunction · 0.70
RunMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
CleanupMethod · 0.65
CredentialMethod · 0.65
SetupMethod · 0.65
ProcessRequestMethod · 0.65
GetMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected