(t *testing.T)
| 354 | } |
| 355 | |
| 356 | func 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 | } |
nothing calls this directly
no test coverage detected