(t *testing.T)
| 267 | } |
| 268 | |
| 269 | func TestWorkspaceUpdates(t *testing.T) { |
| 270 | t.Parallel() |
| 271 | |
| 272 | ctx := testutil.Context(t, testutil.WaitShort) |
| 273 | ctrl := gomock.NewController(t) |
| 274 | updatesProvider := tailnettest.NewMockWorkspaceUpdatesProvider(ctrl) |
| 275 | mSub := tailnettest.NewMockSubscription(ctrl) |
| 276 | updatesCh := make(chan *proto.WorkspaceUpdate, 1) |
| 277 | |
| 278 | clientID := uuid.UUID{0x03} |
| 279 | wsID := uuid.UUID{0x04} |
| 280 | |
| 281 | _, client := createUpdateService(t, ctx, clientID, updatesProvider) |
| 282 | |
| 283 | // Workspace updates |
| 284 | expected := &proto.WorkspaceUpdate{ |
| 285 | UpsertedWorkspaces: []*proto.Workspace{ |
| 286 | { |
| 287 | Id: tailnet.UUIDToByteSlice(wsID), |
| 288 | Name: "ws1", |
| 289 | Status: proto.Workspace_RUNNING, |
| 290 | }, |
| 291 | }, |
| 292 | UpsertedAgents: []*proto.Agent{}, |
| 293 | DeletedWorkspaces: []*proto.Workspace{}, |
| 294 | DeletedAgents: []*proto.Agent{}, |
| 295 | } |
| 296 | updatesCh <- expected |
| 297 | updatesProvider.EXPECT().Subscribe(gomock.Any(), clientID). |
| 298 | Times(1). |
| 299 | Return(mSub, nil) |
| 300 | mSub.EXPECT().Updates().MinTimes(1).Return(updatesCh) |
| 301 | mSub.EXPECT().Close().Times(1).Return(nil) |
| 302 | |
| 303 | updatesStream, err := client.WorkspaceUpdates(ctx, &proto.WorkspaceUpdatesRequest{ |
| 304 | WorkspaceOwnerId: tailnet.UUIDToByteSlice(clientID), |
| 305 | }) |
| 306 | require.NoError(t, err) |
| 307 | defer updatesStream.Close() |
| 308 | |
| 309 | updates, err := updatesStream.Recv() |
| 310 | require.NoError(t, err) |
| 311 | require.Len(t, updates.GetUpsertedWorkspaces(), 1) |
| 312 | require.Equal(t, expected.GetUpsertedWorkspaces()[0].GetName(), updates.GetUpsertedWorkspaces()[0].GetName()) |
| 313 | require.Equal(t, expected.GetUpsertedWorkspaces()[0].GetStatus(), updates.GetUpsertedWorkspaces()[0].GetStatus()) |
| 314 | require.Equal(t, expected.GetUpsertedWorkspaces()[0].GetId(), updates.GetUpsertedWorkspaces()[0].GetId()) |
| 315 | } |
| 316 | |
| 317 | //nolint:revive // t takes precedence |
| 318 | func createUpdateService(t *testing.T, ctx context.Context, clientID uuid.UUID, updates tailnet.WorkspaceUpdatesProvider) (*tailnettest.FakeCoordinator, proto.DRPCTailnetClient) { |
nothing calls this directly
no test coverage detected