github.com/dnephin/dobi@v0.15.0/utils/fs/expanduser_test.go (about) 1 package fs 2 3 import ( 4 "os" 5 "testing" 6 7 "gotest.tools/v3/assert" 8 is "gotest.tools/v3/assert/cmp" 9 ) 10 11 func TestExpandUserNothingToExpand(t *testing.T) { 12 expected := "does/not/expand" 13 path, err := ExpandUser(expected) 14 15 assert.NilError(t, err) 16 assert.Equal(t, expected, path) 17 } 18 19 func TestExpandUserJustTilde(t *testing.T) { 20 path, err := ExpandUser("~") 21 22 assert.NilError(t, err) 23 assert.Equal(t, os.Getenv("HOME"), path) 24 } 25 26 func TestExpandUserCurrentUser(t *testing.T) { 27 path, err := ExpandUser("~/rest/of/path") 28 expected := os.Getenv("HOME") + "/rest/of/path" 29 30 assert.NilError(t, err) 31 assert.Equal(t, expected, path) 32 } 33 34 func TestExpandUserOtherUser(t *testing.T) { 35 _, err := ExpandUser("~otheruser/rest/of/path") 36 37 assert.Check(t, is.Error(err, "expanding ~user/ paths are not supported yet")) 38 }