(t *testing.T, label string, cleanupBadFiles bool)
| 259 | } |
| 260 | |
| 261 | func testSimpleStoreCleanupBadFiles(t *testing.T, |
| 262 | label string, |
| 263 | cleanupBadFiles bool) { |
| 264 | testSimpleStoreEx(t, label, map[string]func(string){ |
| 265 | "beforeReopen": func(tmpDir string) { |
| 266 | // Create some junk files that should be removed automatically. |
| 267 | s := &Store{ |
| 268 | dir: tmpDir, |
| 269 | nextFNameSeq: 100, |
| 270 | options: &StoreOptions{ |
| 271 | OpenFile: func(name string, flag int, perm os.FileMode) (File, error) { |
| 272 | return os.OpenFile(name, flag, perm) |
| 273 | }, |
| 274 | }, |
| 275 | fileRefMap: make(map[string]*FileRef), |
| 276 | } |
| 277 | |
| 278 | fref, file, err := s.startFileLOCKED() |
| 279 | if err != nil || file == nil { |
| 280 | t.Errorf("expected startFileLocked to work, err: %v", err) |
| 281 | } |
| 282 | fref.DecRef() |
| 283 | |
| 284 | fref, file, err = s.startFileLOCKED() |
| 285 | if err != nil || file == nil { |
| 286 | t.Errorf("expected startFileLocked to work, err: %v", err) |
| 287 | } |
| 288 | fref.DecRef() |
| 289 | }, |
| 290 | "done": func(tmpDir string) { |
| 291 | fileInfos, err := ioutil.ReadDir(tmpDir) |
| 292 | if err != nil { |
| 293 | t.Errorf("expected readdir to work, err: %v", err) |
| 294 | } |
| 295 | |
| 296 | if cleanupBadFiles { |
| 297 | // All the junk files should have been removed automatically already. |
| 298 | if len(fileInfos) != 1 { |
| 299 | t.Errorf("expected only 1 file, saw: %v", fileInfos) |
| 300 | } |
| 301 | } else { |
| 302 | if len(fileInfos) != 3 { |
| 303 | t.Errorf("expected 3 files, saw: %v", fileInfos) |
| 304 | } |
| 305 | } |
| 306 | }, |
| 307 | }, |
| 308 | StoreOptions{KeepFiles: !cleanupBadFiles}, |
| 309 | StorePersistOptions{}, |
| 310 | CollectionOptions{}, |
| 311 | 102) |
| 312 | } |
| 313 | |
| 314 | func testSimpleStoreEx(t *testing.T, |
| 315 | label string, |
no test coverage detected
searching dependent graphs…