github.com/aliyun/credentials-go@v1.4.7/credentials/internal/utils/path_test.go (about) 1 package utils 2 3 import ( 4 "os" 5 "runtime" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_getOS(t *testing.T) { 12 assert.Equal(t, runtime.GOOS, getOS()) 13 } 14 15 func TestGetHomePath(t *testing.T) { 16 originGetOS := getOS 17 originUserProfile := os.Getenv("USERPROFILE") 18 originHome := os.Getenv("HOME") 19 defer func() { 20 getOS = originGetOS 21 os.Setenv("USERPROFILE", originUserProfile) 22 os.Setenv("HOME", originHome) 23 }() 24 25 getOS = func() string { 26 return "windows" 27 } 28 os.Setenv("USERPROFILE", "/path/to/custom_home") 29 30 assert.Equal(t, "/path/to/custom_home", GetHomePath()) 31 32 getOS = func() string { 33 return "darwin" 34 } 35 36 os.Setenv("HOME", "/Users/jacksontian") 37 assert.Equal(t, "/Users/jacksontian", GetHomePath()) 38 }