(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func 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 | |
| 68 | func TestFilePreferenceStorage_Load(t *testing.T) { |
| 69 | tmpDir := filepath.Join(os.TempDir(), "test-preferences-load") |
nothing calls this directly
no test coverage detected