完成一个简易的全局skill、command管理器
This commit is contained in:
60
manager/internal/config/paths_test.go
Normal file
60
manager/internal/config/paths_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetConfigRoot_Default(t *testing.T) {
|
||||
// 清除环境变量
|
||||
os.Unsetenv("SKILLMGR_TEST_ROOT")
|
||||
|
||||
root, err := GetConfigRoot()
|
||||
if err != nil {
|
||||
t.Fatalf("GetConfigRoot 失败: %v", err)
|
||||
}
|
||||
|
||||
home, _ := os.UserHomeDir()
|
||||
expected := filepath.Join(home, ConfigDir)
|
||||
|
||||
if root != expected {
|
||||
t.Errorf("期望 %s,得到 %s", expected, root)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConfigRoot_WithEnvOverride(t *testing.T) {
|
||||
testRoot := "/tmp/skillmgr-test"
|
||||
os.Setenv("SKILLMGR_TEST_ROOT", testRoot)
|
||||
defer os.Unsetenv("SKILLMGR_TEST_ROOT")
|
||||
|
||||
root, err := GetConfigRoot()
|
||||
if err != nil {
|
||||
t.Fatalf("GetConfigRoot 失败: %v", err)
|
||||
}
|
||||
|
||||
if root != testRoot {
|
||||
t.Errorf("期望 %s,得到 %s", testRoot, root)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureConfigDirs(t *testing.T) {
|
||||
tmpDir, err := os.MkdirTemp("", "skillmgr-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("创建临时目录失败: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
os.Setenv("SKILLMGR_TEST_ROOT", tmpDir)
|
||||
defer os.Unsetenv("SKILLMGR_TEST_ROOT")
|
||||
|
||||
if err := EnsureConfigDirs(); err != nil {
|
||||
t.Fatalf("EnsureConfigDirs 失败: %v", err)
|
||||
}
|
||||
|
||||
// 检查目录是否存在
|
||||
cacheDir := filepath.Join(tmpDir, CacheDir)
|
||||
if _, err := os.Stat(cacheDir); os.IsNotExist(err) {
|
||||
t.Errorf("缓存目录未创建: %s", cacheDir)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user