storage_test.go 1.4 KB

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