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

Function TestCopilot_CreateInterceptor

provider/copilot_test.go:88–317  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func 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)

Callers

nothing calls this directly

Calls 10

CreateInterceptorMethod · 0.95
NewCopilotFunction · 0.85
HeaderMethod · 0.80
GetMethod · 0.80
StreamingMethod · 0.65
SetupMethod · 0.65
ProcessRequestMethod · 0.65
ErrorMethod · 0.45
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected