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

Function TestFilePreferenceStorage_List

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

Source from the content-addressed store, hash-verified

163}
164
165func TestFilePreferenceStorage_List(t *testing.T) {
166 tmpDir := filepath.Join(os.TempDir(), "test-preferences-list")
167 defer func() {
168 if err := os.RemoveAll(tmpDir); err != nil {
169 t.Errorf("Failed to remove temp dir: %v", err)
170 }
171 }()
172
173 storage, _ := NewFilePreferenceStorage(tmpDir)
174
175 // 保存多个用户的偏好
176 users := []string{"user-1", "user-2", "user-3"}
177 for _, userID := range users {
178 prefs := []*Preference{
179 {ID: "pref-1", UserID: userID, Category: CategoryUI, Key: "theme", Value: "dark"},
180 }
181 if err := storage.Save(context.Background(), userID, prefs); err != nil {
182 t.Fatalf("Save failed: %v", err)
183 }
184 }
185
186 // 列出所有用户
187 userIDs, err := storage.List(context.Background())
188 if err != nil {
189 t.Fatalf("List failed: %v", err)
190 }
191
192 if len(userIDs) != 3 {
193 t.Errorf("List returned %d users, want 3", len(userIDs))
194 }
195}
196
197func TestNewPersistentPreferenceManager(t *testing.T) {
198 tmpDir := filepath.Join(os.TempDir(), "test-persistent-manager")

Callers

nothing calls this directly

Calls 4

SaveMethod · 0.95
ListMethod · 0.95
NewFilePreferenceStorageFunction · 0.85
JoinMethod · 0.45

Tested by

no test coverage detected