github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/pkg/gnoenv/gnohome_test.go (about) 1 package gnoenv 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestHomeDir(t *testing.T) { 12 t.Run("use GNOHOME if set", func(t *testing.T) { 13 // Backup any related environment variables 14 t.Setenv("GNOHOME", "") 15 t.Setenv("GNO_HOME", "") 16 17 expected := "/test/gno_home" 18 os.Setenv("GNOHOME", expected) 19 require.Equal(t, expected, HomeDir()) 20 }) 21 22 t.Run("fallback to GNO_HOME if set", func(t *testing.T) { 23 // Backup any related environment variables 24 t.Setenv("GNOHOME", "") 25 t.Setenv("GNO_HOME", "") 26 t.Log("`GNO_HOME` is deprecated, use `GNOHOME` instead") 27 28 expected := "/test/gnohome" 29 os.Setenv("GNO_HOME", expected) 30 require.Equal(t, expected, HomeDir()) 31 }) 32 33 t.Run("use UserConfigDir with gno", func(t *testing.T) { 34 // Backup any related environment variables 35 t.Setenv("GNOHOME", "") 36 t.Setenv("GNO_HOME", "") 37 38 dir, err := os.UserConfigDir() 39 require.NoError(t, err) 40 expected := filepath.Join(dir, "gno") 41 require.Equal(t, expected, HomeDir()) 42 }) 43 }