(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestCopilot_CreateInterceptor(t *testing.T) { |
| 89 | t.Parallel() |
| 90 | |
| 91 | provider := NewCopilot(config.Copilot{}) |
| 92 | |
| 93 | t.Run("MissingAuthorizationHeader", func(t *testing.T) { |
| 94 | t.Parallel() |
| 95 | |
| 96 | body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}]}` |
| 97 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 98 | w := httptest.NewRecorder() |
| 99 | |
| 100 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 101 | |
| 102 | require.Error(t, err) |
| 103 | require.Nil(t, interceptor) |
| 104 | assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid") |
| 105 | }) |
| 106 | |
| 107 | t.Run("InvalidAuthorizationFormat", func(t *testing.T) { |
| 108 | t.Parallel() |
| 109 | |
| 110 | body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}]}` |
| 111 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 112 | req.Header.Set("Authorization", "InvalidFormat") |
| 113 | w := httptest.NewRecorder() |
| 114 | |
| 115 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 116 | |
| 117 | require.Error(t, err) |
| 118 | require.Nil(t, interceptor) |
| 119 | assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid") |
| 120 | }) |
| 121 | |
| 122 | t.Run("ChatCompletions_NonStreamingRequest_BlockingInterceptor", func(t *testing.T) { |
| 123 | t.Parallel() |
| 124 | |
| 125 | body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}], "stream": false}` |
| 126 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 127 | req.Header.Set("Authorization", "Bearer test-token") |
| 128 | w := httptest.NewRecorder() |
| 129 | |
| 130 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
| 131 | |
| 132 | require.NoError(t, err) |
| 133 | require.NotNil(t, interceptor) |
| 134 | assert.False(t, interceptor.Streaming()) |
| 135 | }) |
| 136 | |
| 137 | t.Run("ChatCompletions_StreamingRequest_StreamingInterceptor", func(t *testing.T) { |
| 138 | t.Parallel() |
| 139 | |
| 140 | body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}], "stream": true}` |
| 141 | req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body)) |
| 142 | req.Header.Set("Authorization", "Bearer test-token") |
| 143 | w := httptest.NewRecorder() |
| 144 | |
| 145 | interceptor, err := provider.CreateInterceptor(w, req, testTracer) |
nothing calls this directly
no test coverage detected