44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package seed
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
|
)
|
|
|
|
func TestMockEntityIdentitiesAreStableAndUnique(t *testing.T) {
|
|
identityPattern := regexp.MustCompile(
|
|
`^00000000-0000-7000-8000-[0-9]{12}$`,
|
|
)
|
|
seen := make(map[string]struct{}, 46)
|
|
for sequence := 1; sequence <= 46; sequence++ {
|
|
record := entity(sequence, common.StatusEnable)
|
|
if !identityPattern.MatchString(record.Identity) {
|
|
t.Fatalf("entity(%d) identity = %q", sequence, record.Identity)
|
|
}
|
|
if _, exists := seen[record.Identity]; exists {
|
|
t.Fatalf("duplicate identity %q", record.Identity)
|
|
}
|
|
seen[record.Identity] = struct{}{}
|
|
if record.Status != common.StatusEnable {
|
|
t.Fatalf("entity(%d) has unexpected defaults: %#v", sequence, record)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIdentityOfEmbeddedEntity(t *testing.T) {
|
|
record := struct {
|
|
Entity struct {
|
|
Identity string
|
|
}
|
|
}{}
|
|
record.Entity.Identity = "mock-identity"
|
|
if got := identityOf(&record); got != record.Entity.Identity {
|
|
t.Fatalf("identityOf() = %q, want %q", got, record.Entity.Identity)
|
|
}
|
|
if got := identityOf(nil); got != "" {
|
|
t.Fatalf("identityOf(nil) = %q, want empty", got)
|
|
}
|
|
}
|