mesh/delivery merged: source.main moved to novox/mesh-catalog@6d000647de2d
mesh/check being carried to cff1005422c1 on 6d000647de2d | from f9dcbc295723
The one bundle that did everything becomes the manager bundle, which runs long and answers the seat's ten verbs and the three acting tools, and a tools bundle of its own that answers the four reading tools and writes nothing, so they answer while the manager fails to load or stops. Both import the module's one package for the layouts of the kept data and the log entries, the key form, the entries' names and the settings with their validity; the settings file and the account with its directory stay as they are. Builds: design 39 parts §1, §2, §3, §4, §5, §6, §7, §8
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package licences
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// design 39 bus-and-switch §10, B6.
|
|
func TestALicencesKeyForm(t *testing.T) {
|
|
for name, key := range map[string]string{
|
|
"jane@example.org": "jane_at_example.org",
|
|
"Jane.Doe@Example.ORG": "jane.doe_at_example.org",
|
|
"0c1d2e3f-4a5b-6c7d-8e9f-a0b1c2d3e4f5": "0c1d2e3f-4a5b-6c7d-8e9f-a0b1c2d3e4f5",
|
|
"team key_1": "team_key_1",
|
|
"a+b/c:d": "a_b_c_d",
|
|
"ops-key": "ops-key",
|
|
} {
|
|
if got := KeyFor(name); got != key {
|
|
t.Errorf("KeyFor(%q) = %q, want %q", name, got, key)
|
|
}
|
|
}
|
|
}
|
|
|
|
// design 39 bus-and-switch §33/AC1: each setting's default is the manifest's, a value at its bound is taken, and one
|
|
// outside its bound or absent keeps the default.
|
|
func TestEachSettingsDefaultAndBound(t *testing.T) {
|
|
raw, err := os.ReadFile("../../module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Config map[string]struct {
|
|
Default any `json:"default"`
|
|
Minimum *float64 `json:"minimum"`
|
|
Maximum *float64 `json:"maximum"`
|
|
Trusted bool `json:"trusted"`
|
|
} `json:"config"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defaults := Defaults.Values()
|
|
if len(m.Config) != len(defaults) {
|
|
t.Fatalf("the manifest declares %d settings, the code %d", len(m.Config), len(defaults))
|
|
}
|
|
file := filepath.Join(t.TempDir(), "settings.json")
|
|
read := func(k string, v any) any {
|
|
b, _ := json.Marshal(map[string]any{k: v})
|
|
_ = os.WriteFile(file, b, 0o600)
|
|
return SettingsFrom(file).Values()[k]
|
|
}
|
|
for k, c := range m.Config {
|
|
if !c.Trusted || c.Default != defaults[k] {
|
|
t.Errorf("%s: the manifest's default %v (trusted %v), the code's %v", k, c.Default, c.Trusted, defaults[k])
|
|
}
|
|
if c.Maximum == nil {
|
|
continue
|
|
}
|
|
lo, hi := *c.Minimum, *c.Maximum
|
|
for v, want := range map[float64]any{lo: lo, hi: hi, lo - 1: defaults[k], hi + 1: defaults[k]} {
|
|
if got := read(k, v); got != want {
|
|
t.Errorf("%s set to %v reads %v, want %v", k, v, got, want)
|
|
}
|
|
}
|
|
}
|
|
if read("switch_auto", false) != false || read("switch_at_pct", "high") != 99.0 {
|
|
t.Error("switch_auto off, or a value of the wrong type, is not read as written")
|
|
}
|
|
}
|
|
|
|
// design 39 bus-and-switch §33: room_below_pct or warn_at_pct above switch_at_pct is an invalid pair naming both
|
|
// values; equal is valid.
|
|
func TestAnInvalidPairIsFound(t *testing.T) {
|
|
s := Defaults
|
|
if len(s.Invalid()) != 0 {
|
|
t.Fatal("the defaults are invalid")
|
|
}
|
|
s.SwitchAt, s.RoomBelow, s.WarnAt = 80, 85, 80
|
|
got := s.Invalid()
|
|
if len(got) != 1 || got[0] != (Invalid{Setting: "room_below_pct", Value: 85, SwitchAt: 80}) {
|
|
t.Fatalf("invalid %+v", got)
|
|
}
|
|
s.WarnAt = 95
|
|
if got := s.Invalid(); len(got) != 2 || got[1].Setting != "warn_at_pct" {
|
|
t.Fatalf("invalid %+v", got)
|
|
}
|
|
}
|