Skip to content

Commit ed91ba8

Browse files
committed
fix tests
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent 8e88565 commit ed91ba8

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

aibridged/bridge.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"net"
1110
"net/http"
1211
"net/http/httputil"
1312
"net/url"
@@ -1328,15 +1327,6 @@ type AnthropicErrorResponse struct {
13281327
StatusCode int `json:"-"`
13291328
}
13301329

1331-
func (b *Bridge) Serve() error {
1332-
list, err := net.Listen("tcp", b.httpSrv.Addr)
1333-
if err != nil {
1334-
return xerrors.Errorf("listen: %w", err)
1335-
}
1336-
1337-
return b.httpSrv.Serve(list) // TODO: TLS.
1338-
}
1339-
13401330
// logConnectionError logs connection errors with appropriate severity
13411331
func (b *Bridge) logConnectionError(ctx context.Context, err error, operation string) {
13421332
if isConnectionError(err) {

aibridged/bridge_test.go

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,14 @@ func TestAnthropicMessages(t *testing.T) {
107107
BaseURL: serpent.String(srv.URL),
108108
Key: serpent.String(sessionToken),
109109
},
110-
}, "127.0.0.1:0", logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
110+
}, logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
111111
return coderdClient, true
112112
}, nil)
113113
require.NoError(t, err)
114114

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())
121116
// Make API call to aibridge for Anthropic /v1/messages
122-
req := createAnthropicMessagesReq(t, "http://"+b.Addr(), reqBody)
117+
req := createAnthropicMessagesReq(t, mockSrv.URL, reqBody)
123118
client := &http.Client{}
124119
resp, err := client.Do(req)
125120
require.NoError(t, err)
@@ -214,19 +209,14 @@ func TestOpenAIChatCompletions(t *testing.T) {
214209
BaseURL: serpent.String(srv.URL),
215210
Key: serpent.String(sessionToken),
216211
},
217-
}, "127.0.0.1:0", logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
212+
}, logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
218213
return coderdClient, true
219214
}, nil)
220215
require.NoError(t, err)
221216

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())
228218
// 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)
230220

231221
client := &http.Client{}
232222
resp, err := client.Do(req)
@@ -289,7 +279,7 @@ func TestSimple(t *testing.T) {
289279
BaseURL: serpent.String(addr),
290280
Key: serpent.String(sessionToken),
291281
},
292-
}, "127.0.0.1:0", logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
282+
}, logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
293283
return client, true
294284
}, nil)
295285
},
@@ -306,7 +296,7 @@ func TestSimple(t *testing.T) {
306296
BaseURL: serpent.String(addr),
307297
Key: serpent.String(sessionToken),
308298
},
309-
}, "127.0.0.1:0", logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
299+
}, logger, func() (proto.DRPCAIBridgeDaemonClient, bool) {
310300
return client, true
311301
}, nil)
312302
},
@@ -355,14 +345,9 @@ func TestSimple(t *testing.T) {
355345
b, err := tc.configureFunc(srv.URL, coderdClient)
356346
require.NoError(t, err)
357347

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())
364349
// 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)
366351
client := &http.Client{}
367352
resp, err := client.Do(req)
368353
require.NoError(t, err)

0 commit comments

Comments
 (0)