feat: order/delay in service files, enable cmd, --all on unit commands
- install/uninstall/start/stop/enable take <name> or --all; *all kept as shortcuts - add enable (enable at boot + start); startall no longer enables - order/delay resolved by config.ResolveOrder and written into systemd, OpenRC and runit service files (After=/sleep), so they apply at boot - install --all stops and disables units before removing their files - update regenerates all installed, enabled units and removes disabled ones - edit creates the config dir; docs and man page updated - tests: fake Init for cmd, ResolveOrder, backend ordering output
This commit is contained in:
@@ -293,3 +293,32 @@ func TestParseStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate_OrderAndDelay(t *testing.T) {
|
||||
b, _ := setup(t)
|
||||
u := config.Unit{Name: "web", Runtime: "podman", Enabled: true, After: []string{"db"}, StartDelay: 3 * time.Second}
|
||||
got, err := b.Generate(u, "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
link := filepath.Join(b.ServiceDir, "unitdore-db")
|
||||
wait := "sv -w 30 check " + link + " >/dev/null 2>&1 || true\nsleep 3\n"
|
||||
if !strings.Contains(got, wait) {
|
||||
t.Errorf("missing %q in:\n%s", wait, got)
|
||||
}
|
||||
// waiting happens before the service command runs
|
||||
if strings.Index(got, "sleep 3") > strings.Index(got, "exec /usr/bin/podman") {
|
||||
t.Errorf("delay must precede exec:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate_NoOrderNoExtras(t *testing.T) {
|
||||
b, _ := setup(t)
|
||||
got, err := b.Generate(config.Unit{Name: "a", Runtime: "podman", Enabled: true}, "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(got, "sv -w") || strings.Contains(got, "sleep") {
|
||||
t.Errorf("unexpected ordering output:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user