(t *testing.T)
| 3424 | } |
| 3425 | |
| 3426 | func TestBlockListMap(t *testing.T) { |
| 3427 | wcfg, fcfg := newDefaultCfgWrapper(t) |
| 3428 | m := setupModel(t, wcfg) |
| 3429 | defer cleanupModel(m) |
| 3430 | |
| 3431 | ffs := fcfg.Filesystem() |
| 3432 | writeFile(t, ffs, "one", []byte("content")) |
| 3433 | writeFile(t, ffs, "two", []byte("content")) |
| 3434 | writeFile(t, ffs, "three", []byte("content")) |
| 3435 | writeFile(t, ffs, "four", []byte("content")) |
| 3436 | writeFile(t, ffs, "five", []byte("content")) |
| 3437 | |
| 3438 | m.ScanFolders() |
| 3439 | |
| 3440 | fi, ok, err := m.model.CurrentFolderFile("default", "one") |
| 3441 | if err != nil { |
| 3442 | t.Fatal(err) |
| 3443 | } |
| 3444 | if !ok { |
| 3445 | t.Error("failed to find existing file") |
| 3446 | } |
| 3447 | var paths []string |
| 3448 | |
| 3449 | for fi, err := range itererr.Zip(m.model.AllForBlocksHash(fcfg.ID, fi.BlocksHash)) { |
| 3450 | if err != nil { |
| 3451 | t.Fatal(err) |
| 3452 | } |
| 3453 | paths = append(paths, fi.Name) |
| 3454 | } |
| 3455 | |
| 3456 | expected := []string{"one", "two", "three", "four", "five"} |
| 3457 | if !equalStringsInAnyOrder(paths, expected) { |
| 3458 | t.Fatalf("expected %q got %q", expected, paths) |
| 3459 | } |
| 3460 | |
| 3461 | // Fudge the files around |
| 3462 | // Remove |
| 3463 | must(t, ffs.Remove("one")) |
| 3464 | |
| 3465 | // Modify |
| 3466 | must(t, ffs.Remove("two")) |
| 3467 | writeFile(t, ffs, "two", []byte("mew-content")) |
| 3468 | |
| 3469 | // Rename |
| 3470 | must(t, ffs.Rename("three", "new-three")) |
| 3471 | |
| 3472 | // Change type |
| 3473 | must(t, ffs.Remove("four")) |
| 3474 | must(t, ffs.Mkdir("four", 0o644)) |
| 3475 | |
| 3476 | m.ScanFolders() |
| 3477 | |
| 3478 | // Check we're left with 2 of the 5 |
| 3479 | |
| 3480 | paths = paths[:0] |
| 3481 | for fi, err := range itererr.Zip(m.model.AllForBlocksHash(fcfg.ID, fi.BlocksHash)) { |
| 3482 | if err != nil { |
| 3483 | t.Fatal(err) |
nothing calls this directly
no test coverage detected