MCPcopy
hub / github.com/syncthing/syncthing / TestBlocksInserted

Function TestBlocksInserted

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

Source from the content-addressed store, hash-verified

1204}
1205
1206func TestBlocksInserted(t *testing.T) {
1207 // Verifies that blocks are inserted after syncing a file
1208
1209 t.Parallel()
1210
1211 sdb, err := Open(t.TempDir())
1212 if err != nil {
1213 t.Fatal(err)
1214 }
1215 t.Cleanup(func() {
1216 if err := sdb.Close(); err != nil {
1217 t.Fatal(err)
1218 }
1219 })
1220
1221 // Add remote file
1222
1223 files := []protocol.FileInfo{genFile("test1", 100, 1)}
1224 if err := sdb.Update(folderID, protocol.DeviceID{42}, files); err != nil {
1225 t.Fatal(err)
1226 }
1227
1228 // Add the same file locally
1229
1230 if err := sdb.Update(folderID, protocol.LocalDeviceID, files); err != nil {
1231 t.Fatal(err)
1232 }
1233
1234 // Verify all the blocks are here
1235
1236 for i, block := range files[0].Blocks {
1237 bs, err := itererr.Collect(sdb.AllLocalBlocksWithHash(folderID, block.Hash))
1238 if err != nil {
1239 t.Fatal(err)
1240 }
1241 if len(bs) == 0 {
1242 t.Error("missing blocks for", i)
1243 }
1244 }
1245}
1246
1247func mustCollect[T any](t *testing.T) func(it iter.Seq[T], errFn func() error) []T {
1248 t.Helper()

Callers

nothing calls this directly

Calls 8

CollectFunction · 0.92
OpenFunction · 0.85
genFileFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
UpdateMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected