(t *testing.T)
| 768 | } |
| 769 | |
| 770 | func TestDropAllFiles(t *testing.T) { |
| 771 | db, err := Open(t.TempDir()) |
| 772 | if err != nil { |
| 773 | t.Fatal(err) |
| 774 | } |
| 775 | t.Cleanup(func() { |
| 776 | if err := db.Close(); err != nil { |
| 777 | t.Fatal(err) |
| 778 | } |
| 779 | }) |
| 780 | |
| 781 | // Some local files |
| 782 | |
| 783 | // Device 1 folder A |
| 784 | err = db.Update("a", protocol.DeviceID{1}, []protocol.FileInfo{ |
| 785 | genFile("test1", 1, 1), |
| 786 | genFile("test2", 2, 2), |
| 787 | }) |
| 788 | if err != nil { |
| 789 | t.Fatal(err) |
| 790 | } |
| 791 | |
| 792 | // Device 1 folder B |
| 793 | err = db.Update("b", protocol.DeviceID{1}, []protocol.FileInfo{ |
| 794 | genFile("test1", 1, 1), |
| 795 | genFile("test2", 2, 2), |
| 796 | }) |
| 797 | if err != nil { |
| 798 | t.Fatal(err) |
| 799 | } |
| 800 | |
| 801 | // Drop folder A |
| 802 | if err := db.DropAllFiles("a", protocol.DeviceID{1}); err != nil { |
| 803 | t.Fatal(err) |
| 804 | } |
| 805 | |
| 806 | // Check |
| 807 | if _, ok, err := db.GetDeviceFile("a", protocol.DeviceID{1}, "test1"); err != nil || ok { |
| 808 | t.Log(err, ok) |
| 809 | t.Error("expected to not exist") |
| 810 | } |
| 811 | if c, err := db.CountLocal("a", protocol.DeviceID{1}); err != nil { |
| 812 | t.Fatal(err) |
| 813 | } else if c.Files != 0 { |
| 814 | t.Log(c) |
| 815 | t.Error("expected count to be zero") |
| 816 | } |
| 817 | if _, ok, err := db.GetDeviceFile("b", protocol.DeviceID{1}, "test1"); err != nil || !ok { |
| 818 | t.Log(err, ok) |
| 819 | t.Error("expected to exist") |
| 820 | } |
| 821 | if c, err := db.CountLocal("b", protocol.DeviceID{1}); err != nil { |
| 822 | t.Fatal(err) |
| 823 | } else if c.Files != 2 { |
| 824 | t.Log(c) |
| 825 | t.Error("expected count to be two") |
| 826 | } |
| 827 |
nothing calls this directly
no test coverage detected