127 lines
4.4 KiB
Go
127 lines
4.4 KiB
Go
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 09.11.2026: the seven Leistungsbeschreibungen, no
|
|
// AGB, AVV or TOM yet.
|
|
func TestReleasedSet(t *testing.T) {
|
|
want := map[string]string{
|
|
"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 {
|
|
if want[d.ID] != d.Version || d.Kind != KindLB || !strings.HasPrefix(d.Title, "Leistungsbeschreibung ") {
|
|
t.Errorf("%+v", d)
|
|
}
|
|
if Default().Get(d.ID) != d {
|
|
t.Errorf("get %s", d.ID)
|
|
}
|
|
}
|
|
if all[0].Title != "Leistungsbeschreibung Breakpilot Plattform" {
|
|
t.Errorf("platform title %q", all[0].Title)
|
|
}
|
|
if all[0].ID != "lb-plattform" || Default().Get("avv") != nil || Default().Get("lb-pruefwerk").Date != "09.11.2026" {
|
|
t.Error("order, absent AVV 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{}, "lb-plattform"},
|
|
"pruefwerk": {Holdings{Products: map[string]bool{"pruefwerk": true}}, "lb-plattform,lb-pruefwerk"},
|
|
"all products": {Holdings{Products: map[string]bool{"pruefwerk": true, "werkpilot": true, "firmwerk": true, "werkmeister": true, "compliance": true}},
|
|
"lb-plattform,lb-pruefwerk,lb-werkpilot,lb-firmwerk,lb-werkmeister"},
|
|
"managed git": {Holdings{ManagedServices: map[string]bool{"git": true}}, "lb-plattform,lb-managed-git"},
|
|
"git and runner": {Holdings{ManagedServices: map[string]bool{"git": true, "ci-runner": true}}, "lb-plattform,lb-managed-git,lb-build-runner"},
|
|
"service named as product": {Holdings{Products: map[string]bool{"git": true}}, "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("<html>"); 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")
|
|
}
|
|
}
|