- dms/ai/workflow: qa0x-Pakete nach internal/gates/<thema> verschoben, Paketname = Thema
- internal/migration{acl,audit,...} -> internal/migration/{acl,audit,...}
- Importpfade, Gate-Skripte und zwei relative Migrationspfade angepasst
- keine Logikaenderung; mail-Gates bewusst unveraendert (pfadabhaengig)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
package migrationverify
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestRun_ErklaerteUndOffeneAbweichungen(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
source := MapCountProvider{
|
|
"mandant-a": {TenantSlug: "mandant-a", Users: 10, Documents: 50, Messages: 100},
|
|
"mandant-b": {TenantSlug: "mandant-b", Users: 5, Documents: 20, Messages: 40},
|
|
}
|
|
// mandant-b/messages ist eine absichtlich eingefuegte, unerklaerte
|
|
// Testabweichung (Pruefung 2 aus VAL-01).
|
|
target := MapCountProvider{
|
|
"mandant-a": {TenantSlug: "mandant-a", Users: 10, Documents: 48, Messages: 100},
|
|
"mandant-b": {TenantSlug: "mandant-b", Users: 5, Documents: 20, Messages: 37},
|
|
}
|
|
explanations := []Explanation{
|
|
{TenantSlug: "mandant-a", Table: TableDocuments, Count: 2, Reason: "abgelaufene Freigabelinks (bewusst nicht migriert)"},
|
|
}
|
|
|
|
reports, err := Run(ctx, []string{"mandant-a", "mandant-b"}, source, target, explanations)
|
|
if err != nil {
|
|
t.Fatalf("Run: %v", err)
|
|
}
|
|
if len(reports) != 6 {
|
|
t.Fatalf("erwarte 6 Reports (2 Tenants x 3 Tabellen), habe %d", len(reports))
|
|
}
|
|
|
|
byKey := map[string]TableReport{}
|
|
for _, r := range reports {
|
|
byKey[r.TenantSlug+"/"+string(r.Table)] = r
|
|
}
|
|
|
|
if r := byKey["mandant-a/documents"]; r.OffenerBefund() {
|
|
t.Fatalf("mandant-a/documents sollte durch Erklaerung gedeckt sein, diff=%d erklaert=%d", r.Diff(), r.ExplainedCount)
|
|
}
|
|
if r := byKey["mandant-a/users"]; r.OffenerBefund() {
|
|
t.Fatalf("mandant-a/users sollte ohne Abweichung OK sein, diff=%d", r.Diff())
|
|
}
|
|
if r := byKey["mandant-b/messages"]; !r.OffenerBefund() {
|
|
t.Fatal("absichtlich eingefuegte Testabweichung mandant-b/messages wurde nicht erkannt")
|
|
}
|
|
if r := byKey["mandant-b/users"]; r.OffenerBefund() {
|
|
t.Fatalf("mandant-b/users sollte ohne Abweichung OK sein, diff=%d", r.Diff())
|
|
}
|
|
}
|
|
|
|
func TestRun_UnbekannterTenant(t *testing.T) {
|
|
ctx := context.Background()
|
|
if _, err := Run(ctx, []string{"unbekannt"}, MapCountProvider{}, MapCountProvider{}, nil); err == nil {
|
|
t.Fatal("erwarte Fehler fuer tenant ohne hinterlegte Zahlen")
|
|
}
|
|
}
|
|
|
|
func TestCombineUsers(t *testing.T) {
|
|
ctx := context.Background()
|
|
users := MapCountProvider{"mandant-a": {Users: 7}}
|
|
rest := MapCountProvider{"mandant-a": {Documents: 3, Messages: 9}}
|
|
|
|
combined := CombineUsers(users, rest)
|
|
tc, err := combined.Counts(ctx, "mandant-a")
|
|
if err != nil {
|
|
t.Fatalf("Counts: %v", err)
|
|
}
|
|
if tc.Users != 7 || tc.Documents != 3 || tc.Messages != 9 {
|
|
t.Fatalf("erwarte users=7 documents=3 messages=9, habe %+v", tc)
|
|
}
|
|
}
|
|
|
|
func TestOffeneBefunde(t *testing.T) {
|
|
reports := []TableReport{
|
|
{TenantSlug: "a", Table: TableUsers, SourceCount: 5, TargetCount: 5},
|
|
{TenantSlug: "a", Table: TableDocuments, SourceCount: 5, TargetCount: 3},
|
|
}
|
|
offen := OffeneBefunde(reports)
|
|
if len(offen) != 1 || offen[0].Table != TableDocuments {
|
|
t.Fatalf("erwarte genau einen offenen Befund (documents), habe %+v", offen)
|
|
}
|
|
}
|