Created
October 25, 2015 10:12
-
-
Save nabeken/b2a7bbc7e0b8bdaf703a to your computer and use it in GitHub Desktop.
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
func (s *BucketSuite) TestObject() { | |
key := "test-object" | |
ct := "application/json" | |
cl := int64(len(s.testdata)) | |
content, err := ioutils.NewFileReadSeeker(bytes.NewReader(s.testdata)) | |
if !s.NoError(err) { | |
return | |
} | |
defer content.Close() | |
// 1. Put new object | |
{ | |
_, err := s.bucket.PutObject( | |
key, | |
content, | |
option.ContentType(ct), | |
option.ContentLength(cl), | |
option.ACLPrivate(), | |
) | |
if !s.NoError(err) { | |
return | |
} | |
} | |
// 2. Get the object and assert its metadata and content | |
{ | |
object, err := s.bucket.GetObject(key) | |
if !s.NoError(err) { | |
return | |
} | |
body, err := ioutil.ReadAll(object.Body) | |
if !s.NoError(err) { | |
return | |
} | |
defer object.Body.Close() | |
s.Equal(ct, *object.ContentType) | |
s.Equal(cl, *object.ContentLength) | |
s.Equal(s.testdata, body) | |
} | |
// 3. The object must exist | |
{ | |
exists, err := s.bucket.ExistsObject(key) | |
s.NoError(err) | |
s.True(exists) | |
} | |
// 4. Delete the object | |
{ | |
_, err := s.bucket.DeleteObject(key) | |
if !s.NoError(err) { | |
return | |
} | |
} | |
// 5. Head the object | |
{ | |
_, err := s.bucket.HeadObject(key) | |
s.Error(err) | |
} | |
// 6. The object must not exist | |
{ | |
exists, err := s.bucket.ExistsObject(key) | |
s.NoError(err) | |
s.False(exists) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment