MCPcopy Index your code
hub / github.com/syncthing/syncthing / TestDropAllFiles

Function TestDropAllFiles

internal/db/sqlite/db_test.go:770–838  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

768}
769
770func 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

Callers

nothing calls this directly

Calls 10

OpenFunction · 0.85
genFileFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
UpdateMethod · 0.65
DropAllFilesMethod · 0.65
GetDeviceFileMethod · 0.65
LogMethod · 0.65
ErrorMethod · 0.65
CountLocalMethod · 0.65

Tested by

no test coverage detected