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

Function TestUserSkillSchemaConstants

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

Source from the content-addressed store, hash-verified

513}
514
515func TestUserSkillSchemaConstants(t *testing.T) {
516 t.Parallel()
517
518 _, _, sqlDB := dbtestutil.NewDBWithSQLDB(t)
519
520 ctx := testutil.Context(t, testutil.WaitMedium)
521 var triggerDef string
522 require.NoError(t, sqlDB.QueryRowContext(
523 ctx,
524 `SELECT pg_get_functiondef('enforce_user_skills_per_user_limit'::regproc)`,
525 ).Scan(&triggerDef))
526 assert.Contains(t, triggerDef, fmt.Sprintf("skill_limit constant int := %d;", skills.MaxPersonalSkillsPerUser))
527
528 constraints := map[database.CheckConstraint]string{
529 database.CheckUserSkillsNameSize: fmt.Sprintf("octet_length(name) <= %d", skills.MaxPersonalSkillNameBytes),
530 database.CheckUserSkillsNameFormat: "name ~ '^[a-z0-9]+(-[a-z0-9]+)*$'::text",
531 database.CheckUserSkillsContentSize: fmt.Sprintf("octet_length(content) <= %d", skills.MaxPersonalSkillSizeBytes),
532 }
533 for constraint, expected := range constraints {
534 t.Run(string(constraint), func(t *testing.T) {
535 t.Parallel()
536
537 ctx := testutil.Context(t, testutil.WaitMedium)
538 var constraintDef string
539 require.NoError(t, sqlDB.QueryRowContext(
540 ctx,
541 `SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conname = $1`,
542 constraint,
543 ).Scan(&constraintDef))
544 assert.Contains(t, constraintDef, expected)
545 })
546 }
547}
548
549//nolint:paralleltest,tparallel // Subtests share one auditor and run sequentially.
550func TestUserSkillAudit(t *testing.T) {

Callers

nothing calls this directly

Calls 6

NewDBWithSQLDBFunction · 0.92
ContextFunction · 0.92
QueryRowContextMethod · 0.80
RunMethod · 0.65
ScanMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected