(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestUserSkillSchemaConstants(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | if testing.Short() { |
| 18 | t.SkipNow() |
| 19 | } |
| 20 | |
| 21 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 22 | _, _, sqlDB := dbtestutil.NewDBWithSQLDB(t) |
| 23 | var triggerDef string |
| 24 | err := sqlDB.QueryRowContext(ctx, |
| 25 | `SELECT pg_get_functiondef('enforce_user_skills_per_user_limit'::regproc)`, |
| 26 | ).Scan(&triggerDef) |
| 27 | require.NoError(t, err) |
| 28 | require.Contains(t, triggerDef, fmt.Sprintf( |
| 29 | "skill_limit constant int := %d", |
| 30 | skills.MaxPersonalSkillsPerUser, |
| 31 | )) |
| 32 | |
| 33 | constraints := map[database.CheckConstraint]string{ |
| 34 | database.CheckUserSkillsNameSize: fmt.Sprintf( |
| 35 | "octet_length(name) <= %d", |
| 36 | skills.MaxPersonalSkillNameBytes, |
| 37 | ), |
| 38 | database.CheckUserSkillsNameFormat: "name ~ '^[a-z0-9]+(-[a-z0-9]+)*$'::text", |
| 39 | database.CheckUserSkillsDescriptionSize: fmt.Sprintf( |
| 40 | "octet_length(description) <= %d", |
| 41 | skills.MaxPersonalSkillDescriptionBytes, |
| 42 | ), |
| 43 | database.CheckUserSkillsContentSize: fmt.Sprintf( |
| 44 | "octet_length(content) <= %d", |
| 45 | skills.MaxPersonalSkillSizeBytes, |
| 46 | ), |
| 47 | } |
| 48 | for constraint, expected := range constraints { |
| 49 | t.Run(string(constraint), func(t *testing.T) { |
| 50 | t.Parallel() |
| 51 | |
| 52 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 53 | var constraintDef string |
| 54 | err := sqlDB.QueryRowContext(ctx, |
| 55 | `SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conname = $1`, |
| 56 | constraint, |
| 57 | ).Scan(&constraintDef) |
| 58 | require.NoError(t, err) |
| 59 | require.Contains(t, constraintDef, expected) |
| 60 | }) |
| 61 | } |
| 62 | } |
nothing calls this directly
no test coverage detected