MCPcopy Create free account
hub / github.com/astercloud/aster / TestFilePreferenceStorage_Load

Function TestFilePreferenceStorage_Load

pkg/memory/preference_storage_test.go:68–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestFilePreferenceStorage_Load(t *testing.T) {
69 tmpDir := filepath.Join(os.TempDir(), "test-preferences-load")
70 defer func() {
71 if err := os.RemoveAll(tmpDir); err != nil {
72 t.Errorf("Failed to remove temp dir: %v", err)
73 }
74 }()
75
76 storage, _ := NewFilePreferenceStorage(tmpDir)
77
78 // 保存偏好
79 original := []*Preference{
80 {
81 ID: "pref-1",
82 UserID: "user-1",
83 Category: CategoryUI,
84 Key: "theme",
85 Value: "dark",
86 Strength: 0.8,
87 Confidence: 0.9,
88 },
89 }
90 if err := storage.Save(context.Background(), "user-1", original); err != nil {
91 t.Fatalf("Save failed: %v", err)
92 }
93
94 // 加载偏好
95 loaded, err := storage.Load(context.Background(), "user-1")
96 if err != nil {
97 t.Fatalf("Load failed: %v", err)
98 }
99
100 if len(loaded) != 1 {
101 t.Errorf("loaded %d preferences, want 1", len(loaded))
102 }
103
104 if loaded[0].ID != "pref-1" {
105 t.Errorf("ID = %s, want 'pref-1'", loaded[0].ID)
106 }
107
108 if loaded[0].Value != "dark" {
109 t.Errorf("Value = %s, want 'dark'", loaded[0].Value)
110 }
111}
112
113func TestFilePreferenceStorage_Load_NotExist(t *testing.T) {
114 tmpDir := filepath.Join(os.TempDir(), "test-preferences-not-exist")

Callers

nothing calls this directly

Calls 4

SaveMethod · 0.95
LoadMethod · 0.95
NewFilePreferenceStorageFunction · 0.85
JoinMethod · 0.45

Tested by

no test coverage detected