Add test for listing an object (#1484)
* Add test for listing an object * Add test for listing an object
This commit is contained in:
committed by
GitHub
parent
e5d2752436
commit
d62235ee58
@@ -1341,3 +1341,55 @@ func TestDeleteObject(t *testing.T) {
|
||||
finalResponse,
|
||||
"testdeleteobjectfile1.txt"), finalResponse) // Gone
|
||||
}
|
||||
|
||||
func TestListObjects(t *testing.T) {
|
||||
/*
|
||||
To test list objects end point.
|
||||
*/
|
||||
|
||||
// Test's variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testlistobjecttobucket1"
|
||||
fileName := "testlistobjecttobucket1.txt"
|
||||
|
||||
// 1. Create the bucket
|
||||
response, err := AddBucket(bucketName, false, false, nil, nil)
|
||||
assert.Nil(err)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if response != nil {
|
||||
assert.Equal(201, response.StatusCode, "Status Code is incorrect")
|
||||
}
|
||||
|
||||
// 2. Upload the object to the bucket
|
||||
uploadResponse, uploadError := UploadAnObject(bucketName, fileName)
|
||||
assert.Nil(uploadError)
|
||||
if uploadError != nil {
|
||||
log.Println(uploadError)
|
||||
return
|
||||
}
|
||||
if uploadResponse != nil {
|
||||
assert.Equal(200, uploadResponse.StatusCode,
|
||||
inspectHTTPResponse(uploadResponse))
|
||||
}
|
||||
|
||||
// 3. List the object
|
||||
listResponse, listError := ListObjects(bucketName, "")
|
||||
assert.Nil(listError)
|
||||
if listError != nil {
|
||||
log.Println(listError)
|
||||
return
|
||||
}
|
||||
finalResponse := inspectHTTPResponse(listResponse)
|
||||
if listResponse != nil {
|
||||
assert.Equal(200, listResponse.StatusCode,
|
||||
finalResponse)
|
||||
}
|
||||
|
||||
// 4. Verify the object was listed
|
||||
assert.True(
|
||||
strings.Contains(finalResponse, "testlistobjecttobucket1"),
|
||||
finalResponse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user