package user import ( "testing" "github.com/tamakyi/TamaBox/internal/conf" "github.com/tamakyi/TamaBox/internal/db" ) // TestVoteOptionMaxLen 钉住「配置值不能超过存储上限」这条约束。 // // 背景:conf 的 vote_option_len 只校验 ≥1,可以填得比 vote_options.content // 的列宽还大;那样校验会放行,写库才失败(PostgreSQL 直接报错)。 func TestVoteOptionMaxLen(t *testing.T) { original := conf.Limits.VoteOptionLen t.Cleanup(func() { conf.Limits.VoteOptionLen = original }) cases := []struct { name string conf int want int }{ {"配置小于存储上限时以配置为准", 100, 100}, {"配置等于存储上限", db.MaxVoteOptionLen, db.MaxVoteOptionLen}, {"配置超过存储上限时截到上限", db.MaxVoteOptionLen + 500, db.MaxVoteOptionLen}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { conf.Limits.VoteOptionLen = c.conf if got := voteOptionMaxLen(); got != c.want { t.Fatalf("voteOptionMaxLen() = %d, want %d", got, c.want) } }) } }