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

Function TestFilePreferenceStorage_Save

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

Source from the content-addressed store, hash-verified

32}
33
34func TestFilePreferenceStorage_Save(t *testing.T) {
35 tmpDir := filepath.Join(os.TempDir(), "test-preferences-save")
36 defer func() {
37 if err := os.RemoveAll(tmpDir); err != nil {
38 t.Errorf("Failed to remove temp dir: %v", err)
39 }
40 }()
41
42 storage, _ := NewFilePreferenceStorage(tmpDir)
43
44 preferences := []*Preference{
45 {
46 ID: "pref-1",
47 UserID: "user-1",
48 Category: CategoryUI,
49 Key: "theme",
50 Value: "dark",
51 Strength: 0.8,
52 Confidence: 0.9,
53 },
54 }
55
56 err := storage.Save(context.Background(), "user-1", preferences)
57 if err != nil {
58 t.Fatalf("Save failed: %v", err)
59 }
60
61 // 验证文件是否创建
62 filePath := filepath.Join(tmpDir, "user-1.json")
63 if _, err := os.Stat(filePath); os.IsNotExist(err) {
64 t.Error("preference file should be created")
65 }
66}
67
68func TestFilePreferenceStorage_Load(t *testing.T) {
69 tmpDir := filepath.Join(os.TempDir(), "test-preferences-load")

Callers

nothing calls this directly

Calls 5

SaveMethod · 0.95
NewFilePreferenceStorageFunction · 0.85
StatMethod · 0.65
ErrorMethod · 0.65
JoinMethod · 0.45

Tested by

no test coverage detected