Skip to content

Commit

Permalink
Add a bad yield
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 17, 2024
1 parent 7b06869 commit 2dd4abd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/batch/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func TestBySize(t *testing.T) {
return batches, err
}

badYield := func(batch [][]byte) error {
out := make([]string, len(batch))
for i, bytes := range batch {
out[i] = string(bytes)
}
return fmt.Errorf("yield failed for %v", out)
}

{
// Empty slice:
batches, err := testBySize([]string{}, 10, panicEncoder)
Expand All @@ -39,18 +47,18 @@ func TestBySize(t *testing.T) {
}
{
// Non-empty slice + two items that are < maxSize + yield returns error.
err := BySize([]string{"foo", "bar"}, 10, goodEncoder, func(batch [][]byte) error { return fmt.Errorf("yield failed") })
assert.ErrorContains(t, err, "yield failed")
err := BySize([]string{"foo", "bar"}, 10, goodEncoder, badYield)
assert.ErrorContains(t, err, "yield failed for [foo bar]")
}
{
// Non-empty slice + two items that are = maxSize + yield returns error.
err := BySize([]string{"foo", "bar"}, 6, goodEncoder, func(batch [][]byte) error { return fmt.Errorf("yield failed") })
assert.ErrorContains(t, err, "yield failed")
err := BySize([]string{"foo", "bar"}, 6, goodEncoder, badYield)
assert.ErrorContains(t, err, "yield failed for [foo bar]")
}
{
// Non-empty slice + two items that are > maxSize + yield returns error.
err := BySize([]string{"foo", "bar-baz"}, 8, goodEncoder, func(batch [][]byte) error { return fmt.Errorf("yield failed") })
assert.ErrorContains(t, err, "yield failed")
err := BySize([]string{"foo", "bar-baz"}, 8, goodEncoder, badYield)
assert.ErrorContains(t, err, "yield failed for [foo]")
}
{
// Non-empty slice + item is larger than max size:
Expand Down

0 comments on commit 2dd4abd

Please sign in to comment.