feat: OpenRC and runit init backends behind an Init interface
Extract init-neutral unit resolution into service/, add initsys.Init with systemd, openrc and runit backends, selected by 'init:' config or autodetect. OpenRC and runit are root only; rootless units run as system services as that user. Add docs and generated examples for all three.
This commit is contained in:
@@ -226,46 +226,6 @@ func TestGenerate_WithPrefixSuffix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildExecCommands(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
unit config.Unit
|
||||
wantStart string
|
||||
wantStop string
|
||||
}{
|
||||
{
|
||||
name: "podman",
|
||||
unit: config.Unit{Name: "app", Runtime: "podman"},
|
||||
wantStart: "/usr/bin/podman start -a app",
|
||||
wantStop: "/usr/bin/podman stop app",
|
||||
},
|
||||
{
|
||||
name: "docker",
|
||||
unit: config.Unit{Name: "app", Runtime: "docker"},
|
||||
wantStart: "/usr/bin/docker start -a app",
|
||||
wantStop: "/usr/bin/docker stop app",
|
||||
},
|
||||
{
|
||||
name: "custom command",
|
||||
unit: config.Unit{Name: "app", Runtime: "podman", Command: "/bin/custom"},
|
||||
wantStart: "/bin/custom",
|
||||
wantStop: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
start, stop := buildExecCommands(tt.unit)
|
||||
if start != tt.wantStart {
|
||||
t.Errorf("start = %q, want %q", start, tt.wantStart)
|
||||
}
|
||||
if stop != tt.wantStop {
|
||||
t.Errorf("stop = %q, want %q", stop, tt.wantStop)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// newComposeStack creates a stack unit whose compose binary, working dir and
|
||||
// compose file exist on disk (compose mode).
|
||||
func newComposeStack(t *testing.T) config.Unit {
|
||||
@@ -290,31 +250,6 @@ func newComposeStack(t *testing.T) config.Unit {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStackMode(t *testing.T) {
|
||||
u := newComposeStack(t)
|
||||
if StackMode(u) != StackModeCompose {
|
||||
t.Errorf("StackMode() = %q, want compose", StackMode(u))
|
||||
}
|
||||
|
||||
missingFile := u
|
||||
missingFile.ComposeFiles = []string{"gone.yaml"}
|
||||
if StackMode(missingFile) != StackModePod {
|
||||
t.Error("missing compose file should fall back to pod mode")
|
||||
}
|
||||
|
||||
missingBin := u
|
||||
missingBin.ComposeBin = ""
|
||||
if StackMode(missingBin) != StackModePod {
|
||||
t.Error("missing compose binary should fall back to pod mode")
|
||||
}
|
||||
|
||||
missingDir := u
|
||||
missingDir.WorkingDir = "/nonexistent/unitdore-test"
|
||||
if StackMode(missingDir) != StackModePod {
|
||||
t.Error("missing working dir should fall back to pod mode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate_StackCompose(t *testing.T) {
|
||||
u := newComposeStack(t)
|
||||
content, err := Generate(u, "", "")
|
||||
@@ -376,22 +311,6 @@ func TestGenerate_StackCustomCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildComposeCommands_Quoting(t *testing.T) {
|
||||
u := config.Unit{
|
||||
Project: "shop",
|
||||
ComposeBin: "/usr/bin/podman-compose",
|
||||
ComposeFiles: []string{"compose.yaml", "my override.yaml"},
|
||||
}
|
||||
start, stop := buildComposeCommands(u)
|
||||
wantBase := `/usr/bin/podman-compose -p shop -f compose.yaml -f "my override.yaml"`
|
||||
if start != wantBase+" up" {
|
||||
t.Errorf("start = %q", start)
|
||||
}
|
||||
if stop != wantBase+" stop" {
|
||||
t.Errorf("stop = %q", stop)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate_Script(t *testing.T) {
|
||||
u := config.Unit{
|
||||
Name: "backup",
|
||||
|
||||
Reference in New Issue
Block a user