Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
z4ce committed Oct 19, 2017
1 parent adb4ae2 commit 6883486
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ func ptrTo(s string) *string {
return &s
}

func ptrToI(s int64) *int64 {
return &s
}

func ptrToB(s bool) *bool {
return &s
}

func TestMain(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Main")
Expand All @@ -34,6 +42,49 @@ func (m *mockS3Client) CopyObject(input *s3.CopyObjectInput) (*s3.CopyObjectOutp
return nil, nil
}

func (m *mockS3Client) DeleteObject(input *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error) {
m.Key = input.Key
m.Bucket = input.Bucket
return nil, nil
}

func (m *mockS3Client) ListObjectVersionsPages(input *s3.ListObjectVersionsInput, process func(p *s3.ListObjectVersionsOutput, last bool) (shouldContinue bool)) error {
startTime := time.Now()
startTimeMinusHour := startTime.Add(time.Hour * -1)
output := s3.ListObjectVersionsOutput{
Versions: []*s3.ObjectVersion{
&s3.ObjectVersion{
ETag: ptrTo("\"6994d44ab6c3b4c005357798f6b0d750\""),
IsLatest: ptrToB(false),
Key: ptrTo("file2"),
LastModified: &startTimeMinusHour,
Owner: &s3.Owner{
DisplayName: ptrTo("user"),
ID: ptrTo("ownerid"),
},
Size: ptrToI(6),
StorageClass: ptrTo("STANDARD"),
VersionId: ptrTo("versionid1"),
},
&s3.ObjectVersion{
ETag: ptrTo("\"6994d44ab6c3b4c005357798f6b0d750\""),
IsLatest: ptrToB(false),
Key: ptrTo("file1"),
LastModified: &startTime,
Owner: &s3.Owner{
DisplayName: ptrTo("user"),
ID: ptrTo("ownerid"),
},
Size: ptrToI(6),
StorageClass: ptrTo("STANDARD"),
VersionId: ptrTo("versionid1"),
},
},
}
process(&output, true)
return nil
}

var _ = Describe("Main", func() {
It("deletes correctly", func() {
final := make(map[string]s3.ObjectVersion)
Expand Down Expand Up @@ -155,4 +206,20 @@ var _ = Describe("Main", func() {
Expect(*(mockSvc.Bucket)).To(Equal("bucket"))
Expect(*(mockSvc.CopySrc)).To(Equal("/bucket/key?versionId=versionid"))
})

It("Deletes when a version is marked", func() {
mockSvc := &mockS3Client{}
setVersion(mockSvc, "bucket", "key", "DELETE")
Expect(*(mockSvc.Key)).To(Equal("key"))
Expect(*(mockSvc.Bucket)).To(Equal("bucket"))
})
It("Processes a dictionary of versions", func() {
startTime := time.Now()
mockSvc := &mockS3Client{}
dict, err := buildVersionDictionary(mockSvc, "bucket", startTime)
Expect(err).To(BeNil())
Expect(*(dict["file2"].VersionId)).To(Equal("versionid1"))
Expect(*(dict["file1"].VersionId)).To(Equal("DELETE"))

})
})

0 comments on commit 6883486

Please sign in to comment.