github.com/KusionStack/kpm@v0.8.4-0.20240326033734-dc72298a30e5/pkg/env/env_test.go (about) 1 package env 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "gotest.tools/v3/assert" 9 ) 10 11 func TestGetAbsPkgPath(t *testing.T) { 12 // Test absolute directory 13 os.Setenv(PKG_PATH, ".") 14 got, err := GetAbsPkgPath() 15 expect, _ := filepath.Abs(".") 16 assert.Equal(t, err, nil) 17 assert.Equal(t, got, expect) 18 19 // Test sub directory 20 os.Setenv(PKG_PATH, "test_subdir") 21 got, err = GetAbsPkgPath() 22 assert.Equal(t, got, filepath.Join(expect, "test_subdir")) 23 assert.Equal(t, err, nil) 24 25 // Test default path 26 os.Setenv(PKG_PATH, "") 27 got, err = GetAbsPkgPath() 28 homeDir, _ := os.UserHomeDir() 29 assert.Equal(t, got, filepath.Join(homeDir, ".kcl/kpm")) 30 assert.Equal(t, err, nil) 31 }