2026-07-28 22:42:21 +08:00
|
|
|
package seed
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
"testing"
|
2026-07-29 13:18:52 +08:00
|
|
|
|
|
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
2026-07-28 22:42:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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++ {
|
2026-07-29 13:18:52 +08:00
|
|
|
record := entity(sequence, common.StatusEnable)
|
2026-07-28 22:42:21 +08:00
|
|
|
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{}{}
|
2026-07-29 14:03:10 +08:00
|
|
|
if record.Status != common.StatusEnable {
|
2026-07-28 22:42:21 +08:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-05 13:58:16 +08:00
|
|
|
|
|
|
|
|
func TestIdentityOfDirectIdentityField(t *testing.T) {
|
|
|
|
|
record := struct {
|
|
|
|
|
Identity string
|
|
|
|
|
}{Identity: "mock-direct-identity"}
|
|
|
|
|
if got := identityOf(&record); got != record.Identity {
|
|
|
|
|
t.Fatalf("identityOf() = %q, want %q", got, record.Identity)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAdditionalScenarioIdentitiesDoNotOverlapBaseScenario(t *testing.T) {
|
|
|
|
|
seen := make(map[string]struct{}, 226)
|
|
|
|
|
for sequence := 1; sequence <= 56; sequence++ {
|
|
|
|
|
seen[entity(sequence, common.StatusEnable).Identity] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
for scenario := 2; scenario <= 10; scenario++ {
|
|
|
|
|
base := 1000 + scenario*100
|
|
|
|
|
for offset := 1; offset <= 20; offset++ {
|
|
|
|
|
identity := entity(base+offset, common.StatusEnable).Identity
|
|
|
|
|
if _, exists := seen[identity]; exists {
|
|
|
|
|
t.Fatalf("duplicate identity %q", identity)
|
|
|
|
|
}
|
|
|
|
|
seen[identity] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|