|
1 | 1 | package tailnet_test
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "context" |
5 | 4 | "io"
|
6 | 5 | "net"
|
7 |
| - "net/http" |
8 | 6 | "sync/atomic"
|
9 | 7 | "testing"
|
10 | 8 | "time"
|
11 | 9 |
|
| 10 | + "github.com/google/uuid" |
| 11 | + "github.com/stretchr/testify/require" |
12 | 12 | "golang.org/x/xerrors"
|
13 | 13 | "tailscale.com/tailcfg"
|
14 | 14 |
|
15 |
| - "github.com/google/uuid" |
16 |
| - |
17 | 15 | "cdr.dev/slog"
|
18 | 16 | "cdr.dev/slog/sloggers/slogtest"
|
| 17 | + "github.com/coder/coder/v2/tailnet" |
19 | 18 | "github.com/coder/coder/v2/tailnet/proto"
|
| 19 | + "github.com/coder/coder/v2/tailnet/tailnettest" |
20 | 20 | "github.com/coder/coder/v2/testutil"
|
21 |
| - |
22 |
| - "github.com/stretchr/testify/require" |
23 |
| - |
24 |
| - "github.com/coder/coder/v2/tailnet" |
25 | 21 | )
|
26 | 22 |
|
27 | 23 | func TestClientService_ServeClient_V2(t *testing.T) {
|
28 | 24 | t.Parallel()
|
29 |
| - fCoord := NewFakeCoordinator() |
| 25 | + fCoord := tailnettest.NewFakeCoordinator() |
30 | 26 | var coord tailnet.Coordinator = fCoord
|
31 | 27 | coordPtr := atomic.Pointer[tailnet.Coordinator]{}
|
32 | 28 | coordPtr.Store(&coord)
|
@@ -107,7 +103,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
|
107 | 103 |
|
108 | 104 | func TestClientService_ServeClient_V1(t *testing.T) {
|
109 | 105 | t.Parallel()
|
110 |
| - fCoord := NewFakeCoordinator() |
| 106 | + fCoord := tailnettest.NewFakeCoordinator() |
111 | 107 | var coord tailnet.Coordinator = fCoord
|
112 | 108 | coordPtr := atomic.Pointer[tailnet.Coordinator]{}
|
113 | 109 | coordPtr.Store(&coord)
|
@@ -144,76 +140,3 @@ func TestClientService_ServeClient_V1(t *testing.T) {
|
144 | 140 | err = testutil.RequireRecvCtx(ctx, t, errCh)
|
145 | 141 | require.ErrorIs(t, err, expectedError)
|
146 | 142 | }
|
147 |
| - |
148 |
| -type FakeCoordinator struct { |
149 |
| - CoordinateCalls chan *FakeCoordinate |
150 |
| - ServeClientCalls chan *FakeServeClient |
151 |
| -} |
152 |
| - |
153 |
| -func (*FakeCoordinator) ServeHTTPDebug(http.ResponseWriter, *http.Request) { |
154 |
| - panic("unimplemented") |
155 |
| -} |
156 |
| - |
157 |
| -func (*FakeCoordinator) Node(uuid.UUID) *tailnet.Node { |
158 |
| - panic("unimplemented") |
159 |
| -} |
160 |
| - |
161 |
| -func (f *FakeCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error { |
162 |
| - errCh := make(chan error) |
163 |
| - f.ServeClientCalls <- &FakeServeClient{ |
164 |
| - Conn: conn, |
165 |
| - ID: id, |
166 |
| - Agent: agent, |
167 |
| - ErrCh: errCh, |
168 |
| - } |
169 |
| - return <-errCh |
170 |
| -} |
171 |
| - |
172 |
| -func (*FakeCoordinator) ServeAgent(net.Conn, uuid.UUID, string) error { |
173 |
| - panic("unimplemented") |
174 |
| -} |
175 |
| - |
176 |
| -func (*FakeCoordinator) Close() error { |
177 |
| - panic("unimplemented") |
178 |
| -} |
179 |
| - |
180 |
| -func (*FakeCoordinator) ServeMultiAgent(uuid.UUID) tailnet.MultiAgentConn { |
181 |
| - panic("unimplemented") |
182 |
| -} |
183 |
| - |
184 |
| -func (f *FakeCoordinator) Coordinate(ctx context.Context, id uuid.UUID, name string, a tailnet.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) { |
185 |
| - reqs := make(chan *proto.CoordinateRequest, 100) |
186 |
| - resps := make(chan *proto.CoordinateResponse, 100) |
187 |
| - f.CoordinateCalls <- &FakeCoordinate{ |
188 |
| - Ctx: ctx, |
189 |
| - ID: id, |
190 |
| - Name: name, |
191 |
| - Auth: a, |
192 |
| - Reqs: reqs, |
193 |
| - Resps: resps, |
194 |
| - } |
195 |
| - return reqs, resps |
196 |
| -} |
197 |
| - |
198 |
| -func NewFakeCoordinator() *FakeCoordinator { |
199 |
| - return &FakeCoordinator{ |
200 |
| - CoordinateCalls: make(chan *FakeCoordinate, 100), |
201 |
| - ServeClientCalls: make(chan *FakeServeClient, 100), |
202 |
| - } |
203 |
| -} |
204 |
| - |
205 |
| -type FakeCoordinate struct { |
206 |
| - Ctx context.Context |
207 |
| - ID uuid.UUID |
208 |
| - Name string |
209 |
| - Auth tailnet.TunnelAuth |
210 |
| - Reqs chan *proto.CoordinateRequest |
211 |
| - Resps chan *proto.CoordinateResponse |
212 |
| -} |
213 |
| - |
214 |
| -type FakeServeClient struct { |
215 |
| - Conn net.Conn |
216 |
| - ID uuid.UUID |
217 |
| - Agent uuid.UUID |
218 |
| - ErrCh chan error |
219 |
| -} |
0 commit comments