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

Function TestUserSkillDatabaseConstraints

coderd/userskills_test.go:457–513  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

455}
456
457func TestUserSkillDatabaseConstraints(t *testing.T) {
458 t.Parallel()
459
460 adminClient, _, api := coderdtest.NewWithAPI(t, nil)
461 firstUser := coderdtest.CreateFirstUser(t, adminClient)
462 _, ownerUser := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
463 tests := []struct {
464 name string
465 params database.InsertUserSkillParams
466 constraint database.CheckConstraint
467 }{
468 {
469 name: "NameFormat",
470 params: database.InsertUserSkillParams{
471 ID: uuid.New(),
472 UserID: ownerUser.ID,
473 Name: "not kebab",
474 Description: "Invalid",
475 Content: userSkillMarkdown("not kebab", "Invalid", "Body."),
476 },
477 constraint: database.CheckUserSkillsNameFormat,
478 },
479 {
480 name: "NameSize",
481 params: database.InsertUserSkillParams{
482 ID: uuid.New(),
483 UserID: ownerUser.ID,
484 Name: strings.Repeat("a", skills.MaxPersonalSkillNameBytes+1),
485 Description: "Invalid",
486 Content: userSkillMarkdown("too-long-name", "Invalid", "Body."),
487 },
488 constraint: database.CheckUserSkillsNameSize,
489 },
490 {
491 name: "ContentSize",
492 params: database.InsertUserSkillParams{
493 ID: uuid.New(),
494 UserID: ownerUser.ID,
495 Name: "content-too-large",
496 Description: "Invalid",
497 Content: strings.Repeat("a", skills.MaxPersonalSkillSizeBytes+1),
498 },
499 constraint: database.CheckUserSkillsContentSize,
500 },
501 }
502 for _, tt := range tests {
503 t.Run(tt.name, func(t *testing.T) {
504 t.Parallel()
505
506 ctx := testutil.Context(t, testutil.WaitMedium)
507 authzCtx := dbauthz.As(ctx, coderdtest.AuthzUserSubject(ownerUser))
508
509 _, err := api.Database.InsertUserSkill(authzCtx, tt.params)
510 require.True(t, database.IsCheckViolation(err, tt.constraint), "expected %s, got %v", tt.constraint, err)
511 })
512 }
513}
514

Callers

nothing calls this directly

Calls 11

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
AsFunction · 0.92
AuthzUserSubjectFunction · 0.92
IsCheckViolationFunction · 0.92
userSkillMarkdownFunction · 0.70
NewMethod · 0.65
RunMethod · 0.65
InsertUserSkillMethod · 0.65

Tested by

no test coverage detected