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

Function Template

coderd/database/dbgen/dbgen.go:485–520  ·  view source on GitHub ↗
(t testing.TB, db database.Store, seed database.Template)

Source from the content-addressed store, hash-verified

483}
484
485func Template(t testing.TB, db database.Store, seed database.Template) database.Template {
486 id := takeFirst(seed.ID, uuid.New())
487 if seed.GroupACL == nil {
488 // By default, all users in the organization can read the template.
489 seed.GroupACL = database.TemplateACL{
490 seed.OrganizationID.String(): db2sdk.TemplateRoleActions(codersdk.TemplateRoleUse),
491 }
492 }
493 if seed.UserACL == nil {
494 seed.UserACL = database.TemplateACL{}
495 }
496 err := db.InsertTemplate(genCtx, database.InsertTemplateParams{
497 ID: id,
498 CreatedAt: takeFirst(seed.CreatedAt, dbtime.Now()),
499 UpdatedAt: takeFirst(seed.UpdatedAt, dbtime.Now()),
500 OrganizationID: takeFirst(seed.OrganizationID, uuid.New()),
501 Name: takeFirst(seed.Name, testutil.GetRandomName(t)),
502 Provisioner: takeFirst(seed.Provisioner, database.ProvisionerTypeEcho),
503 ActiveVersionID: takeFirst(seed.ActiveVersionID, uuid.New()),
504 Description: takeFirst(seed.Description, testutil.GetRandomName(t)),
505 CreatedBy: takeFirst(seed.CreatedBy, uuid.New()),
506 Icon: takeFirst(seed.Icon, testutil.GetRandomName(t)),
507 UserACL: seed.UserACL,
508 GroupACL: seed.GroupACL,
509 DisplayName: takeFirst(seed.DisplayName, testutil.GetRandomName(t)),
510 AllowUserCancelWorkspaceJobs: seed.AllowUserCancelWorkspaceJobs,
511 MaxPortSharingLevel: takeFirst(seed.MaxPortSharingLevel, database.AppSharingLevelOwner),
512 UseClassicParameterFlow: takeFirst(seed.UseClassicParameterFlow, false),
513 CorsBehavior: takeFirst(seed.CorsBehavior, database.CorsBehaviorSimple),
514 })
515 require.NoError(t, err, "insert template")
516
517 template, err := db.GetTemplateByID(genCtx, id)
518 require.NoError(t, err, "get template")
519 return template
520}
521
522func APIKey(t testing.TB, db database.Store, seed database.APIKey, munge ...func(*database.InsertAPIKeyParams)) (key database.APIKey, token string) {
523 id, _ := cryptorand.String(10)

Callers 15

TestWorkspaceTimingsFunction · 0.92
TestTaskParamFunction · 0.92
TestWorkspaceParamFunction · 0.92
TestWorkspaceBuildParamFunction · 0.92
TestWorkspaceAgentParamFunction · 0.92
TestTemplateParamFunction · 0.92

Calls 8

TemplateRoleActionsFunction · 0.92
NowFunction · 0.92
GetRandomNameFunction · 0.92
takeFirstFunction · 0.70
NewMethod · 0.65
InsertTemplateMethod · 0.65
GetTemplateByIDMethod · 0.65
StringMethod · 0.45

Tested by 15

TestWorkspaceTimingsFunction · 0.74
TestTaskParamFunction · 0.74
TestWorkspaceParamFunction · 0.74
TestWorkspaceBuildParamFunction · 0.74
TestWorkspaceAgentParamFunction · 0.74
TestTemplateParamFunction · 0.74