gorm/tests/primary_key_uuid_test.go
2024-04-17 12:25:36 +02:00

34 lines
629 B
Go

package tests_test
import (
"sync"
"testing"
"github.com/google/uuid"
"gorm.io/gorm/schema"
)
func TestStringPrimaryKeyDefault(t *testing.T) {
type Product struct {
ID uuid.UUID
Code string
Name string
}
product, err := schema.Parse(&Product{}, &sync.Map{}, schema.NamingStrategy{})
if err != nil {
t.Fatalf("failed to parse product struct with composite primary key, got error %v", err)
}
isInDefault := false
for _, field := range product.FieldsWithDefaultDBValue {
if field.Name == "ID" {
isInDefault = true
break
}
}
if !isInDefault {
t.Errorf("ID should be fields with default")
}
}