MCPcopy
hub / github.com/syncthing/syncthing / TestCheckConsistency

Function TestCheckConsistency

lib/protocol/protocol_test.go:413–465  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

411}
412
413func TestCheckConsistency(t *testing.T) {
414 cases := []struct {
415 fi FileInfo
416 ok bool
417 }{
418 {
419 // valid
420 fi: FileInfo{
421 Name: "foo",
422 Type: FileInfoTypeFile,
423 Blocks: []BlockInfo{{Size: 1234, Offset: 0, Hash: []byte{1, 2, 3, 4}}},
424 },
425 ok: true,
426 },
427 {
428 // deleted with blocks
429 fi: FileInfo{
430 Name: "foo",
431 Deleted: true,
432 Type: FileInfoTypeFile,
433 Blocks: []BlockInfo{{Size: 1234, Offset: 0, Hash: []byte{1, 2, 3, 4}}},
434 },
435 ok: false,
436 },
437 {
438 // no blocks
439 fi: FileInfo{
440 Name: "foo",
441 Type: FileInfoTypeFile,
442 },
443 ok: false,
444 },
445 {
446 // directory with blocks
447 fi: FileInfo{
448 Name: "foo",
449 Type: FileInfoTypeDirectory,
450 Blocks: []BlockInfo{{Size: 1234, Offset: 0, Hash: []byte{1, 2, 3, 4}}},
451 },
452 ok: false,
453 },
454 }
455
456 for _, tc := range cases {
457 err := checkFileInfoConsistency(tc.fi)
458 if tc.ok && err != nil {
459 t.Errorf("Unexpected error %v (want nil) for %v", err, tc.fi)
460 }
461 if !tc.ok && err == nil {
462 t.Errorf("Unexpected nil error for %v", tc.fi)
463 }
464 }
465}
466
467func TestBlockSize(t *testing.T) {
468 cases := []struct {

Callers

nothing calls this directly

Calls 1

checkFileInfoConsistencyFunction · 0.85

Tested by

no test coverage detected