(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func 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 | |
| 366 | func BenchmarkOpenAI_CreateInterceptor_ChatCompletions(b *testing.B) { |
| 367 | provider := NewOpenAI(config.OpenAI{ |
nothing calls this directly
no test coverage detected