The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
69 lines
2.7 KiB
Go
69 lines
2.7 KiB
Go
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"])
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestSeatContributions runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestSeatContributions(t *testing.T) {
|
|
t.Run("AContributionReachesTheHoldersFileInModuleOrderNamedByModule", testAContributionReachesTheHoldersFileInModuleOrderNamedByModule)
|
|
t.Run("NoContributionPlacesNothing", testNoContributionPlacesNothing)
|
|
}
|