tests that we add the missing wholeRef entries in FileInfo rows when going from a version 4 to a version 5 index.
(t *testing.T)
| 594 | // tests that we add the missing wholeRef entries in FileInfo rows when going from |
| 595 | // a version 4 to a version 5 index. |
| 596 | func TestFixMissingWholeref(t *testing.T) { |
| 597 | ctx := context.Background() |
| 598 | tf := new(test.Fetcher) |
| 599 | s := sorted.NewMemoryKeyValue() |
| 600 | |
| 601 | ix, err := index.New(s) |
| 602 | if err != nil { |
| 603 | t.Fatal(err) |
| 604 | } |
| 605 | ix.InitBlobSource(tf) |
| 606 | |
| 607 | // populate with a file |
| 608 | add := func(b *test.Blob) { |
| 609 | tf.AddBlob(b) |
| 610 | if _, err := ix.ReceiveBlob(ctxbg, b.BlobRef(), b.Reader()); err != nil { |
| 611 | t.Fatalf("ReceiveBlob(%v): %v", b.BlobRef(), err) |
| 612 | } |
| 613 | } |
| 614 | add(chunk1) |
| 615 | add(chunk2) |
| 616 | add(chunk3) |
| 617 | add(fileBlob) |
| 618 | |
| 619 | // revert the row to the old form, by stripping the wholeRef suffix |
| 620 | key := "fileinfo|" + fileBlobRef.String() |
| 621 | val5, err := s.Get(key) |
| 622 | if err != nil { |
| 623 | t.Fatalf("could not get %v: %v", key, err) |
| 624 | } |
| 625 | parts := strings.SplitN(val5, "|", 4) |
| 626 | val4 := strings.Join(parts[:3], "|") |
| 627 | if err := s.Set(key, val4); err != nil { |
| 628 | t.Fatalf("could not set (%v, %v): %v", key, val4, err) |
| 629 | } |
| 630 | |
| 631 | // revert index version at 4 to trigger the fix |
| 632 | if err := s.Set("schemaversion", "4"); err != nil { |
| 633 | t.Fatal(err) |
| 634 | } |
| 635 | |
| 636 | // init broken index |
| 637 | ix, err = index.New(s) |
| 638 | if err != index.Exp_ErrMissingWholeRef { |
| 639 | t.Fatalf("wrong error upon index initialization: got %v, wanted %v", err, index.Exp_ErrMissingWholeRef) |
| 640 | } |
| 641 | // and fix it |
| 642 | if err := ix.Exp_FixMissingWholeRef(tf); err != nil { |
| 643 | t.Fatal(err) |
| 644 | } |
| 645 | |
| 646 | // init fixed index |
| 647 | ix, err = index.New(s) |
| 648 | if err != nil { |
| 649 | t.Fatal(err) |
| 650 | } |
| 651 | // and check that the value is now actually fixed |
| 652 | fi, err := ix.GetFileInfo(ctx, fileBlobRef) |
| 653 | if err != nil { |
nothing calls this directly
no test coverage detected