@@ -107,19 +107,14 @@ func TestAnthropicMessages(t *testing.T) {
107
107
BaseURL : serpent .String (srv .URL ),
108
108
Key : serpent .String (sessionToken ),
109
109
},
110
- }, "127.0.0.1:0" , logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
110
+ }, logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
111
111
return coderdClient , true
112
112
}, nil )
113
113
require .NoError (t , err )
114
114
115
- go func () {
116
- assert .NoError (t , b .Serve ())
117
- }()
118
- // Wait for bridge to come up.
119
- require .Eventually (t , func () bool { return len (b .Addr ()) > 0 }, testutil .WaitLong , testutil .IntervalFast )
120
-
115
+ mockSrv := httptest .NewServer (b .Handler ())
121
116
// Make API call to aibridge for Anthropic /v1/messages
122
- req := createAnthropicMessagesReq (t , "http://" + b . Addr () , reqBody )
117
+ req := createAnthropicMessagesReq (t , mockSrv . URL , reqBody )
123
118
client := & http.Client {}
124
119
resp , err := client .Do (req )
125
120
require .NoError (t , err )
@@ -214,19 +209,14 @@ func TestOpenAIChatCompletions(t *testing.T) {
214
209
BaseURL : serpent .String (srv .URL ),
215
210
Key : serpent .String (sessionToken ),
216
211
},
217
- }, "127.0.0.1:0" , logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
212
+ }, logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
218
213
return coderdClient , true
219
214
}, nil )
220
215
require .NoError (t , err )
221
216
222
- go func () {
223
- assert .NoError (t , b .Serve ())
224
- }()
225
- // Wait for bridge to come up.
226
- require .Eventually (t , func () bool { return len (b .Addr ()) > 0 }, testutil .WaitLong , testutil .IntervalFast )
227
-
217
+ mockSrv := httptest .NewServer (b .Handler ())
228
218
// Make API call to aibridge for OpenAI /v1/chat/completions
229
- req := createOpenAIChatCompletionsReq (t , "http://" + b . Addr () , reqBody )
219
+ req := createOpenAIChatCompletionsReq (t , mockSrv . URL , reqBody )
230
220
231
221
client := & http.Client {}
232
222
resp , err := client .Do (req )
@@ -289,7 +279,7 @@ func TestSimple(t *testing.T) {
289
279
BaseURL : serpent .String (addr ),
290
280
Key : serpent .String (sessionToken ),
291
281
},
292
- }, "127.0.0.1:0" , logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
282
+ }, logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
293
283
return client , true
294
284
}, nil )
295
285
},
@@ -306,7 +296,7 @@ func TestSimple(t *testing.T) {
306
296
BaseURL : serpent .String (addr ),
307
297
Key : serpent .String (sessionToken ),
308
298
},
309
- }, "127.0.0.1:0" , logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
299
+ }, logger , func () (proto.DRPCAIBridgeDaemonClient , bool ) {
310
300
return client , true
311
301
}, nil )
312
302
},
@@ -355,14 +345,9 @@ func TestSimple(t *testing.T) {
355
345
b , err := tc .configureFunc (srv .URL , coderdClient )
356
346
require .NoError (t , err )
357
347
358
- go func () {
359
- assert .NoError (t , b .Serve ())
360
- }()
361
- // Wait for bridge to come up.
362
- require .Eventually (t , func () bool { return len (b .Addr ()) > 0 }, testutil .WaitLong , testutil .IntervalFast )
363
-
348
+ mockSrv := httptest .NewServer (b .Handler ())
364
349
// When: calling the "API server" with the fixture's request body.
365
- req := tc .createRequest (t , "http://" + b . Addr () , reqBody )
350
+ req := tc .createRequest (t , mockSrv . URL , reqBody )
366
351
client := & http.Client {}
367
352
resp , err := client .Do (req )
368
353
require .NoError (t , err )
0 commit comments