init push
This commit is contained in:
37
internal/domain/user/model_test.go
Normal file
37
internal/domain/user/model_test.go
Normal 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")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user