Files
ONE/backend/internal/store/store_test.go
T

43 lines
1.1 KiB
Go

package store
import (
"strings"
"testing"
"oneblog/internal/db"
"oneblog/internal/model"
)
func TestSlugify(t *testing.T) {
cases := map[string]string{
"Hello World": "hello-world",
" Rebuild ONE ": "rebuild-one",
"Go 语言 / 2026": "go-语言-2026",
"!!!": "",
}
for in, want := range cases {
if got := Slugify(in); got != want {
t.Errorf("Slugify(%q) = %q, want %q", in, got, want)
}
}
}
func TestListOptionsRebind(t *testing.T) {
// 列表查询的占位符数量必须和参数数量一致,否则在 PostgreSQL 上会直接报错
d := &db.DB{Dialect: db.Postgres}
q := d.Q(`SELECT id FROM posts WHERE kind = ? AND status = ? AND title LIKE ? LIMIT ? OFFSET ?`)
if strings.Count(q, "$") != 5 {
t.Errorf("expected 5 placeholders, got %q", q)
}
}
func TestPostInputDefaults(t *testing.T) {
in := model.PostInput{Kind: model.KindShort, ContentMd: "一句话。"}
if in.Kind != "short" {
t.Errorf("kind = %q", in.Kind)
}
if in.Status != "" {
t.Errorf("empty status means draft is applied by the API layer, got %q", in.Status)
}
}