package contractdocs import ( "strings" "testing" ) func TestCommittedDocumentsMatchTheirPins(t *testing.T) { if err := Check(); err != nil { t.Fatal(err) } // Every file under files/ is in the table: nothing is committed unpinned. entries, err := files.ReadDir("files") if err != nil { t.Fatal(err) } inTable := map[string]bool{} for _, d := range released { inTable[d.File] = true } for _, e := range entries { if !inTable[e.Name()] { t.Errorf("files/%s is not in the table", e.Name()) } } if len(entries) != len(released) { t.Errorf("%d files, %d table entries", len(entries), len(released)) } } // The released set as of 19.11.2026: AGB, AVV (the master) and TOM, then the // seven Leistungsbeschreibungen. func TestReleasedSet(t *testing.T) { want := map[string]string{ "agb": "1.0.0", "avv": "1.0.0", "tom": "1.0.0", "lb-plattform": "1.0.0", "lb-pruefwerk": "1.0.3", "lb-werkpilot": "1.0.0", "lb-firmwerk": "1.0.0", "lb-werkmeister": "1.0.0", "lb-managed-git": "1.0.0", "lb-build-runner": "1.0.0", } all := Default().All() if len(all) != len(want) { t.Fatalf("%d documents", len(all)) } for _, d := range all { lb := d.Kind == KindLB && strings.HasPrefix(d.Title, "Leistungsbeschreibung ") stand := map[string]string{KindAGB: "09.11.2026", KindAVV: "17.11.2026", KindTOM: "09.11.2026"}[d.ID] top := stand != "" && d.Kind == d.ID && d.Title == Title(d.Kind) && d.Date == stand if want[d.ID] != d.Version || (!lb && !top) { t.Errorf("%+v", d) } if Default().Get(d.ID) != d { t.Errorf("get %s", d.ID) } } if all[3].Title != "Leistungsbeschreibung Breakpilot Plattform" { t.Errorf("platform title %q", all[3].Title) } if all[0].ID != "agb" || all[1].ID != "avv" || all[2].ID != "tom" || all[3].ID != "lb-plattform" || Default().Get("lb-pruefwerk").Date != "09.11.2026" { t.Error("order or Stand") } } // The one place that says which Leistungsbeschreibung applies to whom. func TestApplicability(t *testing.T) { ids := func(h Holdings) string { var out []string for _, d := range Default().For(h) { out = append(out, d.ID) } return strings.Join(out, ",") } for name, c := range map[string]struct { h Holdings want string }{ "nothing booked": {Holdings{}, "agb,avv,tom,lb-plattform"}, "pruefwerk": {Holdings{Products: map[string]bool{"pruefwerk": true}}, "agb,avv,tom,lb-plattform,lb-pruefwerk"}, "all products": {Holdings{Products: map[string]bool{"pruefwerk": true, "werkpilot": true, "firmwerk": true, "werkmeister": true, "compliance": true}}, "agb,avv,tom,lb-plattform,lb-pruefwerk,lb-werkpilot,lb-firmwerk,lb-werkmeister"}, "managed git": {Holdings{ManagedServices: map[string]bool{"git": true}}, "agb,avv,tom,lb-plattform,lb-managed-git"}, "git and runner": {Holdings{ManagedServices: map[string]bool{"git": true, "ci-runner": true}}, "agb,avv,tom,lb-plattform,lb-managed-git,lb-build-runner"}, "service named as product": {Holdings{Products: map[string]bool{"git": true}}, "agb,avv,tom,lb-plattform"}, } { if got := ids(c.h); got != c.want { t.Errorf("%s: %s, want %s", name, got, c.want) } } // AGB, AVV and TOM apply to everyone once released. for _, k := range []string{KindAGB, KindAVV, KindTOM} { if !(&Doc{Kind: k}).Applies(Holdings{}) { t.Errorf("%s does not apply", k) } } } func TestTitles(t *testing.T) { if Title(KindAVV) != "Auftragsverarbeitungsvertrag" || Title(KindAGB) == "" || Title(KindTOM) == "" || Title("x") != "" { t.Error("titles") } if !ValidVersion("1.0.0") || ValidVersion("1.0") || ValidVersion("v1.0.0") || ValidVersion("1.0.0 ") { t.Error("versions") } } func TestCheckRefusesBadEntries(t *testing.T) { pdf := []byte("%PDF-1.7 synthetic") good := Doc{ID: "avv", Kind: KindAVV, Version: "1.0.0", Date: "01.12.2026", PDF: pdf, SHA256: Sum(pdf)} if err := NewCatalogue(good).Check(); err != nil { t.Fatalf("good: %v", err) } for name, mod := range map[string]func(d *Doc){ "changed pdf": func(d *Doc) { d.PDF = []byte("%PDF-1.7 changed") }, "not a pdf": func(d *Doc) { d.PDF = []byte(""); d.SHA256 = Sum(d.PDF) }, "bad id": func(d *Doc) { d.ID = "../avv" }, "avv under other id": func(d *Doc) { d.ID = "avv-master" }, "unknown kind": func(d *Doc) { d.Kind = "nda" }, "avv for product": func(d *Doc) { d.Product = "pruefwerk" }, "both conditions": func(d *Doc) { d.Kind = KindLB; d.Product = "pruefwerk"; d.ManagedService = "git" }, "bad version": func(d *Doc) { d.Version = "1.0" }, "iso date": func(d *Doc) { d.Date = "2026-12-01" }, } { d := good mod(&d) if NewCatalogue(d).Check() == nil { t.Errorf("%s: not refused", name) } } if NewCatalogue(good, good).Check() == nil { t.Error("duplicate id not refused") } }