(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func 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 | |
| 113 | func TestFilePreferenceStorage_Load_NotExist(t *testing.T) { |
| 114 | tmpDir := filepath.Join(os.TempDir(), "test-preferences-not-exist") |
nothing calls this directly
no test coverage detected