Merge pull request #572 from harshavardhana/pr_out_add_marker_support_for_donut_also_add_a_testing_code

master
Harshavardhana 10 years ago
commit 8c5a83ddcf
  1. 15
      pkg/storage/donut/objectstorage.go
  2. 16
      pkg/storage/drivers/api_testsuite.go

@ -134,9 +134,22 @@ func (d donut) ListObjects(bucket, prefix, marker, delimiter string, maxkeys int
actualObjects = donutObjects actualObjects = donutObjects
} }
sort.Strings(actualObjects)
var newActualObjects []string
switch {
case marker != "":
for _, objectName := range actualObjects {
if objectName > marker {
newActualObjects = append(newActualObjects, objectName)
}
}
default:
newActualObjects = actualObjects
}
var results []string var results []string
var commonPrefixes []string var commonPrefixes []string
for _, objectName := range actualObjects { for _, objectName := range newActualObjects {
if len(results) >= maxkeys { if len(results) >= maxkeys {
isTruncated = true isTruncated = true
break break

@ -181,10 +181,25 @@ func testPaging(c *check.C, create func() Driver) {
c.Assert(resources.CommonPrefixes[0], check.Equals, "this/") c.Assert(resources.CommonPrefixes[0], check.Equals, "this/")
} }
// check results with Marker
{
var prefixes []string
resources.CommonPrefixes = prefixes // allocate new everytime
resources.Prefix = ""
resources.Marker = "newPrefix"
resources.Delimiter = "/"
resources.Maxkeys = 3
objects, resources, err = drivers.ListObjects("bucket", resources)
c.Assert(objects[0].Key, check.Equals, "newPrefix2")
c.Assert(objects[1].Key, check.Equals, "obj0")
c.Assert(objects[2].Key, check.Equals, "obj1")
c.Assert(resources.CommonPrefixes[0], check.Equals, "this/")
}
// check ordering of results with prefix // check ordering of results with prefix
{ {
resources.Prefix = "obj" resources.Prefix = "obj"
resources.Delimiter = "" resources.Delimiter = ""
resources.Marker = ""
resources.Maxkeys = 1000 resources.Maxkeys = 1000
objects, resources, err = drivers.ListObjects("bucket", resources) objects, resources, err = drivers.ListObjects("bucket", resources)
c.Assert(objects[0].Key, check.Equals, "obj0") c.Assert(objects[0].Key, check.Equals, "obj0")
@ -196,6 +211,7 @@ func testPaging(c *check.C, create func() Driver) {
// check ordering of results with prefix and no paging // check ordering of results with prefix and no paging
{ {
resources.Prefix = "new" resources.Prefix = "new"
resources.Marker = ""
resources.Maxkeys = 5 resources.Maxkeys = 5
objects, resources, err = drivers.ListObjects("bucket", resources) objects, resources, err = drivers.ListObjects("bucket", resources)
c.Assert(objects[0].Key, check.Equals, "newPrefix") c.Assert(objects[0].Key, check.Equals, "newPrefix")

Loading…
Cancel
Save