mirror of
https://github.com/coder/coder.git
synced 2025-07-29 10:35:52 +00:00
feat: add support for WorkspaceUpdates to WebsocketDialer (#15534)
closes #14730 Adds support for WorkspaceUpdates to the WebsocketDialer. This allows us to dial the new endpoint added in #14847 and connect it up to a `tailnet.Controllers` to connect to all agents over the tailnet. I refactored the fakeWorkspaceUpdatesProvider to a mock and moved it to `tailnettest` so it could be more easily reused. The Mock is a little more full-featured.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/mock/gomock"
|
||||
"golang.org/x/xerrors"
|
||||
"tailscale.com/tailcfg"
|
||||
|
||||
@@ -236,8 +237,8 @@ func TestClientUserCoordinateeAuth(t *testing.T) {
|
||||
agentID2 := uuid.UUID{0x02}
|
||||
clientID := uuid.UUID{0x03}
|
||||
|
||||
updatesCh := make(chan *proto.WorkspaceUpdate, 1)
|
||||
updatesProvider := &fakeUpdatesProvider{ch: updatesCh}
|
||||
ctrl := gomock.NewController(t)
|
||||
updatesProvider := tailnettest.NewMockWorkspaceUpdatesProvider(ctrl)
|
||||
|
||||
fCoord, client := createUpdateService(t, ctx, clientID, updatesProvider)
|
||||
|
||||
@@ -271,8 +272,10 @@ func TestWorkspaceUpdates(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
ctrl := gomock.NewController(t)
|
||||
updatesProvider := tailnettest.NewMockWorkspaceUpdatesProvider(ctrl)
|
||||
mSub := tailnettest.NewMockSubscription(ctrl)
|
||||
updatesCh := make(chan *proto.WorkspaceUpdate, 1)
|
||||
updatesProvider := &fakeUpdatesProvider{ch: updatesCh}
|
||||
|
||||
clientID := uuid.UUID{0x03}
|
||||
wsID := uuid.UUID{0x04}
|
||||
@@ -293,6 +296,11 @@ func TestWorkspaceUpdates(t *testing.T) {
|
||||
DeletedAgents: []*proto.Agent{},
|
||||
}
|
||||
updatesCh <- expected
|
||||
updatesProvider.EXPECT().Subscribe(gomock.Any(), clientID).
|
||||
Times(1).
|
||||
Return(mSub, nil)
|
||||
mSub.EXPECT().Updates().MinTimes(1).Return(updatesCh)
|
||||
mSub.EXPECT().Close().Times(1).Return(nil)
|
||||
|
||||
updatesStream, err := client.WorkspaceUpdates(ctx, &proto.WorkspaceUpdatesRequest{
|
||||
WorkspaceOwnerId: tailnet.UUIDToByteSlice(clientID),
|
||||
@@ -354,34 +362,6 @@ func createUpdateService(t *testing.T, ctx context.Context, clientID uuid.UUID,
|
||||
return fCoord, client
|
||||
}
|
||||
|
||||
type fakeUpdatesProvider struct {
|
||||
ch chan *proto.WorkspaceUpdate
|
||||
}
|
||||
|
||||
func (*fakeUpdatesProvider) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeUpdatesProvider) Subscribe(context.Context, uuid.UUID) (tailnet.Subscription, error) {
|
||||
return &fakeSubscription{ch: f.ch}, nil
|
||||
}
|
||||
|
||||
type fakeSubscription struct {
|
||||
ch chan *proto.WorkspaceUpdate
|
||||
}
|
||||
|
||||
func (*fakeSubscription) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeSubscription) Updates() <-chan *proto.WorkspaceUpdate {
|
||||
return f.ch
|
||||
}
|
||||
|
||||
var _ tailnet.Subscription = (*fakeSubscription)(nil)
|
||||
|
||||
var _ tailnet.WorkspaceUpdatesProvider = (*fakeUpdatesProvider)(nil)
|
||||
|
||||
type fakeTunnelAuth struct{}
|
||||
|
||||
// AuthorizeTunnel implements tailnet.TunnelAuthorizer.
|
||||
|
Reference in New Issue
Block a user