Close automatable P2 test gaps with mocks and httptest integration.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Add container/podman exec mocks, BITS/curl HiddenRun coverage, WinRM/GPO/systemd deploy-plan httptest, and a 3-hop discover-spread Playwright stub chain.
This commit is contained in:
91
agent/miner/runtime_detect_test.go
Normal file
91
agent/miner/runtime_detect_test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package miner
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func mockVersionOKCmd(_ string, args ...string) *exec.Cmd {
|
||||
if runtime.GOOS == "windows" {
|
||||
if len(args) >= 2 && args[0] == "version" && args[1] == "--format" {
|
||||
return exec.Command("cmd", "/c", "echo", "24.0.1")
|
||||
}
|
||||
return exec.Command("cmd", "/c", "exit", "0")
|
||||
}
|
||||
if len(args) >= 2 && args[0] == "version" && args[1] == "--format" {
|
||||
return exec.Command("sh", "-c", "echo 24.0.1")
|
||||
}
|
||||
return exec.Command("true")
|
||||
}
|
||||
|
||||
func mockVersionPodmanCmd(_ string, args ...string) *exec.Cmd {
|
||||
if runtime.GOOS == "windows" {
|
||||
if len(args) >= 2 && args[0] == "version" && args[1] == "--format" {
|
||||
return exec.Command("cmd", "/c", "echo", "4.9.0")
|
||||
}
|
||||
return exec.Command("cmd", "/c", "exit", "0")
|
||||
}
|
||||
if len(args) >= 2 && args[0] == "version" && args[1] == "--format" {
|
||||
return exec.Command("sh", "-c", "echo 4.9.0")
|
||||
}
|
||||
return exec.Command("true")
|
||||
}
|
||||
|
||||
func TestDetectContainerRuntimePrefersDocker(t *testing.T) {
|
||||
SetContainerRuntimeProbes(
|
||||
func(name string) (string, error) {
|
||||
if name == "docker" {
|
||||
return "/usr/bin/docker", nil
|
||||
}
|
||||
if name == "podman" {
|
||||
return "/usr/bin/podman", nil
|
||||
}
|
||||
return "", exec.ErrNotFound
|
||||
},
|
||||
mockVersionOKCmd,
|
||||
)
|
||||
defer SetContainerRuntimeProbes(nil, nil)
|
||||
|
||||
rt := DetectContainerRuntime()
|
||||
if !rt.Available || rt.CLI != "docker" {
|
||||
t.Fatalf("runtime=%+v want docker", rt)
|
||||
}
|
||||
if rt.Version != "24.0.1" {
|
||||
t.Fatalf("version=%q", rt.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectContainerRuntimeFallsBackToPodman(t *testing.T) {
|
||||
SetContainerRuntimeProbes(
|
||||
func(name string) (string, error) {
|
||||
if name == "podman" {
|
||||
return "/usr/bin/podman", nil
|
||||
}
|
||||
return "", exec.ErrNotFound
|
||||
},
|
||||
mockVersionPodmanCmd,
|
||||
)
|
||||
defer SetContainerRuntimeProbes(nil, nil)
|
||||
|
||||
rt := DetectContainerRuntime()
|
||||
if !rt.Available || rt.CLI != "podman" {
|
||||
t.Fatalf("runtime=%+v want podman", rt)
|
||||
}
|
||||
if rt.Version != "4.9.0" {
|
||||
t.Fatalf("version=%q", rt.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectContainerRuntimeUnavailable(t *testing.T) {
|
||||
SetContainerRuntimeProbes(
|
||||
func(string) (string, error) { return "", exec.ErrNotFound },
|
||||
nil,
|
||||
)
|
||||
defer SetContainerRuntimeProbes(nil, nil)
|
||||
|
||||
rt := DetectContainerRuntime()
|
||||
if rt.Available || rt.CLI != "" {
|
||||
t.Fatalf("runtime=%+v want unavailable", rt)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user