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

Function setupTestSchedule

cli/schedule_test.go:33–80  ·  view source on GitHub ↗

setupTestSchedule creates 4 workspaces: 1. a-owner-ws1: owned by owner, has both autostart and autostop enabled. 2. b-owner-ws2: owned by owner, has only autostart enabled. 3. c-member-ws3: owned by member, has only autostop enabled. 4. d-member-ws4: owned by member, has neither autostart nor autost

(t *testing.T, sched *cron.Schedule)

Source from the content-addressed store, hash-verified

31// It returns the owner and member clients, the database, and the workspaces.
32// The workspaces are returned in the same order as they are created.
33func setupTestSchedule(t *testing.T, sched *cron.Schedule) (ownerClient, memberClient *codersdk.Client, db database.Store, ws []codersdk.Workspace) {
34 t.Helper()
35
36 ownerClient, db = coderdtest.NewWithDatabase(t, nil)
37 owner := coderdtest.CreateFirstUser(t, ownerClient)
38 memberClient, memberUser := coderdtest.CreateAnotherUserMutators(t, ownerClient, owner.OrganizationID, nil, func(r *codersdk.CreateUserRequestWithOrgs) {
39 r.Username = "testuser2" // ensure deterministic ordering
40 })
41 _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
42 Name: "a-owner",
43 OwnerID: owner.UserID,
44 OrganizationID: owner.OrganizationID,
45 AutostartSchedule: sql.NullString{String: sched.String(), Valid: true},
46 Ttl: sql.NullInt64{Int64: 8 * time.Hour.Nanoseconds(), Valid: true},
47 }).WithAgent().Do()
48
49 _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
50 Name: "b-owner",
51 OwnerID: owner.UserID,
52 OrganizationID: owner.OrganizationID,
53 AutostartSchedule: sql.NullString{String: sched.String(), Valid: true},
54 }).WithAgent().Do()
55 _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
56 Name: "c-member",
57 OwnerID: memberUser.ID,
58 OrganizationID: owner.OrganizationID,
59 Ttl: sql.NullInt64{Int64: 8 * time.Hour.Nanoseconds(), Valid: true},
60 }).WithAgent().Do()
61 _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
62 Name: "d-member",
63 OwnerID: memberUser.ID,
64 OrganizationID: owner.OrganizationID,
65 }).WithAgent().Do()
66
67 // Need this for LatestBuild.Deadline
68 resp, err := ownerClient.Workspaces(context.Background(), codersdk.WorkspaceFilter{})
69 require.NoError(t, err)
70 require.Len(t, resp.Workspaces, 4)
71 // Ensure same order as in CLI output
72 ws = resp.Workspaces
73 sort.Slice(ws, func(i, j int) bool {
74 a := ws[i].OwnerName + "/" + ws[i].Name
75 b := ws[j].OwnerName + "/" + ws[j].Name
76 return a < b
77 })
78
79 return ownerClient, memberClient, db, ws
80}
81
82//nolint:paralleltest // t.Setenv
83func TestScheduleShow(t *testing.T) {

Callers 3

TestScheduleShowFunction · 0.85
TestScheduleModifyFunction · 0.85
TestScheduleOverrideFunction · 0.85

Calls 10

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
WithAgentMethod · 0.80
WorkspacesMethod · 0.80
HelperMethod · 0.65
DoMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected