storage_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package blob_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/kopia/kopia/internal/blobtesting"
  6. "github.com/kopia/kopia/internal/gather"
  7. "github.com/kopia/kopia/internal/testlogging"
  8. "github.com/kopia/kopia/repo/blob"
  9. )
  10. func TestListAllBlobsConsistent(t *testing.T) {
  11. ctx := testlogging.Context(t)
  12. data := blobtesting.DataMap{}
  13. st := blobtesting.NewMapStorage(data, nil, time.Now)
  14. st.PutBlob(ctx, "foo1", gather.FromSlice([]byte{1, 2, 3})) //nolint:errcheck
  15. st.PutBlob(ctx, "foo2", gather.FromSlice([]byte{1, 2, 3})) //nolint:errcheck
  16. st.PutBlob(ctx, "foo3", gather.FromSlice([]byte{1, 2, 3})) //nolint:errcheck
  17. // set up faulty storage that will add a blob while a scan is in progress.
  18. f := &blobtesting.FaultyStorage{
  19. Base: st,
  20. Faults: map[string][]*blobtesting.Fault{
  21. "ListBlobsItem": {
  22. {ErrCallback: func() error {
  23. st.PutBlob(ctx, "foo0", gather.FromSlice([]byte{1, 2, 3})) //nolint:errcheck
  24. return nil
  25. }},
  26. },
  27. },
  28. }
  29. r, err := blob.ListAllBlobsConsistent(ctx, f, "foo", 3)
  30. if err != nil {
  31. t.Fatalf("error: %v", err)
  32. }
  33. // make sure we get the list with 4 items, not 3.
  34. if got, want := len(r), 4; got != want {
  35. t.Errorf("unexpected list result count: %v, want %v", got, want)
  36. }
  37. }
  38. func TestListAllBlobsConsistentEmpty(t *testing.T) {
  39. ctx := testlogging.Context(t)
  40. data := blobtesting.DataMap{}
  41. st := blobtesting.NewMapStorage(data, nil, time.Now)
  42. r, err := blob.ListAllBlobsConsistent(ctx, st, "foo", 3)
  43. if err != nil {
  44. t.Fatalf("error: %v", err)
  45. }
  46. if got, want := len(r), 0; got != want {
  47. t.Errorf("unexpected list result count: %v, want %v", got, want)
  48. }
  49. }