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

Function setupCLITaskTestWithSnapshot

cli/task_test.go:367–400  ·  view source on GitHub ↗

setupCLITaskTestWithSnapshot creates a task in the specified status with a log snapshot. Note: We do not use IncludeProvisionerDaemon because these tests use dbfake to directly set up database state and don't need actual provisioning. This also avoids potential interference from the provisioner daem

(ctx context.Context, t *testing.T, status codersdk.TaskStatus, messages []agentapisdk.Message)

Source from the content-addressed store, hash-verified

365// set up database state and don't need actual provisioning. This also avoids potential
366// interference from the provisioner daemon polling for jobs.
367func setupCLITaskTestWithSnapshot(ctx context.Context, t *testing.T, status codersdk.TaskStatus, messages []agentapisdk.Message) (*codersdk.Client, codersdk.Task) {
368 t.Helper()
369
370 ownerClient, db := coderdtest.NewWithDatabase(t, nil)
371 owner := coderdtest.CreateFirstUser(t, ownerClient)
372 userClient, user := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID)
373
374 ownerUser, err := ownerClient.User(ctx, owner.UserID.String())
375 require.NoError(t, err)
376 ownerSubject := coderdtest.AuthzUserSubject(ownerUser)
377
378 task := createTaskInStatus(t, db, owner.OrganizationID, user.ID, status)
379
380 // Create snapshot envelope with agentapi format.
381 envelope := coderd.TaskLogSnapshotEnvelope{
382 Format: "agentapi",
383 Data: agentapisdk.GetMessagesResponse{
384 Messages: messages,
385 },
386 }
387 snapshotJSON, err := json.Marshal(envelope)
388 require.NoError(t, err)
389
390 // Insert snapshot into database.
391 snapshotTime := time.Now()
392 err = db.UpsertTaskSnapshot(dbauthz.As(ctx, ownerSubject), database.UpsertTaskSnapshotParams{
393 TaskID: task.ID,
394 LogSnapshot: json.RawMessage(snapshotJSON),
395 LogSnapshotCreatedAt: snapshotTime,
396 })
397 require.NoError(t, err)
398
399 return userClient, task
400}
401
402// setupCLITaskTestWithoutSnapshot creates a task in the specified status without a log snapshot.
403// Note: We do not use IncludeProvisionerDaemon because these tests use dbfake to directly

Callers 1

Test_TaskLogs_GoldenFunction · 0.85

Calls 11

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
AuthzUserSubjectFunction · 0.92
AsFunction · 0.92
createTaskInStatusFunction · 0.85
HelperMethod · 0.65
UserMethod · 0.65
UpsertTaskSnapshotMethod · 0.65
StringMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected