- README.md: full usage docs - Makefile: build/install/uninstall/test/lint/clean targets - config/config_test.go: 7 tests (load, save, find, add, roundtrip, invalid yaml) - runtime/runtime_test.go: 6 tests (get, available, ListRunning graceful degradation) - systemd/generator_test.go: 7 tests (ServiceName, Generate system/user/custom/docker/unknown, buildExecCommands) - fix: docker/podman ListRunning returns nil (not error) when daemon unavailable - fix: invalid YAML test uses tab-indent which is genuinely unparseable
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package runtime
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGet_Podman(t *testing.T) {
|
|
rt := Get("podman")
|
|
if rt == nil {
|
|
t.Fatal("Get(podman) returned nil")
|
|
}
|
|
if rt.Name() != "podman" {
|
|
t.Errorf("Name() = %q, want %q", rt.Name(), "podman")
|
|
}
|
|
}
|
|
|
|
func TestGet_Docker(t *testing.T) {
|
|
rt := Get("docker")
|
|
if rt == nil {
|
|
t.Fatal("Get(docker) returned nil")
|
|
}
|
|
if rt.Name() != "docker" {
|
|
t.Errorf("Name() = %q, want %q", rt.Name(), "docker")
|
|
}
|
|
}
|
|
|
|
func TestGet_Unknown(t *testing.T) {
|
|
rt := Get("containerd")
|
|
if rt != nil {
|
|
t.Errorf("Get(containerd) should return nil for unknown runtime, got %+v", rt)
|
|
}
|
|
}
|
|
|
|
func TestAvailable_ReturnsRuntimes(t *testing.T) {
|
|
runtimes := Available()
|
|
if len(runtimes) == 0 {
|
|
t.Error("Available() returned empty list")
|
|
}
|
|
names := map[string]bool{}
|
|
for _, rt := range runtimes {
|
|
names[rt.Name()] = true
|
|
}
|
|
if !names["podman"] {
|
|
t.Error("Available() should include podman")
|
|
}
|
|
if !names["docker"] {
|
|
t.Error("Available() should include docker")
|
|
}
|
|
}
|
|
|
|
// ListRunning and Exists are integration-level — they call external binaries.
|
|
// We test that they don't panic when the binary is absent (returns nil/false, no error).
|
|
func TestPodman_ListRunning_NoBinary(t *testing.T) {
|
|
// This test is meaningful if podman isn't installed; if it is, we just check no error occurs
|
|
p := &Podman{}
|
|
containers, err := p.ListRunning()
|
|
if err != nil {
|
|
t.Errorf("ListRunning() should not error when podman is absent: %v", err)
|
|
}
|
|
// containers may be nil or populated — both are fine
|
|
_ = containers
|
|
}
|
|
|
|
func TestDocker_ListRunning_NoBinary(t *testing.T) {
|
|
d := &Docker{}
|
|
containers, err := d.ListRunning()
|
|
if err != nil {
|
|
t.Errorf("ListRunning() should not error when docker is absent: %v", err)
|
|
}
|
|
_ = containers
|
|
}
|