From d62235ee58782b1353a0a795f9e4d35ac709ff28 Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Wed, 2 Feb 2022 13:06:01 -0600 Subject: [PATCH] Add test for listing an object (#1484) * Add test for listing an object * Add test for listing an object --- integration/buckets_test.go | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/integration/buckets_test.go b/integration/buckets_test.go index 12d3d4a40..e80b0eaa8 100644 --- a/integration/buckets_test.go +++ b/integration/buckets_test.go @@ -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) +}