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

Function TestOpenAI_InjectAuthHeader

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

Source from the content-addressed store, hash-verified

326}
327
328func TestOpenAI_InjectAuthHeader(t *testing.T) {
329 t.Parallel()
330
331 provider := NewOpenAI(config.OpenAI{Key: "centralized-key"})
332
333 tests := []struct {
334 name string
335 presetHeaders map[string]string
336 wantAuthorization string
337 }{
338 {
339 name: "when no Authorization header is provided, inject centralized key",
340 presetHeaders: map[string]string{},
341 wantAuthorization: "Bearer centralized-key",
342 },
343 {
344 name: "when Authorization header is provided, do not overwrite it",
345 presetHeaders: map[string]string{"Authorization": "Bearer user-token"},
346 wantAuthorization: "Bearer user-token",
347 },
348 }
349
350 for _, tc := range tests {
351 t.Run(tc.name, func(t *testing.T) {
352 t.Parallel()
353
354 headers := http.Header{}
355 for k, v := range tc.presetHeaders {
356 headers.Set(k, v)
357 }
358
359 provider.InjectAuthHeader(&headers)
360
361 assert.Equal(t, tc.wantAuthorization, headers.Get("Authorization"))
362 })
363 }
364}
365
366func BenchmarkOpenAI_CreateInterceptor_ChatCompletions(b *testing.B) {
367 provider := NewOpenAI(config.OpenAI{

Callers

nothing calls this directly

Calls 3

InjectAuthHeaderMethod · 0.95
NewOpenAIFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected