One machine ran another time zone and a German console keymap with no record why. The module writes /etc/locale.conf and /etc/vconsole.conf whole and sets the zone through a run-once step of its own Go binary (timedatectl, read back): /etc/localtime is a link the mesh may not write (hq ADR 0012) and a module may not declare an action (ADR 0005). Tools: localization_get, _time_zone, _locales, _keymaps (to-be 42 Phase 1).
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package main
|
|
|
|
// The module's shape (novox/hq to-be 42 Phase 1, research 027): two files written whole and the
|
|
// time zone as a step of its own binary — never a symbolic link written by the mesh (ADR 0012),
|
|
// never an action (ADR 0005).
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTheFilesSayWhatTheToolsCompareAgainst(t *testing.T) {
|
|
m := manifest(t)
|
|
if m.Module != "localization" || m.Version != "1" {
|
|
t.Fatalf("%s %s", m.Module, m.Version)
|
|
}
|
|
locale := m.resource(t, "locale")
|
|
if locale["path"] != "/etc/locale.conf" || locale["into"] != nil || !strings.Contains(locale["content"].(string), "\nLANG="+MeshLang+"\n") {
|
|
t.Fatalf("locale: %v", locale)
|
|
}
|
|
keymap := m.resource(t, "keymap")
|
|
if keymap["path"] != "/etc/vconsole.conf" || !strings.Contains(keymap["content"].(string), "\nKEYMAP="+MeshKeymap+"\n") {
|
|
t.Fatalf("keymap: %v", keymap)
|
|
}
|
|
for _, r := range []resource{locale, keymap} {
|
|
var settings []string
|
|
for _, l := range strings.Split(r["content"].(string), "\n") {
|
|
if l != "" && !strings.HasPrefix(l, "#") {
|
|
settings = append(settings, l)
|
|
}
|
|
}
|
|
if len(settings) != 1 {
|
|
t.Fatalf("%v says one thing: %v", r["id"], settings)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTheTimeZoneIsAStepOfTheModulesOwnBinaryRunAsRoot(t *testing.T) {
|
|
m := manifest(t)
|
|
step := m.resource(t, "time-zone")
|
|
if step["type"] != "process" || step["run-once"] != true || step["artifact"] != "tools" || step["user"] != nil {
|
|
t.Fatalf("step: %v", step)
|
|
}
|
|
run := step["run"].([]any)
|
|
if len(run) != 3 || run[0] != "./"+binaryName || run[1] != "set-time-zone" || run[2] != MeshZone {
|
|
t.Fatalf("run: %v", run)
|
|
}
|
|
for _, r := range m.Resources {
|
|
if r["type"] == "action" || r["path"] == "/etc/localtime" {
|
|
t.Fatalf("%v: the zone is never written by the mesh", r["id"])
|
|
}
|
|
}
|
|
}
|