package selfcompose import ( "context" "slices" "strings" "testing" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" ) // The node that keeps a kept build is the want's kept-on alone, for an artifact its parts name (design 47 G 526, A-50). func TestTheKeepingNodeIsTheWantsKeptOn(t *testing.T) { kd := strings.Repeat("6", 64) for _, row := range []struct { name, digest string want *meshwants.WantsByWantNodeModuleValue node string kept bool }{ {"kept, by its bare digest", kd, &meshwants.WantsByWantNodeModuleValue{Fp: "f1", KeptOn: "n3", Parts: map[string]string{"db:p": "sha256:" + kd}}, "n3", true}, {"kept, by the declared digest", "sha256:" + kd, &meshwants.WantsByWantNodeModuleValue{Fp: "f1", KeptOn: "n3", Parts: map[string]string{"db:p": "sha256:" + kd}}, "n3", true}, {"a digest the parts do not name", "sha256:" + strings.Repeat("7", 64), &meshwants.WantsByWantNodeModuleValue{Fp: "f1", KeptOn: "n3", Parts: map[string]string{"db:p": "sha256:" + kd}}, "", false}, {"a want naming no keeping node", kd, &meshwants.WantsByWantNodeModuleValue{Fp: "f1", Parts: map[string]string{"db:p": "sha256:" + kd}}, "", false}, {"no want of the module", kd, nil, "", false}, } { c := &Composer{wants: map[string]meshwants.WantsByWantNodeModuleValue{}} if row.want != nil { c.wants["db"] = *row.want } node, fp, kept, err := c.KeptBuildOf(context.Background(), "db", row.digest) if err != nil || node != row.node || kept != row.kept || (kept && fp != "f1") { t.Errorf("%s: node %q fp %q kept %v err %v", row.name, node, fp, kept, err) } } } // Design 47 G ยง558, A-275: a manifest's `invokes` in its long form {verb, fields} is read for its seat, and one of a form that // cannot be read is refused, never read as no seats. func TestSeatsOfReadsALongFormInvokeAndRefusesAnUnreadableOne(t *testing.T) { c := New(Env{Node: "n1"}) c.modules["m"] = meshcatalog.ModulesByModuleValue{Manifest: "d1"} c.modules["bad"] = meshcatalog.ModulesByModuleValue{Manifest: "d2"} c.manifests["d1"] = []byte(`{"module":"m","invokes":["seat:a.b",{"verb":"seat:mesh-catalog.revision","fields":["x"]}]}`) c.manifests["d2"] = []byte(`{"module":"bad","invokes":[3]}`) seats, err := c.seatsOf(context.Background(), reader{c: c}, "m") if err != nil || !slices.Equal(seats, []string{"a", "mesh-catalog"}) { t.Fatalf("seats %v, %v", seats, err) } if seats, err := c.seatsOf(context.Background(), reader{c: c}, "bad"); err == nil { t.Fatalf("an unreadable invokes gave seats %v", seats) } }