MCPcopy
hub / github.com/jaypipes/ghw / TestPathRoot

Function TestPathRoot

pkg/linuxpath/path_linux_test.go:25–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestPathRoot(t *testing.T) {
26 orig, origExists := os.LookupEnv("GHW_CHROOT")
27 if origExists {
28 // For tests, save the original, test an override and then at the end
29 // of the test, reset to the original
30 defer os.Setenv("GHW_CHROOT", orig)
31 os.Unsetenv("GHW_CHROOT")
32 } else {
33 defer os.Unsetenv("GHW_CHROOT")
34 }
35
36 ctx := ghw.ContextFromEnv()
37 paths := linuxpath.New(ctx)
38
39 // No environment variable is set for GHW_CHROOT, so pathProcCpuinfo() should
40 // return the default "/proc/cpuinfo"
41 path := paths.ProcCpuinfo
42 if path != "/proc/cpuinfo" {
43 t.Fatalf("Expected pathProcCpuInfo() to return '/proc/cpuinfo' but got %s", path)
44 }
45
46 // Now set the GHW_CHROOT environ variable and verify that pathRoot()
47 // returns that value
48 os.Setenv("GHW_CHROOT", "/host")
49
50 ctx = ghw.ContextFromEnv()
51 paths = linuxpath.New(ctx)
52
53 path = paths.ProcCpuinfo
54 if path != "/host/proc/cpuinfo" {
55 t.Fatalf("Expected path.ProcCpuinfo to return '/host/proc/cpuinfo' but got %s", path)
56 }
57}
58
59func TestPathSpecificRoots(t *testing.T) {
60 ctx := ghw.ContextFromEnv()

Callers

nothing calls this directly

Calls 1

NewFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…