Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
fix dir permission
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv committed Jan 29, 2021
1 parent 7b8f409 commit 699f84e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pkg/storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ type s3Suite struct {
storage *S3Storage
}

type s3SuiteCustom struct{}

var _ = Suite(&s3Suite{})
var _ = Suite(&s3SuiteCustom{})

// FIXME: Cannot use the real SetUpTest/TearDownTest to set up the mock
// otherwise the mock error will be ignored.
Expand Down Expand Up @@ -893,3 +896,62 @@ func (s *s3Suite) TestWalkDir(c *C) {
c.Assert(err, IsNil)
c.Assert(i, Equals, len(contents))
}

// TestWalkDirBucket checks WalkDir retrieves all directory content under a bucket.
func (s *s3SuiteCustom) TestWalkDirBucket(c *C) {
controller := gomock.NewController(c)
s3API := mock.NewMockS3API(controller)
storage := NewS3StorageForTest(
s3API,
&backup.S3{
Region: "us-west-2",
Bucket: "bucket",
Prefix: "",
Acl: "acl",
Sse: "sse",
StorageClass: "sc",
},
)
defer controller.Finish()
ctx := aws.BackgroundContext()

contents := []*s3.Object{
{
Key: aws.String("sp/.gitignore"),
Size: aws.Int64(437),
},
{
Key: aws.String("prefix/sp/01.jpg"),
Size: aws.Int64(27499),
},
}
s3API.EXPECT().
ListObjectsWithContext(ctx, gomock.Any()).
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) {
c.Assert(aws.StringValue(input.Bucket), Equals, "bucket")
c.Assert(aws.StringValue(input.Prefix), Equals, nil)
c.Assert(aws.StringValue(input.Marker), Equals, "")
c.Assert(aws.Int64Value(input.MaxKeys), Equals, int64(2))
c.Assert(aws.StringValue(input.Delimiter), Equals, "")
return &s3.ListObjectsOutput{
IsTruncated: aws.Bool(true),
Contents: contents,
}, nil
})

// Ensure we receive the items in order.
i := 0
err := storage.WalkDir(
ctx,
&WalkOption{SubDir: "sp", ListCount: 2},
func(path string, size int64) error {
comment := Commentf("index = %d", i)
c.Assert(path, Equals, *contents[i].Key, comment)
c.Assert(size, Equals, *contents[i].Size, comment)
i++
return nil
},
)
c.Assert(err, IsNil)
c.Assert(i, Equals, len(contents))
}

0 comments on commit 699f84e

Please sign in to comment.