package main import ( "testing" catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" ) func TestAsksOf(t *testing.T) { m := map[string]any{"module": "m", "claims": []any{map[string]any{"name": "seat-a"}}, "emits": []any{"done"}} a, err := AsksOf(catalog.CatalogEntry{Module: "m", Verdict: "accepted", Manifest: m}) if err != nil { t.Fatal(err) } if len(a.Claims) != 1 || a.Claims[0] != "seat-a" || !a.EmitsOwn || a.Accepted.Module != "m" || a.Accepted.Digest == "" { t.Errorf("read %+v", a) } b, _ := AsksOf(catalog.CatalogEntry{Module: "m", Manifest: map[string]any{"module": "m"}}) if b.EmitsOwn || len(b.Claims) != 0 { t.Errorf("an entry with neither: %+v", b) } if b.Accepted.Digest != a.Accepted.Digest { t.Errorf("the digest is of the bus-state asked alone: %s vs %s", b.Accepted.Digest, a.Accepted.Digest) } if _, err := AsksOf(catalog.CatalogEntry{}); err == nil { t.Error("an entry with no module was read") } }