package resolution import ( "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) func hotkeysHolder() mcat.Manifest { return mcat.Manifest{Module: "triggerhappy", Claims: []mcat.Claim{{Name: mcat.HotkeysSeat}}, Resources: []map[string]any{ {"id": "triggers", "type": "file", "path": "/etc/triggerhappy/triggers.d/mesh.conf", "content": "# the mesh's triggers\n${contribution:node-hotkeys:trigger}"}, }} } func TestAContributionReachesTheHoldersFileInModuleOrderNamedByModule(t *testing.T) { laptop := mcat.Manifest{Module: "laptop", Contributions: []mcat.SeatContribution{ {Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "KEY_PROG1 1 play ${machine:account-home}"}, {Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "KEY_F21 1 touchpad\n"}, }} another := mcat.Manifest{Module: "another", Contributions: []mcat.SeatContribution{ {Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "KEY_MUTE 1 mute ${shell:zsh:first}"}, }} unrelated := mcat.Manifest{Module: "bar", Contributions: []mcat.SeatContribution{ {Seat: mcat.DisplaySessionSeat, Kind: "config", Content: "bar { }"}, }} r := mcat.Resolution{Node: "laptop", Account: "op", Modules: []mcat.Manifest{hotkeysHolder(), laptop, another, unrelated}} out, err := Declaration(r, mcat.Rendering{}) if err != nil { t.Fatal(err) } var file map[string]any for _, res := range out { if res["id"] == "triggerhappy.triggers" { file = res } } if file == nil { t.Fatalf("the holder's file was not composed: %v", out) } // Module order; each module named once; text never read, so neither ${machine:…} nor ${shell:…} // inside a contribution is filled. want := "# the mesh's triggers\n" + "# another\nKEY_MUTE 1 mute ${shell:zsh:first}\n" + "# laptop\nKEY_PROG1 1 play ${machine:account-home}\nKEY_F21 1 touchpad\n" if got := file["content"]; got != want { t.Fatalf("the holder's file is\n%s\nnot\n%s", got, want) } } func TestNoContributionPlacesNothing(t *testing.T) { r := mcat.Resolution{Node: "laptop", Account: "op", Modules: []mcat.Manifest{hotkeysHolder()}} out, err := Declaration(r, mcat.Rendering{}) if err != nil { t.Fatal(err) } for _, res := range out { if res["id"] == "triggerhappy.triggers" && res["content"] != "# the mesh's triggers\n" { t.Fatalf("an empty kind left %q", res["content"]) } } }