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

Function setupSupportBundleTestFixture

cli/support_test.go:491–540  ·  view source on GitHub ↗
(
	ctx context.Context,
	t testing.TB,
	db database.Store,
	orgID, ownerID uuid.UUID,
	withAgent func([]*proto.Agent) []*proto.Agent,
)

Source from the content-addressed store, hash-verified

489}
490
491func setupSupportBundleTestFixture(
492 ctx context.Context,
493 t testing.TB,
494 db database.Store,
495 orgID, ownerID uuid.UUID,
496 withAgent func([]*proto.Agent) []*proto.Agent,
497) dbfake.WorkspaceResponse {
498 t.Helper()
499 // nolint: gocritic // Used for seeding test data only.
500 ctx = dbauthz.AsSystemRestricted(ctx)
501 b := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
502 OrganizationID: orgID,
503 OwnerID: ownerID,
504 })
505 if withAgent != nil {
506 b = b.WithAgent(withAgent)
507 }
508 r := b.Do()
509 _, err := db.InsertProvisionerJobLogs(ctx, database.InsertProvisionerJobLogsParams{
510 JobID: r.Build.JobID,
511 CreatedAt: []time.Time{dbtime.Now()},
512 Source: []database.LogSource{database.LogSourceProvisionerDaemon},
513 Level: []database.LogLevel{database.LogLevelInfo},
514 Stage: []string{"provision"},
515 Output: []string{"done"},
516 })
517 require.NoError(t, err)
518 if withAgent != nil {
519 res, err := db.GetWorkspaceResourcesByJobID(ctx, r.Build.JobID)
520 require.NoError(t, err)
521 var resIDs []uuid.UUID
522 for _, res := range res {
523 resIDs = append(resIDs, res.ID)
524 }
525 agents, err := db.GetWorkspaceAgentsByResourceIDs(ctx, resIDs)
526 require.NoError(t, err)
527 for _, agt := range agents {
528 _, err = db.InsertWorkspaceAgentLogs(ctx, database.InsertWorkspaceAgentLogsParams{
529 AgentID: agt.ID,
530 CreatedAt: dbtime.Now(),
531 Output: []string{"started up"},
532 Level: []database.LogLevel{database.LogLevelInfo},
533 LogSourceID: r.Build.JobID,
534 OutputLength: 10,
535 })
536 require.NoError(t, err)
537 }
538 }
539 return r
540}

Callers 1

TestSupportBundleFunction · 0.85

Calls 10

AsSystemRestrictedFunction · 0.92
WorkspaceBuildFunction · 0.92
NowFunction · 0.92
WithAgentMethod · 0.80
HelperMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected