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

Function TestTemplateUpdateBuildDeadlines

enterprise/coderd/schedule/template_test.go:36–321  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestTemplateUpdateBuildDeadlines(t *testing.T) {
37 t.Parallel()
38
39 db, _ := dbtestutil.NewDB(t)
40
41 var (
42 quietUser = dbgen.User(t, db, database.User{
43 Username: "quiet",
44 })
45 noQuietUser = dbgen.User(t, db, database.User{
46 Username: "no-quiet",
47 })
48 file = dbgen.File(t, db, database.File{
49 CreatedBy: quietUser.ID,
50 })
51 templateJob = dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
52 FileID: file.ID,
53 InitiatorID: quietUser.ID,
54 Tags: database.StringMap{
55 "foo": "bar",
56 },
57 })
58 templateVersion = dbgen.TemplateVersion(t, db, database.TemplateVersion{
59 OrganizationID: templateJob.OrganizationID,
60 CreatedBy: quietUser.ID,
61 JobID: templateJob.ID,
62 })
63 organizationID = templateJob.OrganizationID
64 )
65
66 const userQuietHoursSchedule = "CRON_TZ=UTC 0 0 * * *" // midnight UTC
67 ctx := testutil.Context(t, testutil.WaitLong)
68 quietUser, err := db.UpdateUserQuietHoursSchedule(ctx, database.UpdateUserQuietHoursScheduleParams{
69 ID: quietUser.ID,
70 QuietHoursSchedule: userQuietHoursSchedule,
71 })
72 require.NoError(t, err)
73
74 realNow := time.Now().UTC()
75 nowY, nowM, nowD := realNow.Date()
76 buildTime := time.Date(nowY, nowM, nowD, 12, 0, 0, 0, time.UTC) // noon today UTC
77 nextQuietHours := time.Date(nowY, nowM, nowD+1, 0, 0, 0, 0, time.UTC) // midnight tomorrow UTC
78
79 defaultTTL := 8 * time.Hour
80
81 cases := []struct {
82 name string
83 now time.Time
84 // Before:
85 deadline time.Time
86 maxDeadline time.Time
87 // After:
88 newDeadline time.Time
89 newMaxDeadline time.Time
90 // Config:
91 noQuietHours bool
92 // Note that ttl will not influence the new build at all unless it's 0
93 // AND the build does not have a max deadline post recalculation.

Callers

nothing calls this directly

Calls 15

SetMethod · 0.95
NewDBFunction · 0.92
UserFunction · 0.92
FileFunction · 0.92
ProvisionerJobFunction · 0.92
TemplateVersionFunction · 0.92
ContextFunction · 0.92
TemplateFunction · 0.92
WorkspaceBuildFunction · 0.92
StringFunction · 0.92
WithJobCompletedAtFunction · 0.92

Tested by

no test coverage detected