MCPcopy
hub / github.com/restic/restic / TestCheckerModifiedData

Function TestCheckerModifiedData

internal/checker/checker_test.go:356–435  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

354}
355
356func TestCheckerModifiedData(t *testing.T) {
357 repo, _, be := repository.TestRepositoryWithVersion(t, 0)
358 sn := archiver.TestSnapshot(t, repo, ".", nil)
359 t.Logf("archived as %v", sn.ID().Str())
360
361 errBe := &errorBackend{Backend: be}
362
363 for _, test := range []struct {
364 name string
365 be backend.Backend
366 damage func()
367 check func(t *testing.T, err error)
368 }{
369 {
370 "errorBackend",
371 errBe,
372 func() {
373 errBe.ProduceErrors = true
374 },
375 func(t *testing.T, err error) {
376 if err == nil {
377 t.Fatal("no error found, checker is broken")
378 }
379 },
380 },
381 {
382 "errorOnceBackend",
383 &errorOnceBackend{Backend: be},
384 func() {},
385 func(t *testing.T, err error) {
386 if !strings.Contains(err.Error(), "check successful on second attempt, original error pack") {
387 t.Fatalf("wrong error found, got %v", err)
388 }
389 },
390 },
391 {
392 // ignore if a backend returns incomplete garbled data on the first try
393 "corruptPartialOnceBackend",
394 &errorOnceBackend{Backend: be, shortenBy: 10, maxErrorOffset: 100},
395 func() {},
396 func(t *testing.T, err error) {
397 test.Assert(t, err == nil, "unexpected error found, got %v", err)
398 },
399 },
400 } {
401 t.Run(test.name, func(t *testing.T) {
402 checkRepo := repository.TestOpenBackend(t, test.be)
403
404 chkr := checker.New(checkRepo, false)
405
406 hints, errs := chkr.LoadIndex(context.TODO(), nil)
407 if len(errs) > 0 {
408 t.Fatalf("expected no errors, got %v: %v", len(errs), errs)
409 }
410
411 if len(hints) > 0 {
412 t.Errorf("expected no hints, got %v: %v", len(hints), hints)
413 }

Callers

nothing calls this directly

Calls 15

TestSnapshotFunction · 0.92
AssertFunction · 0.92
TestOpenBackendFunction · 0.92
NewFunction · 0.92
checkPacksFunction · 0.85
checkStructFunction · 0.85
checkDataFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80
RunMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected