-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package local_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cheekybits/is" | ||
"github.com/graymeta/stow" | ||
"github.com/graymeta/stow/local" | ||
) | ||
|
||
func TestItemsPaging(t *testing.T) { | ||
is := is.New(t) | ||
testDir, teardown, err := setup() | ||
is.NoErr(err) | ||
defer teardown() | ||
cfg := stow.ConfigMap{"path": testDir} | ||
l, err := stow.Dial(local.Kind, cfg) | ||
is.NoErr(err) | ||
is.OK(l) | ||
|
||
// get the first container to work with | ||
containers, _, err := l.Containers("", stow.CursorStart) | ||
is.NoErr(err) | ||
is.True(len(containers) > 0) | ||
container := containers[0] | ||
|
||
// make 25 items | ||
for i := 0; i < 25; i++ { | ||
_, err := container.Put(fmt.Sprintf("item-%02d", i), strings.NewReader(`item`), 4) | ||
is.NoErr(err) | ||
} | ||
|
||
// get the first page | ||
items, cursor, err := container.Items("item-", stow.CursorStart) | ||
is.NoErr(err) | ||
is.OK(items) | ||
is.Equal(len(items), 10) | ||
is.OK(cursor) | ||
is.Equal(cursor, "item-10") | ||
|
||
// get the next page | ||
items, cursor, err = container.Items("item-", cursor) | ||
is.NoErr(err) | ||
is.OK(items) | ||
is.Equal(len(items), 10) | ||
is.OK(cursor) | ||
is.Equal(cursor, "item-20") | ||
|
||
// get the last page | ||
items, cursor, err = container.Items("item-", cursor) | ||
is.NoErr(err) | ||
is.OK(items) | ||
is.Equal(len(items), 5) | ||
is.True(stow.IsCursorEnd(cursor)) | ||
|
||
// bad cursor | ||
items, cursor, err = container.Items("item-", "made up cursor") | ||
is.Equal(err, stow.ErrBadCursor) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters