Skip to content

Commit

Permalink
b2: add failing test for key and obj lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kurin committed Jul 22, 2018
1 parent d745b0f commit b5c7a27
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion b2/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ func TestVerifyReader(t *testing.T) {
}
}

func TestListWithKey(t *testing.T) {
func TestListBucketsWithKey(t *testing.T) {
ctx := context.Background()
bucket, done := startLiveTest(ctx, t)
defer done()
Expand All @@ -1033,6 +1033,43 @@ func TestListWithKey(t *testing.T) {
}
}

func TestListBucketContentsWithKey(t *testing.T) {
ctx := context.Background()
bucket, done := startLiveTest(ctx, t)
defer done()

for _, path := range []string{"foo/bar", "foo/baz", "foo", "bar", "baz"} {
if _, _, err := writeFile(ctx, bucket, path, 1, 1e8); err != nil {
t.Fatal(err)
}
}

key, err := bucket.CreateKey(ctx, "testKey", Capabilities("listBuckets", "listFiles"), Prefix("foo/"))
if err != nil {
t.Fatal(err)
}
client, err := NewClient(ctx, key.ID(), key.Secret())
if err != nil {
t.Fatal(err)
}
obucket, err := client.Bucket(ctx, bucket.Name())
if err != nil {
t.Fatal(err)
}
iter := obucket.List(ctx)
var got []string
for iter.Next() {
got = append(got, iter.Object().Name())
}
if iter.Err() != nil {
t.Fatal(iter.Err())
}
want := []string{"foo/bar", "foo/baz"}
if !reflect.DeepEqual(got, want) {
t.Errorf("error listing objects with restricted key: got %v, want %v", got, want)
}
}

func TestCreateDeleteKey(t *testing.T) {
ctx := context.Background()
bucket, done := startLiveTest(ctx, t)
Expand Down

0 comments on commit b5c7a27

Please sign in to comment.