forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_linux_test.go
41 lines (35 loc) · 995 Bytes
/
path_linux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
// +build linux
package ghw
import (
"os"
"testing"
)
func TestPathRoot(t *testing.T) {
orig, origExists := os.LookupEnv("GHW_CHROOT")
if origExists {
// For tests, save the original, test an override and then at the end
// of the test, reset to the original
defer os.Setenv("GHW_CHROOT", orig)
os.Unsetenv("GHW_CHROOT")
} else {
defer os.Unsetenv("GHW_CHROOT")
}
// No environment variable is set for GHW_CHROOT, so pathRoot() should
// return the default "/"
path := pathRoot()
if path != DEFAULT_ROOT_PATH {
t.Fatalf("Expected pathRoot() to return '/' but got %s", path)
}
// Now set the GHW_CHROOT environ variable and verify that pathRoot()
// returns that value
os.Setenv("GHW_CHROOT", "/host")
path = pathRoot()
if path != "/host" {
t.Fatalf("Expected pathRoot() to return '/host' but got %s", path)
}
}