Skip to content

Commit

Permalink
test: update tests to have context
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Nov 18, 2024
1 parent 355191f commit 1df22db
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tracks/paged_list_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tracks

import (
"context"
"io"
"testing"

Expand All @@ -12,7 +13,7 @@ type dummyPageResolver struct {
page func(pageIdx int) ([]int, error)
}

func (d *dummyPageResolver) Page(idx int) ([]int, error) {
func (d *dummyPageResolver) Page(ctx context.Context, idx int) ([]int, error) {
return d.page(idx)
}

Expand All @@ -33,7 +34,7 @@ func TestPagedListSimpleIteration(t *testing.T) {
iter := list.iterStart()

for i := 0; i < 10; i++ {
if !iter.next() {
if !iter.next(context.Background()) {
t.Fatalf("iterator next returned false before end")
}

Expand All @@ -49,7 +50,7 @@ func TestPagedListSimpleIteration(t *testing.T) {
}
}

if iter.next() {
if iter.next(context.Background()) {
t.Fatalf("iterator next returned true after end")
} else if iter.error() != nil {
t.Fatalf("iterator error is not nil after end")
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestPagedListMoving(t *testing.T) {
iter := list.iterStart()

for i := 0; i < 13; i++ {
if !iter.next() {
if !iter.next(context.Background()) {
t.Fatalf("iterator next returned false before end")
}
}
Expand All @@ -107,7 +108,7 @@ func TestPagedListMoving(t *testing.T) {
t.Fatalf("item.item = %d, wanted %d", item.item, 12*100)
}

if list.moveStart() != nil {
if list.moveStart(context.Background()) != nil {
t.Fatalf("moveStart returned an error")
}

Expand Down Expand Up @@ -138,7 +139,7 @@ func TestPagedListShuffle(t *testing.T) {
// load all items
iter := list.iterStart()
for i := 0; i < 50; i++ {
if !iter.next() {
if !iter.next(context.Background()) {
t.Fatalf("iterator next returned false before end")
}

Expand All @@ -160,7 +161,7 @@ func TestPagedListShuffle(t *testing.T) {
// move to some position
iter = list.iterStart()
for i := 0; i < 36; i++ {
if !iter.next() {
if !iter.next(context.Background()) {
t.Fatalf("iterator next returned false before end")
}
}
Expand All @@ -183,7 +184,7 @@ func TestPagedListShuffle(t *testing.T) {
// check order is back to the original
iter = list.iterStart()
for i := 0; i < 50; i++ {
if !iter.next() {
if !iter.next(context.Background()) {
t.Fatalf("iterator next returned false before end")
}

Expand Down

0 comments on commit 1df22db

Please sign in to comment.