MCPcopy Index your code
hub / github.com/coder/coder / TestWatcher_PublishChanges

Function TestWatcher_PublishChanges

coderd/workspaceconnwatcher/watcher_test.go:290–414  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestWatcher_PublishChanges(t *testing.T) {
291 t.Parallel()
292
293 ctx := testutil.Context(t, testutil.WaitShort)
294 logger := testutil.Logger(t)
295 h := newHarness(ctx, t, logger)
296
297 // Initial build update, job is running.
298 build0 := h.db.EXPECT().GetLatestWorkspaceBuildWithStatusByWorkspaceID(gomock.Any(), h.workspace.ID).
299 Times(1).
300 Return(database.GetLatestWorkspaceBuildWithStatusByWorkspaceIDRow{
301 Transition: database.WorkspaceTransitionStart,
302 BuildNumber: 1,
303 JobStatus: database.ProvisionerJobStatusRunning,
304 WorkspaceTable: database.WorkspaceTable{
305 ID: h.workspace.ID,
306 OwnerID: userID,
307 OrganizationID: orgID,
308 },
309 }, nil)
310
311 dec, err := h.Dial(ctx, "wss://local.test/")
312 require.NoError(t, err)
313 defer func() {
314 _ = dec.Close()
315 }()
316 events := dec.Chan()
317
318 e0 := testutil.RequireReceive(ctx, t, events)
319 require.Equal(t, workspacesdk.ConnectionWatchEvent{
320 BuildUpdate: &workspacesdk.BuildUpdate{
321 Transition: codersdk.WorkspaceTransitionStart,
322 JobStatus: codersdk.ProvisionerJobRunning,
323 },
324 }, e0)
325
326 // Since job is still running, we don't immediately query for agents. Next we set up the db queries and send in an
327 // update over the pubsub to kick a new query.
328 build1 := h.db.EXPECT().GetLatestWorkspaceBuildWithStatusByWorkspaceID(gomock.Any(), h.workspace.ID).
329 After(build0).
330 Times(1).
331 Return(database.GetLatestWorkspaceBuildWithStatusByWorkspaceIDRow{
332 Transition: database.WorkspaceTransitionStart,
333 BuildNumber: 1,
334 JobStatus: database.ProvisionerJobStatusSucceeded,
335 WorkspaceTable: database.WorkspaceTable{
336 ID: h.workspace.ID,
337 OwnerID: userID,
338 OrganizationID: orgID,
339 },
340 }, nil)
341 // RBAC check for agent query
342 h.db.EXPECT().GetWorkspaceByID(gomock.Any(), h.workspace.ID).
343 After(build1).
344 Times(2). // these queries are identical between the initial and the update below
345 Return(h.workspace, nil)
346 agent0 := h.db.EXPECT().GetWorkspaceAgentsByWorkspaceAndBuildNumber(
347 gomock.Any(),

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
LoggerFunction · 0.92
RequireReceiveFunction · 0.92
WorkspaceEventChannelFunction · 0.92
newHarnessFunction · 0.85
DialMethod · 0.65
CloseMethod · 0.65
GetWorkspaceByIDMethod · 0.65
PublishMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected