Skip to content

Commit

Permalink
refactor: test
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jan 31, 2024
1 parent 9fcd900 commit 5e16433
Showing 1 changed file with 63 additions and 36 deletions.
99 changes: 63 additions & 36 deletions pkg/storer/internal/upload/uploadstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,45 +574,72 @@ func TestChunkPutter(t *testing.T) {
t.Fatalf("Get(...): unexpected TagItem (-want +have):\n%s", diff)
}

var uploadItemsCount int
err = ts.IndexStore().Iterate(
storage.Query{
Factory: func() storage.Item { return &upload.UploadItem{} },
},
func(res storage.Result) (bool, error) {
pi := res.Entry.(*upload.UploadItem)
if pi.TagID == tag.TagID {
uploadItemsCount++
}
return false, nil
},
)
if err != nil {
t.Fatalf("iterate upload items: %v", err)
}
if uploadItemsCount != 0 {
t.Fatalf("want %d upload items. got %d", 0, uploadItemsCount)
}
t.Run("cleanup upload items", func(t *testing.T) {
var uploadItemsCount int
err = ts.IndexStore().Iterate(
storage.Query{
Factory: func() storage.Item { return &upload.UploadItem{} },
},
func(res storage.Result) (bool, error) {
pi := res.Entry.(*upload.UploadItem)
if pi.TagID == tag.TagID {
uploadItemsCount++
}
return false, nil
},
)
if err != nil {
t.Fatalf("iterate upload items: %v", err)
}
if uploadItemsCount != 0 {
t.Fatalf("want %d upload items. got %d", 0, uploadItemsCount)
}

var pushItemsCount int
err = ts.IndexStore().Iterate(
storage.Query{
Factory: func() storage.Item { return &upload.PushItem{} },
},
func(res storage.Result) (bool, error) {
pi := res.Entry.(*upload.PushItem)
if pi.TagID == tag.TagID {
pushItemsCount++
})
t.Run("cleanup push items", func(t *testing.T) {
var pushItemsCount int
err = ts.IndexStore().Iterate(
storage.Query{
Factory: func() storage.Item { return &upload.PushItem{} },
},
func(res storage.Result) (bool, error) {
pi := res.Entry.(*upload.PushItem)
if pi.TagID == tag.TagID {
pushItemsCount++
}
return false, nil
},
)
if err != nil {
t.Fatalf("iterate push items: %v", err)
}
if pushItemsCount != 0 {
t.Fatalf("want %d push items. got %d", 0, pushItemsCount)
}
})
t.Run("cleanup chunks", func(t *testing.T) {
count := 0
err := upload.IterateAll(ts.IndexStore(), func(addr swarm.Address, synced bool) (bool, error) {
count++
if synced {
t.Fatal("expected synced to be false")
}
has, err := ts.ChunkStore().Has(context.Background(), addr)
if err != nil {
t.Fatalf("unexpected error in Has(...): %v", err)
}
if !has {
t.Fatalf("expected chunk to be present %s", addr.String())
}
return false, nil
},
)
if err != nil {
t.Fatalf("iterate push items: %v", err)
}
if pushItemsCount != 0 {
t.Fatalf("want %d push items. got %d", 0, pushItemsCount)
}
})
if err != nil {
t.Fatalf("IterateAll(...): unexpected error %v", err)
}
if count != 0 {
t.Fatalf("unexpected count: want 0 have %d", count)
}
})
})

t.Run("error after close", func(t *testing.T) {
Expand Down

0 comments on commit 5e16433

Please sign in to comment.