(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestCopilot_CreateInterceptor(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | |
| 71 | provider := NewCopilot(config.Copilot{}) |
| 72 | |
| 73 | t.Run("MissingAuthorizationHeader", func(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | |
| 76 | body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}]}` |
| 77 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 78 | w := httptest.NewRecorder() |
| 79 | |
| 80 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 81 | |
| 82 | require.Error(t, err) |
| 83 | require.Nil(t, interceptor) |
| 84 | assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid") |
| 85 | }) |
| 86 | |
| 87 | t.Run("InvalidAuthorizationFormat", func(t *testing.T) { |
| 88 | t.Parallel() |
| 89 | |
| 90 | body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}]}` |
| 91 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 92 | req.Header.Set("Authorization", "InvalidFormat") |
| 93 | w := httptest.NewRecorder() |
| 94 | |
| 95 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 96 | |
| 97 | require.Error(t, err) |
| 98 | require.Nil(t, interceptor) |
| 99 | assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid") |
| 100 | }) |
| 101 | |
| 102 | t.Run("ChatCompletions_NonStreamingRequest_BlockingInterceptor", func(t *testing.T) { |
| 103 | t.Parallel() |
| 104 | |
| 105 | body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}], "stream": false}` |
| 106 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 107 | req.Header.Set("Authorization", "Bearer test-token") |
| 108 | w := httptest.NewRecorder() |
| 109 | |
| 110 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 111 | |
| 112 | require.NoError(t, err) |
| 113 | require.NotNil(t, interceptor) |
| 114 | assert.False(t, interceptor.Streaming()) |
| 115 | }) |
| 116 | |
| 117 | t.Run("ChatCompletions_StreamingRequest_StreamingInterceptor", func(t *testing.T) { |
| 118 | t.Parallel() |
| 119 | |
| 120 | body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}], "stream": true}` |
| 121 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 122 | req.Header.Set("Authorization", "Bearer test-token") |
| 123 | w := httptest.NewRecorder() |
| 124 | |
| 125 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
nothing calls this directly
no test coverage detected