package main // The module's directories (novox/hq issue 1873): its state directory said place ".", which is /var/lib/systemd, // systemd's own directory (tmpfiles.d/systemd.conf: d /var/lib/systemd 0755 root root); the node-engine gave it to // the operator's account, mode 0700, on every machine. What the tools keep moves to the mesh's directory for the // module, and for one delivery the record "state" states the package's owner and mode, so the node-engine, which // takes a directory it recorded at the same path under the same id as its own, gives it back. import ( "encoding/json" "os" "testing" ) func manifestResources(t *testing.T) (map[string]map[string]any, map[string]any) { t.Helper() raw, err := os.ReadFile("../../module.json") if err != nil { t.Fatal(err) } var m map[string]any if err := json.Unmarshal(raw, &m); err != nil { t.Fatal(err) } out := map[string]map[string]any{} list, _ := m["resources"].([]any) for _, x := range list { r, _ := x.(map[string]any) out[r["id"].(string)] = r } return out, m } // 1873/AC1: the tools' record is kept in /mesh/systemd; "state" gives /var/lib/systemd back to root, 0755. func TestTheToolsKeepTheirRecordOutsideSystemdsOwnDirectory(t *testing.T) { rs, m := manifestResources(t) data := rs["data"] if data == nil || data["type"] != "directory" || data["place"] != "mesh" || data["path"] != nil { t.Fatalf("the tools' directory is placed \"mesh\" with no path (/var/lib/mesh/systemd): %v", data) } build, _ := m["build"].(map[string]any) artifacts, _ := build["artifacts"].([]any) env := artifacts[0].(map[string]any)["env"].(map[string]any) if env["MESH_SYSTEMD_STATE"] != "${dir:data}" { t.Errorf("MESH_SYSTEMD_STATE is %v, not ${dir:data}", env["MESH_SYSTEMD_STATE"]) } state := rs["state"] if state == nil || state["type"] != "directory" || state["path"] != "/var/lib/systemd" || state["owner"] != "root" || state["mode"] != "0755" || state["place"] != nil { t.Errorf("state gives /var/lib/systemd back as systemd declares it, root 0755: %v", state) } }