MCPcopy
hub / github.com/syncthing/syncthing / TestAllForBlocksHash

Function TestAllForBlocksHash

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

Source from the content-addressed store, hash-verified

926}
927
928func TestAllForBlocksHash(t *testing.T) {
929 t.Parallel()
930
931 sdb, err := Open(t.TempDir())
932 if err != nil {
933 t.Fatal(err)
934 }
935 t.Cleanup(func() {
936 if err := sdb.Close(); err != nil {
937 t.Fatal(err)
938 }
939 })
940
941 // test1 is unique, while test2 and test3 have the same blocks and hence
942 // the same blocks hash
943
944 files := []protocol.FileInfo{
945 genFile("test1", 1, 1),
946 genFile("test2", 2, 2),
947 genFile("test3", 3, 3),
948 }
949 files[2].Blocks = files[1].Blocks
950
951 if err := sdb.Update(folderID, protocol.LocalDeviceID, files); err != nil {
952 t.Fatal(err)
953 }
954
955 // Check test1
956
957 test1, ok, err := sdb.GetDeviceFile(folderID, protocol.LocalDeviceID, "test1")
958 if err != nil || !ok {
959 t.Fatal("expected to exist")
960 }
961
962 vals := mustCollect[db.FileMetadata](t)(sdb.AllLocalFilesWithBlocksHash(folderID, test1.BlocksHash))
963 if len(vals) != 1 {
964 t.Log(vals)
965 t.Fatal("expected one file to match")
966 }
967
968 // Check test2 which also matches test3
969
970 test2, ok, err := sdb.GetDeviceFile(folderID, protocol.LocalDeviceID, "test2")
971 if err != nil || !ok {
972 t.Fatal("expected to exist")
973 }
974
975 vals = mustCollect[db.FileMetadata](t)(sdb.AllLocalFilesWithBlocksHash(folderID, test2.BlocksHash))
976 if len(vals) != 2 {
977 t.Log(vals)
978 t.Fatal("expected two files to match")
979 }
980 if vals[0].Name != "test2" {
981 t.Log(vals[0])
982 t.Error("expected test2")
983 }
984 if vals[1].Name != "test3" {
985 t.Log(vals[1])

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected