Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -159,25 +159,28 @@ func TestARetentionThatIsNotACountThinsNothingAndSaysWhich(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The manifest declares the three preferences with today's values as their defaults, and its file,
|
||||
// The manifest declares the retention's config values with today's values as their defaults, and its file,
|
||||
// filled with those defaults, reads as today's retention: nothing changes on a machine that sets none.
|
||||
func TestTheManifestsDefaultsAreTodaysRetention(t *testing.T) {
|
||||
raw, err := os.ReadFile("../../module.json")
|
||||
must(t, err)
|
||||
var m struct {
|
||||
Settings map[string]struct {
|
||||
Kind string `json:"kind"`
|
||||
Default any `json:"default"`
|
||||
Why string `json:"why"`
|
||||
} `json:"settings"`
|
||||
Config map[string]struct {
|
||||
Type string `json:"type"`
|
||||
Description string `json:"description"`
|
||||
Minimum *float64 `json:"minimum"`
|
||||
Maximum *float64 `json:"maximum"`
|
||||
Default any `json:"default"`
|
||||
} `json:"config"`
|
||||
Resources []map[string]any `json:"resources"`
|
||||
}
|
||||
must(t, json.Unmarshal(raw, &m))
|
||||
want := map[string]float64{"keep-daily": 14, "keep-weekly": 8, "keep-monthly": 6, "keep-hand-taken-days": 7}
|
||||
for k, v := range want {
|
||||
s, ok := m.Settings[k]
|
||||
if !ok || s.Kind != "preference" || s.Default != v || s.Why == "" {
|
||||
t.Errorf("setting %s: %+v, want a preference defaulting to %v with why", k, s, v)
|
||||
s, ok := m.Config[k]
|
||||
if !ok || s.Type != "number" || s.Default != v || s.Description == "" || s.Minimum == nil || *s.Minimum != 1 ||
|
||||
s.Maximum == nil || *s.Maximum != 9999 {
|
||||
t.Errorf("config value %s: %+v, want a number from 1 to 9999 defaulting to %v with a description", k, s, v)
|
||||
}
|
||||
}
|
||||
content := ""
|
||||
@@ -186,15 +189,15 @@ func TestTheManifestsDefaultsAreTodaysRetention(t *testing.T) {
|
||||
if r["path"] != "${dir:state}/"+RetentionFile {
|
||||
t.Errorf("the retention file is placed at %v, where this program does not read it", r["path"])
|
||||
}
|
||||
content, _ = r["content"].(string)
|
||||
content = templateText(t, r)
|
||||
}
|
||||
}
|
||||
if content == "" {
|
||||
t.Fatal("no retention resource in the manifest")
|
||||
}
|
||||
filled := regexp.MustCompile(`\$\{setting:([a-z-]+)\}`).ReplaceAllStringFunc(content, func(p string) string {
|
||||
k := p[len("${setting:") : len(p)-1]
|
||||
return fmt.Sprint(m.Settings[k].Default)
|
||||
filled := regexp.MustCompile(`\$\{config:([a-z-]+)\}`).ReplaceAllStringFunc(content, func(p string) string {
|
||||
k := p[len("${config:") : len(p)-1]
|
||||
return fmt.Sprint(m.Config[k].Default)
|
||||
})
|
||||
got, err := ParseRetention(filled)
|
||||
must(t, err)
|
||||
|
||||
Reference in New Issue
Block a user