package resolution import ( "reflect" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) func TestTheResolverConfigSeatIsGone(t *testing.T) { if _, known := mcat.SeatNamed("node-resolver-config"); known { t.Error("node-resolver-config is still in the mesh's set; the uplink's holder writes the resolver file") } // An uplink's holder needs no seat beside it for the file: it is its own. if got := DependsOn(nil, mod("networkmanager", nil, nil, nil, mcat.Claim{Name: "node-uplink"})); len(got) != 0 { t.Errorf("an uplink holder with nothing declared depends on %v", got) } } // The catalogue as it is: nothing claims the retired seat, and every manager the mesh knows holds the // uplink and writes the resolver file; beside them only a holder of node-resolver does (ADR 0247). func TestTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes(t *testing.T) { cat := map[string]mcat.Manifest{} for _, m := range theCatalogue(t) { cat[m.Module] = m } if got := PossibleHolders(cat, "node-uplink"); !reflect.DeepEqual(got, uplinks) { t.Errorf("node-uplink can be held by %v, not %v", got, uplinks) } for name, m := range cat { for _, c := range m.Claims { if c.Name == "node-resolver-config" { t.Errorf("%s still claims node-resolver-config", name) } } _, writes := m.Facts["resolvers"] isUplink := false for _, u := range uplinks { isUplink = isUplink || u == name } for _, f := range m.Facts { // Or the machine's own resolver's, where it is held (novox/hq ADR 0247): the uplink's holder // steps back from the file there, and nowhere else. if f.Path == "/etc/resolv.conf" && !isUplink && !holdsSeat(m, mcat.ResolverSeat) { t.Errorf("%s writes /etc/resolv.conf and holds neither the uplink nor the machine's resolver", name) } } for _, r := range m.Resources { if r["path"] == "/etc/resolv.conf" { t.Errorf("%s declares /etc/resolv.conf as a file of its own", name) } } if isUplink && !writes { t.Errorf("%s holds the uplink and does not write the resolver file", name) } } }