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

Function TestWorkspaceBuildDeadlineConstraint

coderd/database/querier_test.go:8598–8695  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8596}
8597
8598func TestWorkspaceBuildDeadlineConstraint(t *testing.T) {
8599 t.Parallel()
8600
8601 ctx := testutil.Context(t, testutil.WaitLong)
8602
8603 db, _ := dbtestutil.NewDB(t)
8604 org := dbgen.Organization(t, db, database.Organization{})
8605 user := dbgen.User(t, db, database.User{})
8606 template := dbgen.Template(t, db, database.Template{
8607 CreatedBy: user.ID,
8608 OrganizationID: org.ID,
8609 })
8610 templateVersion := dbgen.TemplateVersion(t, db, database.TemplateVersion{
8611 TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true},
8612 OrganizationID: org.ID,
8613 CreatedBy: user.ID,
8614 })
8615 workspace := dbgen.Workspace(t, db, database.WorkspaceTable{
8616 OwnerID: user.ID,
8617 TemplateID: template.ID,
8618 Name: "test-workspace",
8619 Deleted: false,
8620 })
8621 job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
8622 OrganizationID: org.ID,
8623 InitiatorID: database.PrebuildsSystemUserID,
8624 Provisioner: database.ProvisionerTypeEcho,
8625 Type: database.ProvisionerJobTypeWorkspaceBuild,
8626 StartedAt: sql.NullTime{Time: time.Now().Add(-time.Minute), Valid: true},
8627 CompletedAt: sql.NullTime{Time: time.Now(), Valid: true},
8628 })
8629 workspaceBuild := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{
8630 WorkspaceID: workspace.ID,
8631 TemplateVersionID: templateVersion.ID,
8632 JobID: job.ID,
8633 BuildNumber: 1,
8634 })
8635
8636 cases := []struct {
8637 name string
8638 deadline time.Time
8639 maxDeadline time.Time
8640 expectOK bool
8641 }{
8642 {
8643 name: "no deadline or max_deadline",
8644 deadline: time.Time{},
8645 maxDeadline: time.Time{},
8646 expectOK: true,
8647 },
8648 {
8649 name: "deadline set when max_deadline is not set",
8650 deadline: time.Now().Add(time.Hour),
8651 maxDeadline: time.Time{},
8652 expectOK: true,
8653 },
8654 {
8655 name: "deadline before max_deadline",

Callers

nothing calls this directly

Calls 13

ContextFunction · 0.92
NewDBFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
TemplateFunction · 0.92
TemplateVersionFunction · 0.92
WorkspaceFunction · 0.92
ProvisionerJobFunction · 0.92
WorkspaceBuildFunction · 0.92
IsCheckViolationFunction · 0.92
AddMethod · 0.65

Tested by

no test coverage detected