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:
@@ -11,14 +11,15 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The container runtime's log rotation is a preference (novox/hq issue 452).
|
||||
// The container runtime's log rotation is two config values with defaults (novox/hq issue 452, ADR 0348 §4).
|
||||
|
||||
type manifestForLogs 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"`
|
||||
Default any `json:"default"`
|
||||
Trusted bool `json:"trusted"`
|
||||
} `json:"config"`
|
||||
Resources []map[string]any `json:"resources"`
|
||||
}
|
||||
|
||||
@@ -44,16 +45,16 @@ func resourceByID(m manifestForLogs, id string) (map[string]any, int) {
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
// filled is a file's content as the controller fills it from the settings' defaults alone: each
|
||||
// ${setting:<key>} replaced by the default as text, the way the controller writes a value into a file.
|
||||
// filled is a file's content as the controller fills it from the config values' defaults alone: each
|
||||
// ${config:<key>} replaced by the default as text, the way the controller writes a value into a file.
|
||||
func filled(t *testing.T, m manifestForLogs, content string) string {
|
||||
t.Helper()
|
||||
ref := regexp.MustCompile(`\$\{setting:([a-z0-9][a-z0-9_.-]*)\}`)
|
||||
ref := regexp.MustCompile(`\$\{config:([a-z0-9][a-z0-9_.-]*)\}`)
|
||||
var missing []string
|
||||
out := ref.ReplaceAllStringFunc(content, func(s string) string {
|
||||
key := ref.FindStringSubmatch(s)[1]
|
||||
d, ok := m.Settings[key]
|
||||
if !ok || d.Kind != "preference" {
|
||||
d, ok := m.Config[key]
|
||||
if !ok || d.Default == nil || d.Description == "" || !d.Trusted {
|
||||
missing = append(missing, key)
|
||||
return s
|
||||
}
|
||||
@@ -77,7 +78,7 @@ func TestTheDefaultLogRotationIsTheOneTheHandSetMachineHas(t *testing.T) {
|
||||
t.Fatal("no daemon resource")
|
||||
}
|
||||
var keys map[string]any
|
||||
if err := json.Unmarshal([]byte(filled(t, m, daemon["content"].(string))), &keys); err != nil {
|
||||
if err := json.Unmarshal([]byte(filled(t, m, templateText(t, daemon))), &keys); err != nil {
|
||||
t.Fatalf("daemon.json's keys with the defaults are not JSON: %v", err)
|
||||
}
|
||||
if keys["log-driver"] != "json-file" {
|
||||
@@ -125,7 +126,7 @@ func TestTheLogRotationIsCheckedBeforeDaemonJSONIsWritten(t *testing.T) {
|
||||
t.Errorf("log-rotation says trusted %v, want true", conf["trusted"])
|
||||
}
|
||||
// The step reads the very values daemon.json takes: the same keys, filled the same way.
|
||||
values, err := parseLogRotation(filled(t, m, conf["content"].(string)))
|
||||
values, err := parseLogRotation(filled(t, m, templateText(t, conf)))
|
||||
if err != nil {
|
||||
t.Fatalf("the defaults are refused: %v", err)
|
||||
}
|
||||
@@ -133,8 +134,8 @@ func TestTheLogRotationIsCheckedBeforeDaemonJSONIsWritten(t *testing.T) {
|
||||
t.Errorf("defaults read as %+v", values)
|
||||
}
|
||||
daemon, _ := resourceByID(m, "daemon")
|
||||
for _, key := range []string{"${setting:log-max-size}", "${setting:log-max-file}"} {
|
||||
if !strings.Contains(daemon["content"].(string), key) || !strings.Contains(conf["content"].(string), key) {
|
||||
for _, key := range []string{"${config:log-max-size}", "${config:log-max-file}"} {
|
||||
if !strings.Contains(templateText(t, daemon), key) || !strings.Contains(templateText(t, conf), key) {
|
||||
t.Errorf("%s is not in both daemon and log-rotation", key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user