1
0
Files
Skill/manager/internal/config/paths_test.go

61 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}