Files
wehub-resource-sync 36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:06 +08:00

46 lines
1.2 KiB
Go

package source
import (
"testing"
"github.com/pranshuparmar/witr/pkg/model"
)
func TestFindEnvVar(t *testing.T) {
ancestry := []model.Process{
{PID: 1, Command: "systemd", Env: []string{"PATH=/usr/bin"}},
{PID: 100, Command: "bash", Env: []string{"FOO=bar", "BAZ=qux"}},
}
// The target (last element) is searched first.
if got := findEnvVar(ancestry, "FOO"); got != "bar" {
t.Errorf("findEnvVar(FOO) = %q, want bar", got)
}
// A variable only the ancestor sets is still found.
if got := findEnvVar(ancestry, "PATH"); got != "/usr/bin" {
t.Errorf("findEnvVar(PATH) = %q, want /usr/bin", got)
}
// A missing variable yields "".
if got := findEnvVar(ancestry, "MISSING"); got != "" {
t.Errorf("findEnvVar(MISSING) = %q, want empty", got)
}
}
func TestDetectLXCRuntime(t *testing.T) {
tests := []struct {
cmd string
want string
}{
{"incusd", "incus"},
{"lxd", "lxd"},
{"lxc-start", "lxc"},
{"unrelated", "lxc"}, // fallback when no known manager is in the chain
}
for _, tt := range tests {
got := detectLXCRuntime([]model.Process{{Command: tt.cmd}})
if got != tt.want {
t.Errorf("detectLXCRuntime(%q) = %q, want %q", tt.cmd, got, tt.want)
}
}
}