(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func 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 | |
| 59 | func TestPathSpecificRoots(t *testing.T) { |
| 60 | ctx := ghw.ContextFromEnv() |
nothing calls this directly
no test coverage detected
searching dependent graphs…