Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestIDMapRoundTripFixture(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
users := map[string]string{
|
||||
"user_2abcClerkId": "550e8400-e29b-41d4-a716-446655440000",
|
||||
}
|
||||
companies := map[string]string{
|
||||
"org_or_legacy_company_text_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
|
||||
}
|
||||
path, err := WriteIDMapDir(dir, users, companies, true)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteIDMapDir: %v", err)
|
||||
}
|
||||
if filepath.Base(path) != "id-map.json" {
|
||||
t.Fatalf("unexpected path %s", path)
|
||||
}
|
||||
|
||||
doc, err := ReadIDMap(path)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadIDMap: %v", err)
|
||||
}
|
||||
if doc.Version != 1 || !doc.Meta.DryRun {
|
||||
t.Fatalf("meta %#v", doc.Meta)
|
||||
}
|
||||
if doc.Meta.UserCount != 1 || doc.Meta.CompanyCount != 1 {
|
||||
t.Fatalf("counts user=%d company=%d", doc.Meta.UserCount, doc.Meta.CompanyCount)
|
||||
}
|
||||
|
||||
uid, ok := doc.ResolveUser("user_2abcClerkId")
|
||||
if !ok || uid.String() != "550e8400-e29b-41d4-a716-446655440000" {
|
||||
t.Fatalf("ResolveUser = %v ok=%v", uid, ok)
|
||||
}
|
||||
cid, ok := doc.ResolveCompany("org_or_legacy_company_text_id")
|
||||
if !ok || cid.String() != "6ba7b810-9dad-11d1-80b4-00c04fd430c8" {
|
||||
t.Fatalf("ResolveCompany = %v ok=%v", cid, ok)
|
||||
}
|
||||
if _, ok := doc.ResolveUser("missing"); ok {
|
||||
t.Fatal("expected missing user")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDMapValidateRejectsBadUUID(t *testing.T) {
|
||||
t.Parallel()
|
||||
doc := NewIDMapDocument(map[string]string{"u1": "not-a-uuid"}, nil, false)
|
||||
if err := doc.Validate(); err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDMapValidateRejectsEmptyLegacy(t *testing.T) {
|
||||
t.Parallel()
|
||||
doc := NewIDMapDocument(map[string]string{"": uuid.New().String()}, nil, false)
|
||||
if err := doc.Validate(); err == nil {
|
||||
t.Fatal("expected empty legacy error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDMapWriteRejectsInvalid(t *testing.T) {
|
||||
t.Parallel()
|
||||
path := filepath.Join(t.TempDir(), "bad.json")
|
||||
err := WriteIDMap(path, IDMapDocument{Version: 2})
|
||||
if err == nil {
|
||||
t.Fatal("expected write validation error")
|
||||
}
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
t.Fatalf("file should not exist, stat err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemapOrphanDetectionFixture(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Membership rows whose company/user legacy IDs are absent from the map are orphans.
|
||||
companies := map[string]string{"co_a": uuid.New().String()}
|
||||
users := map[string]string{"user_a": uuid.New().String()}
|
||||
doc := NewIDMapDocument(users, companies, false)
|
||||
|
||||
type membership struct{ CompanyLegacy, UserLegacy string }
|
||||
rows := []membership{
|
||||
{"co_a", "user_a"},
|
||||
{"co_missing", "user_a"},
|
||||
{"co_a", "user_missing"},
|
||||
}
|
||||
orphans := 0
|
||||
for _, m := range rows {
|
||||
_, okC := doc.ResolveCompany(m.CompanyLegacy)
|
||||
_, okU := doc.ResolveUser(m.UserLegacy)
|
||||
if !okC || !okU {
|
||||
orphans++
|
||||
}
|
||||
}
|
||||
if orphans != 2 {
|
||||
t.Fatalf("orphans = %d, want 2", orphans)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user