init push

This commit is contained in:
2026-07-16 22:16:45 +07:00
commit 8b068bdb10
1021 changed files with 332816 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package user
import (
"testing"
"gorm.io/gorm"
)
func TestUserTableName(t *testing.T) {
var u User
if got := u.TableName(); got != "users" {
t.Fatalf("unexpected table name: %s", got)
}
}
func TestUserBeforeCreate(t *testing.T) {
t.Run("generates id when empty", func(t *testing.T) {
u := &User{}
if err := u.BeforeCreate(&gorm.DB{}); err != nil {
t.Fatalf("BeforeCreate error: %v", err)
}
if len(u.ID) != 16 {
t.Fatalf("expected generated 16-byte ID, got %d", len(u.ID))
}
})
t.Run("keeps existing id", func(t *testing.T) {
existing := []byte("1234567890abcdef")
u := &User{ID: append([]byte(nil), existing...)}
if err := u.BeforeCreate(&gorm.DB{}); err != nil {
t.Fatalf("BeforeCreate error: %v", err)
}
if string(u.ID) != string(existing) {
t.Fatalf("expected existing id to stay unchanged")
}
})
}