Cleaning our logs for clarity (#1670)
Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5977e9e82f
commit
fd09a4c815
@@ -131,7 +131,7 @@ func NotifyPostgres() (*http.Response, error) {
|
||||
}
|
||||
|
||||
func TestNotifyPostgres(t *testing.T) {
|
||||
|
||||
printStartFunc("TestNotifyPostgres")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -147,9 +147,11 @@ func TestNotifyPostgres(t *testing.T) {
|
||||
if response != nil {
|
||||
assert.Equal(200, response.StatusCode, finalResponse)
|
||||
}
|
||||
printEndFunc("TestNotifyPostgres")
|
||||
}
|
||||
|
||||
func TestRestartService(t *testing.T) {
|
||||
printStartFunc("TestRestartService")
|
||||
assert := assert.New(t)
|
||||
restartResponse, restartError := RestartService()
|
||||
assert.Nil(restartError)
|
||||
@@ -165,4 +167,5 @@ func TestRestartService(t *testing.T) {
|
||||
addObjRsp,
|
||||
)
|
||||
}
|
||||
printEndFunc("TestRestartService")
|
||||
}
|
||||
|
||||
@@ -62,6 +62,30 @@ func printMessage(message string) {
|
||||
fmt.Println(message)
|
||||
}
|
||||
|
||||
func printLoggingMessage(message string, functionName string) {
|
||||
/*
|
||||
Helper function to have standard output across the tests.
|
||||
*/
|
||||
finalString := "......................." + functionName + "(): " + message
|
||||
printMessage(finalString)
|
||||
}
|
||||
|
||||
func printStartFunc(functionName string) {
|
||||
/*
|
||||
Common function for all tests to tell that test has started
|
||||
*/
|
||||
printMessage("")
|
||||
printLoggingMessage("started", functionName)
|
||||
}
|
||||
|
||||
func printEndFunc(functionName string) {
|
||||
/*
|
||||
Helper function for all tests to tell that test has ended, is completed
|
||||
*/
|
||||
printLoggingMessage("completed", functionName)
|
||||
printMessage("")
|
||||
}
|
||||
|
||||
func initConsoleServer() (*restapi.Server, error) {
|
||||
|
||||
//os.Setenv("CONSOLE_MINIO_SERVER", "localhost:9000")
|
||||
@@ -99,7 +123,7 @@ func initConsoleServer() (*restapi.Server, error) {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
printStartFunc("TestMain")
|
||||
// start console server
|
||||
go func() {
|
||||
fmt.Println("start server")
|
||||
@@ -188,6 +212,6 @@ func TestMain(m *testing.M) {
|
||||
if response != nil {
|
||||
fmt.Println("DELETE StatusCode:", response.StatusCode)
|
||||
}
|
||||
|
||||
printEndFunc("TestMain")
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
)
|
||||
|
||||
func TestLoginStrategy(t *testing.T) {
|
||||
printStartFunc("TestLoginStrategy")
|
||||
assert := assert.New(t)
|
||||
|
||||
// image for now:
|
||||
@@ -67,5 +68,5 @@ func TestLoginStrategy(t *testing.T) {
|
||||
assert.Equal(models.LoginDetailsLoginStrategyForm, loginDetails.LoginStrategy, "Login Details don't match")
|
||||
|
||||
}
|
||||
|
||||
printEndFunc("TestLoginStrategy")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
tests like users.ts can run over clean data and we don't collide against
|
||||
it.
|
||||
*/
|
||||
|
||||
printStartFunc("TestAddServiceAccount")
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &http.Client{
|
||||
@@ -46,13 +46,11 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
// Add service account
|
||||
fmt.Println(".......................TestServiceAccountPolicy(): Create Data to add user")
|
||||
requestDataAddServiceAccount := map[string]interface{}{
|
||||
"accessKey": "testuser1",
|
||||
"secretKey": "password",
|
||||
}
|
||||
|
||||
fmt.Println("..............................TestServiceAccountPolicy(): Prepare the POST")
|
||||
requestDataJSON, _ := json.Marshal(requestDataAddServiceAccount)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
@@ -64,17 +62,11 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println(".................................TestServiceAccountPolicy(): Make the POST")
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestServiceAccountPolicy(): Verification")
|
||||
fmt.Println(".................................TestServiceAccountPolicy(): POST response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("....................................TestServiceAccountPolicy(): POST error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("POST StatusCode:", response.StatusCode)
|
||||
assert.Equal(201, response.StatusCode, "Status Code is incorrect")
|
||||
@@ -97,7 +89,6 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
]
|
||||
}`,
|
||||
}
|
||||
fmt.Println("..............................TestServiceAccountPolicy(): Prepare the PUT")
|
||||
requestDataJSON, _ = json.Marshal(requestDataPolicy)
|
||||
requestDataBody = bytes.NewReader(requestDataJSON)
|
||||
request, err = http.NewRequest(
|
||||
@@ -108,27 +99,17 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println(".................................TestServiceAccountPolicy(): Make the PUT")
|
||||
response, err = client.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestServiceAccountPolicy(): Verification")
|
||||
fmt.Println(".................................TestServiceAccountPolicy(): PUT response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("....................................TestServiceAccountPolicy(): PUT error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("POST StatusCode:", response.StatusCode)
|
||||
assert.Equal(200, response.StatusCode, "Status Code is incorrect")
|
||||
}
|
||||
|
||||
fmt.Println("...................................TestServiceAccountPolicy(): Check policy")
|
||||
|
||||
// Test policy
|
||||
fmt.Println(".......................TestAddUserServiceAccount(): Create Data to add user")
|
||||
request, err = http.NewRequest(
|
||||
"GET", "http://localhost:9090/api/v1/service-accounts/testuser1/policy", nil)
|
||||
if err != nil {
|
||||
@@ -137,18 +118,11 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println(".................................TestAddServiceAccount(): Make the POST")
|
||||
response, err = client.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestAddServiceAccount(): Verification")
|
||||
fmt.Println(".................................TestAddServiceAccount(): POST response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("....................................TestAddServiceAccount(): POST error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("POST StatusCode:", response.StatusCode)
|
||||
assert.Equal(200, response.StatusCode, "Status Code is incorrect")
|
||||
@@ -166,8 +140,6 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
fmt.Println("...................................TestServiceAccountPolicy(): Remove service account")
|
||||
|
||||
// {{baseUrl}}/user?name=proident velit
|
||||
// Investiga como se borra en el browser.
|
||||
request, err = http.NewRequest(
|
||||
@@ -178,21 +150,14 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println("...............................TestServiceAccountPolicy(): Make the DELETE")
|
||||
response, err = client.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestServiceAccountPolicy(): Verification")
|
||||
fmt.Println("...............................TestServiceAccountPolicy(): DELETE response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("..................................TestServiceAccountPolicy(): DELETE error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("DELETE StatusCode:", response.StatusCode)
|
||||
assert.Equal(204, response.StatusCode, "has to be 204 when delete user")
|
||||
}
|
||||
|
||||
printEndFunc("TestAddServiceAccount")
|
||||
}
|
||||
|
||||
@@ -636,6 +636,7 @@ func PutObjectsLegalholdStatus(bucketName string, prefix string, status string,
|
||||
}
|
||||
|
||||
func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
printStartFunc("TestPutObjectsLegalholdStatus")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjectslegalholdstatus"
|
||||
@@ -675,8 +676,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, listError := ListObjects(bucketName, prefix, "true")
|
||||
fmt.Println(listError)
|
||||
listResponse, _ := ListObjects(bucketName, prefix, "true")
|
||||
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err = json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -731,10 +731,11 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestPutObjectsLegalholdStatus")
|
||||
}
|
||||
|
||||
func TestGetBucketQuota(t *testing.T) {
|
||||
|
||||
printStartFunc("TestGetBucketQuota")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
validBucket := "testgetbucketquota"
|
||||
@@ -816,10 +817,11 @@ func TestGetBucketQuota(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestGetBucketQuota")
|
||||
}
|
||||
|
||||
func TestPutBucketQuota(t *testing.T) {
|
||||
|
||||
printStartFunc("TestPutBucketQuota")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
validBucket := "testputbucketquota"
|
||||
@@ -883,10 +885,11 @@ func TestPutBucketQuota(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestPutBucketQuota")
|
||||
}
|
||||
|
||||
func TestListBucketEvents(t *testing.T) {
|
||||
|
||||
printStartFunc("TestListBucketEvents")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
validBucket := "testlistbucketevents"
|
||||
@@ -949,10 +952,11 @@ func TestListBucketEvents(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
printEndFunc("TestListBucketEvents")
|
||||
}
|
||||
|
||||
func TestDeleteObjectsRetentionStatus(t *testing.T) {
|
||||
|
||||
printStartFunc("TestDeleteObjectsRetentionStatus")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdeleteobjectslegalholdstatus"
|
||||
@@ -991,8 +995,7 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, listError := ListObjects(bucketName, validPrefix, "true")
|
||||
fmt.Println(listError)
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
|
||||
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err = json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1067,10 +1070,11 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestDeleteObjectsRetentionStatus")
|
||||
}
|
||||
|
||||
func TestBucketSetPolicy(t *testing.T) {
|
||||
|
||||
printStartFunc("TestBucketSetPolicy")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
validBucketName := "testbucketsetpolicy"
|
||||
@@ -1136,10 +1140,11 @@ func TestBucketSetPolicy(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
printEndFunc("TestBucketSetPolicy")
|
||||
}
|
||||
|
||||
func TestRestoreObjectToASelectedVersion(t *testing.T) {
|
||||
|
||||
printStartFunc("TestRestoreObjectToASelectedVersion")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testrestoreobjectstoselectedversion"
|
||||
@@ -1178,8 +1183,7 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
// 3. Get versionID
|
||||
listResponse, listError := ListObjects(bucketName, validPrefix, "true")
|
||||
fmt.Println(listError)
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
|
||||
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err = json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1235,9 +1239,11 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestRestoreObjectToASelectedVersion")
|
||||
}
|
||||
|
||||
func TestPutBucketsTags(t *testing.T) {
|
||||
printStartFunc("TestPutBucketsTags")
|
||||
// Focused test for "Put Bucket's tags" endpoint
|
||||
|
||||
// 1. Create the bucket
|
||||
@@ -1298,10 +1304,11 @@ func TestPutBucketsTags(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
printEndFunc("TestPutBucketsTags")
|
||||
}
|
||||
|
||||
func TestGetsTheMetadataOfAnObject(t *testing.T) {
|
||||
|
||||
printStartFunc("TestGetsTheMetadataOfAnObject")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
bucketName := "testgetsthemetadataofanobject"
|
||||
@@ -1380,10 +1387,11 @@ func TestGetsTheMetadataOfAnObject(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
printEndFunc("TestGetsTheMetadataOfAnObject")
|
||||
}
|
||||
|
||||
func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
|
||||
printStartFunc("TestPutObjectsRetentionStatus")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjectsretentionstatus"
|
||||
@@ -1422,8 +1430,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, listError := ListObjects(bucketName, prefix, "true")
|
||||
fmt.Println(listError)
|
||||
listResponse, _ := ListObjects(bucketName, prefix, "true")
|
||||
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err = json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1480,13 +1487,14 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestPutObjectsRetentionStatus")
|
||||
}
|
||||
|
||||
func TestShareObjectOnURL(t *testing.T) {
|
||||
/*
|
||||
Test to share an object via URL
|
||||
*/
|
||||
|
||||
printStartFunc("TestShareObjectOnURL")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
bucketName := "testshareobjectonurl"
|
||||
@@ -1566,13 +1574,14 @@ func TestShareObjectOnURL(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
printEndFunc("TestShareObjectOnURL")
|
||||
}
|
||||
|
||||
func TestListObjects(t *testing.T) {
|
||||
/*
|
||||
To test list objects end point.
|
||||
*/
|
||||
|
||||
printStartFunc("TestListObjects")
|
||||
// Test's variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testlistobjecttobucket1"
|
||||
@@ -1618,13 +1627,14 @@ func TestListObjects(t *testing.T) {
|
||||
assert.True(
|
||||
strings.Contains(finalResponse, "testlistobjecttobucket1"),
|
||||
finalResponse)
|
||||
printEndFunc("TestListObjects")
|
||||
}
|
||||
|
||||
func TestDeleteObject(t *testing.T) {
|
||||
/*
|
||||
Test to delete an object from a given bucket.
|
||||
*/
|
||||
|
||||
printStartFunc("TestDeleteObject")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdeleteobjectbucket1"
|
||||
@@ -1693,13 +1703,14 @@ func TestDeleteObject(t *testing.T) {
|
||||
strings.Contains(
|
||||
finalResponse,
|
||||
"testdeleteobjectfile1.txt"), finalResponse) // Gone
|
||||
printEndFunc("TestDeleteObject")
|
||||
}
|
||||
|
||||
func TestUploadObjectToBucket(t *testing.T) {
|
||||
/*
|
||||
Function to test the upload of an object to a bucket.
|
||||
*/
|
||||
|
||||
printStartFunc("TestUploadObjectToBucket")
|
||||
// Test's variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testuploadobjecttobucket1"
|
||||
@@ -1729,13 +1740,14 @@ func TestUploadObjectToBucket(t *testing.T) {
|
||||
if uploadResponse != nil {
|
||||
assert.Equal(200, uploadResponse.StatusCode, finalResponse)
|
||||
}
|
||||
printEndFunc("TestUploadObjectToBucket")
|
||||
}
|
||||
|
||||
func TestDownloadObject(t *testing.T) {
|
||||
/*
|
||||
Test to download an object from a given bucket.
|
||||
*/
|
||||
|
||||
printStartFunc("TestDownloadObject")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdownloadobjbucketone"
|
||||
@@ -1802,13 +1814,14 @@ func TestDownloadObject(t *testing.T) {
|
||||
// path/to/whatever does not exist
|
||||
assert.Fail("File wasn't downloaded")
|
||||
}
|
||||
printEndFunc("TestDownloadObject")
|
||||
}
|
||||
|
||||
func TestDeleteMultipleObjects(t *testing.T) {
|
||||
/*
|
||||
Function to test the deletion of multiple objects from a given bucket.
|
||||
*/
|
||||
|
||||
printStartFunc("TestDeleteMultipleObjects")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdeletemultipleobjsbucket1"
|
||||
@@ -1873,13 +1886,14 @@ func TestDeleteMultipleObjects(t *testing.T) {
|
||||
// 5. Verify empty list is obtained as we deleted all the objects
|
||||
expected := "Http Response: {\"objects\":null}\n"
|
||||
assert.Equal(expected, finalResponse, finalResponse)
|
||||
printEndFunc("TestDeleteMultipleObjects")
|
||||
}
|
||||
|
||||
func TestPutObjectTag(t *testing.T) {
|
||||
/*
|
||||
Test to put a tag to an object
|
||||
*/
|
||||
|
||||
printStartFunc("TestPutObjectTag")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjecttagbucketone"
|
||||
@@ -1944,12 +1958,14 @@ func TestPutObjectTag(t *testing.T) {
|
||||
assert.True(
|
||||
strings.Contains(finalResponse, tags["tag"]),
|
||||
finalResponse)
|
||||
printEndFunc("TestPutObjectTag")
|
||||
}
|
||||
|
||||
func TestBucketRetention(t *testing.T) {
|
||||
/*
|
||||
To test bucket retention feature
|
||||
*/
|
||||
printStartFunc("TestBucketRetention")
|
||||
// 1. Create the bucket with 2 years validity retention
|
||||
assert := assert.New(t)
|
||||
/*
|
||||
@@ -2018,12 +2034,14 @@ func TestBucketRetention(t *testing.T) {
|
||||
}
|
||||
expected := "Http Response: {\"mode\":\"compliance\",\"unit\":\"years\",\"validity\":3}\n"
|
||||
assert.Equal(expected, finalResponse, finalResponse)
|
||||
printEndFunc("TestBucketRetention")
|
||||
}
|
||||
|
||||
func TestBucketInformationGenericErrorResponse(t *testing.T) {
|
||||
/*
|
||||
Test Bucket Info End Point with a Generic Error Response.
|
||||
*/
|
||||
printStartFunc("TestBucketInformationGenericErrorResponse")
|
||||
// 1. Create the bucket
|
||||
assert := assert.New(t)
|
||||
response, err := AddBucket("bucketinformation2", false, false, nil, nil)
|
||||
@@ -2069,13 +2087,14 @@ func TestBucketInformationGenericErrorResponse(t *testing.T) {
|
||||
// Since bucketinformation3 hasn't been created, then it is expected that
|
||||
// tag2 is not part of the response, this is why assert.False is used.
|
||||
assert.False(strings.Contains(finalResponse, "tag2"), finalResponse)
|
||||
printEndFunc("TestBucketInformationGenericErrorResponse")
|
||||
}
|
||||
|
||||
func TestBucketInformationSuccessfulResponse(t *testing.T) {
|
||||
/*
|
||||
Test Bucket Info End Point with a Successful Response.
|
||||
*/
|
||||
|
||||
printStartFunc("TestBucketInformationSuccessfulResponse")
|
||||
// 1. Create the bucket
|
||||
assert := assert.New(t)
|
||||
response, err := AddBucket("bucketinformation1", false, false, nil, nil)
|
||||
@@ -2125,12 +2144,14 @@ func TestBucketInformationSuccessfulResponse(t *testing.T) {
|
||||
assert.True(
|
||||
strings.Contains(debugResponse, "tag1"),
|
||||
inspectHTTPResponse(bucketInfoResponse))
|
||||
printEndFunc("TestBucketInformationSuccessfulResponse")
|
||||
}
|
||||
|
||||
func TestDeleteBucket(t *testing.T) {
|
||||
/*
|
||||
Test to delete a bucket
|
||||
*/
|
||||
printStartFunc("TestDeleteBucket")
|
||||
// 1. Create the bucket
|
||||
assert := assert.New(t)
|
||||
response, err := AddBucket("testdeletebucket1", false, false, nil, nil)
|
||||
@@ -2173,12 +2194,14 @@ func TestDeleteBucket(t *testing.T) {
|
||||
}
|
||||
assert.True(
|
||||
strings.Contains(finalResponse, "The specified bucket does not exist"))
|
||||
printEndFunc("TestDeleteBucket")
|
||||
}
|
||||
|
||||
func TestListBuckets(t *testing.T) {
|
||||
/*
|
||||
Test the list of buckets without query parameters.
|
||||
*/
|
||||
printStartFunc("TestListBuckets")
|
||||
assert := assert.New(t)
|
||||
|
||||
// 1. Create buckets
|
||||
@@ -2225,9 +2248,11 @@ func TestListBuckets(t *testing.T) {
|
||||
assert.True(strings.Contains(string(b),
|
||||
"testlistbuckets"+strconv.Itoa(i)))
|
||||
}
|
||||
printEndFunc("TestListBuckets")
|
||||
}
|
||||
|
||||
func TestBucketsGet(t *testing.T) {
|
||||
printStartFunc("TestListBuckets")
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &http.Client{
|
||||
@@ -2265,9 +2290,11 @@ func TestBucketsGet(t *testing.T) {
|
||||
assert.Greater(listBuckets.Total, int64(0), "Total buckets is 0")
|
||||
|
||||
}
|
||||
printEndFunc("TestListBuckets")
|
||||
}
|
||||
|
||||
func TestBucketVersioning(t *testing.T) {
|
||||
printStartFunc("TestBucketVersioning")
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &http.Client{
|
||||
@@ -2370,9 +2397,11 @@ func TestBucketVersioning(t *testing.T) {
|
||||
if response != nil {
|
||||
fmt.Println("DELETE StatusCode:", response.StatusCode)
|
||||
}
|
||||
printEndFunc("TestBucketVersioning")
|
||||
}
|
||||
|
||||
func TestSetBucketTags(t *testing.T) {
|
||||
printStartFunc("TestSetBucketTags")
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &http.Client{
|
||||
@@ -2441,9 +2470,11 @@ func TestSetBucketTags(t *testing.T) {
|
||||
}
|
||||
|
||||
assert.Equal("TAG", bucket.Details.Tags["test"], "Failed to add tag")
|
||||
printEndFunc("TestSetBucketTags")
|
||||
}
|
||||
|
||||
func TestGetBucket(t *testing.T) {
|
||||
printStartFunc("TestGetBucket")
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &http.Client{
|
||||
@@ -2477,6 +2508,7 @@ func TestGetBucket(t *testing.T) {
|
||||
if response != nil {
|
||||
assert.Equal(200, response.StatusCode, "Status Code is incorrect")
|
||||
}
|
||||
printEndFunc("TestGetBucket")
|
||||
}
|
||||
|
||||
func TestAddBucketLocking(t *testing.T) {
|
||||
@@ -2485,6 +2517,7 @@ func TestAddBucketLocking(t *testing.T) {
|
||||
is not enabled.
|
||||
Then, locking will be activated because versioning is activated as well.
|
||||
*/
|
||||
printStartFunc("TestAddBucketLocking")
|
||||
assert := assert.New(t)
|
||||
|
||||
/*
|
||||
@@ -2514,9 +2547,11 @@ func TestAddBucketLocking(t *testing.T) {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
printEndFunc("TestAddBucketLocking")
|
||||
}
|
||||
|
||||
func TestAddBucket(t *testing.T) {
|
||||
printStartFunc("TestAddBucket")
|
||||
assert := assert.New(t)
|
||||
type args struct {
|
||||
bucketName string
|
||||
@@ -2558,6 +2593,7 @@ func TestAddBucket(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
printEndFunc("TestAddBucket")
|
||||
}
|
||||
|
||||
func CreateBucketEvent(bucketName string, ignoreExisting bool, arn string, prefix string, suffix string, events []string) (*http.Response, error) {
|
||||
@@ -2639,7 +2675,7 @@ func DeleteBucketEvent(bucketName string, arn string, events []string, prefix st
|
||||
}
|
||||
|
||||
func TestDeleteBucketEvent(t *testing.T) {
|
||||
|
||||
printStartFunc("TestDeleteBucketEvent")
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -2719,6 +2755,7 @@ func TestDeleteBucketEvent(t *testing.T) {
|
||||
efinalResponseEvent,
|
||||
)
|
||||
}
|
||||
printEndFunc("TestDeleteBucketEvent")
|
||||
}
|
||||
|
||||
func SetMultiBucketReplication(accessKey string, secretKey string, targetURL string, region string, originBucket string, destinationBucket string, syncMode string, bandwidth int, healthCheckPeriod int, prefix string, tags string, replicateDeleteMarkers bool, replicateDeletes bool, priority int, storageClass string, replicateMetadata bool) (*http.Response, error) {
|
||||
@@ -2859,7 +2896,7 @@ func DeleteBucketReplicationRule(bucketName string, ruleID string) (*http.Respon
|
||||
}
|
||||
|
||||
func TestReplication(t *testing.T) {
|
||||
|
||||
printStartFunc("TestReplication")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
originBucket := "testputobjectslegalholdstatus"
|
||||
@@ -2954,7 +2991,7 @@ func TestReplication(t *testing.T) {
|
||||
if response != nil {
|
||||
assert.Equal(204, response.StatusCode, finalResponse)
|
||||
}
|
||||
|
||||
printEndFunc("TestReplication")
|
||||
}
|
||||
|
||||
func GetBucketVersioning(bucketName string) (*http.Response, error) {
|
||||
|
||||
@@ -40,7 +40,6 @@ func AddUser(accessKey string, secretKey string, groups []string, policies []str
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
|
||||
fmt.Println(".......................TestAddUser(): Create Data to add user")
|
||||
requestDataAdd := map[string]interface{}{
|
||||
"accessKey": accessKey,
|
||||
"secretKey": secretKey,
|
||||
@@ -48,7 +47,6 @@ func AddUser(accessKey string, secretKey string, groups []string, policies []str
|
||||
"policies": policies,
|
||||
}
|
||||
|
||||
fmt.Println("..............................TestAddUser(): Prepare the POST")
|
||||
requestDataJSON, _ := json.Marshal(requestDataAdd)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
@@ -59,7 +57,6 @@ func AddUser(accessKey string, secretKey string, groups []string, policies []str
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println(".................................TestAddUser(): Make the POST")
|
||||
response, err := client.Do(request)
|
||||
return response, err
|
||||
}
|
||||
@@ -72,7 +69,6 @@ func DeleteUser(userName string) (*http.Response, error) {
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
fmt.Println("...................................TestAddUser(): Remove user")
|
||||
request, err := http.NewRequest(
|
||||
"DELETE", "http://localhost:9090/api/v1/user?name="+userName, nil)
|
||||
if err != nil {
|
||||
@@ -80,8 +76,6 @@ func DeleteUser(userName string) (*http.Response, error) {
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println("...............................TestAddUser(): Make the DELETE")
|
||||
response, err := client.Do(request)
|
||||
return response, err
|
||||
}
|
||||
@@ -94,7 +88,6 @@ func ListUsers(offset string, limit string) (*http.Response, error) {
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
fmt.Println("...................................TestAddUser(): Remove user")
|
||||
request, err := http.NewRequest(
|
||||
"GET",
|
||||
"http://localhost:9090/api/v1/users?offset="+offset+"&limit="+limit,
|
||||
@@ -104,8 +97,6 @@ func ListUsers(offset string, limit string) (*http.Response, error) {
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Println("...............................TestAddUser(): Make the DELETE")
|
||||
response, err := client.Do(request)
|
||||
return response, err
|
||||
}
|
||||
@@ -368,24 +359,17 @@ func TestAddUser(t *testing.T) {
|
||||
tests like users.ts can run over clean data and we don't collide against
|
||||
it.
|
||||
*/
|
||||
|
||||
printStartFunc("TestAddUser")
|
||||
assert := assert.New(t)
|
||||
|
||||
// With no groups & no policies
|
||||
var groups = []string{}
|
||||
var policies = []string{}
|
||||
|
||||
fmt.Println(".................................TestAddUser(): Make the POST")
|
||||
response, err := AddUser("accessKey", "secretKey", groups, policies)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestAddUser(): Verification")
|
||||
fmt.Println(".................................TestAddUser(): POST response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("....................................TestAddUser(): POST error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("POST StatusCode:", response.StatusCode)
|
||||
assert.Equal(201, response.StatusCode, "Status Code is incorrect")
|
||||
@@ -396,16 +380,11 @@ func TestAddUser(t *testing.T) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("..................................TestAddUser(): Verification")
|
||||
fmt.Println("...............................TestAddUser(): DELETE response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("..................................TestAddUser(): DELETE error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("DELETE StatusCode:", response.StatusCode)
|
||||
assert.Equal(204, response.StatusCode, "has to be 204 when delete user")
|
||||
}
|
||||
|
||||
printEndFunc("TestAddUser")
|
||||
}
|
||||
|
||||
func TestListUsers(t *testing.T) {
|
||||
@@ -415,7 +394,7 @@ func TestListUsers(t *testing.T) {
|
||||
2. Then, it lists the users <------ 200 is expected when listing them.
|
||||
3. Finally, it deletes the users
|
||||
*/
|
||||
|
||||
printStartFunc("TestListUsers")
|
||||
assert := assert.New(t)
|
||||
|
||||
// With no groups & no policies
|
||||
@@ -425,8 +404,6 @@ func TestListUsers(t *testing.T) {
|
||||
// 1. Create the users
|
||||
numberOfUsers := 5
|
||||
for i := 1; i < numberOfUsers; i++ {
|
||||
fmt.Println("............................TestListUsers(): Adding users")
|
||||
fmt.Println(strconv.Itoa(i) + "accessKey" + strconv.Itoa(i))
|
||||
response, err := AddUser(
|
||||
strconv.Itoa(i)+"accessKey"+strconv.Itoa(i),
|
||||
"secretKey"+strconv.Itoa(i), groups, policies)
|
||||
@@ -434,11 +411,6 @@ func TestListUsers(t *testing.T) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("............................TestListUsers(): Verification")
|
||||
fmt.Println("...........................TestListUsers(): POST response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("..............................TestListUsers(): POST error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("POST StatusCode:", response.StatusCode)
|
||||
assert.Equal(201, response.StatusCode,
|
||||
@@ -476,24 +448,20 @@ func TestListUsers(t *testing.T) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("............................TestListUsers(): Verification")
|
||||
fmt.Println(".........................TestListUsers(): DELETE response")
|
||||
fmt.Println(response)
|
||||
fmt.Println("............................TestListUsers(): DELETE error")
|
||||
fmt.Println(err)
|
||||
if response != nil {
|
||||
fmt.Println("DELETE StatusCode:", response.StatusCode)
|
||||
assert.Equal(204,
|
||||
response.StatusCode, "has to be 204 when delete user")
|
||||
}
|
||||
}
|
||||
printEndFunc("TestListUsers")
|
||||
}
|
||||
|
||||
func TestGetUserInfo(t *testing.T) {
|
||||
/*
|
||||
Test to get the user information via API.
|
||||
*/
|
||||
|
||||
printStartFunc("TestGetUserInfo")
|
||||
// 1. Create the user
|
||||
fmt.Println("TestGetUserInfo(): 1. Create the user")
|
||||
assert := assert.New(t)
|
||||
@@ -532,13 +500,14 @@ func TestGetUserInfo(t *testing.T) {
|
||||
expected := "{\"accessKey\":\"accessKey\",\"memberOf\":null,\"policy\":[],\"status\":\"enabled\"}\n"
|
||||
obtained := string(b)
|
||||
assert.Equal(expected, obtained, "User Information is wrong")
|
||||
printEndFunc("TestGetUserInfo")
|
||||
}
|
||||
|
||||
func TestUpdateUserInfoSuccessfulResponse(t *testing.T) {
|
||||
/*
|
||||
Update User Information Test with Successful Response
|
||||
*/
|
||||
|
||||
printStartFunc("TestGetUserInfo")
|
||||
assert := assert.New(t)
|
||||
|
||||
// 1. Create an active user
|
||||
@@ -576,14 +545,14 @@ func TestUpdateUserInfoSuccessfulResponse(t *testing.T) {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
assert.True(strings.Contains(string(b), "disabled"))
|
||||
|
||||
printEndFunc("TestGetUserInfo")
|
||||
}
|
||||
|
||||
func TestUpdateUserInfoGenericErrorResponse(t *testing.T) {
|
||||
/*
|
||||
Update User Information Test with Generic Error Response
|
||||
*/
|
||||
|
||||
printStartFunc("TestUpdateUserInfoGenericErrorResponse")
|
||||
assert := assert.New(t)
|
||||
|
||||
// 1. Create an active user
|
||||
@@ -621,13 +590,14 @@ func TestUpdateUserInfoGenericErrorResponse(t *testing.T) {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
assert.True(strings.Contains(string(b), "status not valid"))
|
||||
|
||||
printEndFunc("TestUpdateUserInfoGenericErrorResponse")
|
||||
}
|
||||
|
||||
func TestRemoveUserSuccessfulResponse(t *testing.T) {
|
||||
/*
|
||||
To test removing a user from API
|
||||
*/
|
||||
printStartFunc("TestRemoveUserSuccessfulResponse")
|
||||
assert := assert.New(t)
|
||||
|
||||
// 1. Create an active user
|
||||
@@ -674,13 +644,14 @@ func TestRemoveUserSuccessfulResponse(t *testing.T) {
|
||||
printMessage(finalResponse)
|
||||
assert.True(strings.Contains(
|
||||
finalResponse, "The specified user does not exist"), finalResponse)
|
||||
|
||||
printEndFunc("TestRemoveUserSuccessfulResponse")
|
||||
}
|
||||
|
||||
func TestUpdateGroupsForAUser(t *testing.T) {
|
||||
/*
|
||||
To test Update Groups For a User End Point.
|
||||
*/
|
||||
printStartFunc("TestUpdateGroupsForAUser")
|
||||
// 1. Create the user
|
||||
numberOfGroups := 3
|
||||
groupName := "updategroupforausergroup"
|
||||
@@ -730,13 +701,14 @@ func TestUpdateGroupsForAUser(t *testing.T) {
|
||||
assert.True(strings.Contains(
|
||||
finalResponse, groupName+strconv.Itoa(i)), finalResponse)
|
||||
}
|
||||
printEndFunc("TestUpdateGroupsForAUser")
|
||||
}
|
||||
|
||||
func TestCreateServiceAccountForUser(t *testing.T) {
|
||||
/*
|
||||
To test creation of service account for a user.
|
||||
*/
|
||||
|
||||
printStartFunc("TestCreateServiceAccountForUser")
|
||||
// Test's variables
|
||||
userName := "testcreateserviceaccountforuser1"
|
||||
assert := assert.New(t)
|
||||
@@ -790,13 +762,14 @@ func TestCreateServiceAccountForUser(t *testing.T) {
|
||||
)
|
||||
}
|
||||
assert.Equal(len(finalResponse), serviceAccountLengthInBytes, finalResponse)
|
||||
printEndFunc("TestCreateServiceAccountForUser")
|
||||
}
|
||||
|
||||
func TestCreateServiceAccountForUserWithCredentials(t *testing.T) {
|
||||
/*
|
||||
To test creation of service account for a user.
|
||||
*/
|
||||
|
||||
printStartFunc("TestCreateServiceAccountForUserWithCredentials")
|
||||
// Test's variables
|
||||
userName := "testcreateserviceaccountforuserwithcredentials1"
|
||||
assert := assert.New(t)
|
||||
@@ -882,13 +855,14 @@ func TestCreateServiceAccountForUserWithCredentials(t *testing.T) {
|
||||
assert.Equal(len(finalResponse), serviceAccountLengthInBytes, finalResponse)
|
||||
})
|
||||
}
|
||||
printEndFunc("TestCreateServiceAccountForUserWithCredentials")
|
||||
}
|
||||
|
||||
func TestUsersGroupsBulk(t *testing.T) {
|
||||
/*
|
||||
To test UsersGroupsBulk End Point
|
||||
*/
|
||||
|
||||
printStartFunc("TestUsersGroupsBulk")
|
||||
// Vars
|
||||
assert := assert.New(t)
|
||||
numberOfUsers := 5
|
||||
@@ -971,4 +945,5 @@ func TestUsersGroupsBulk(t *testing.T) {
|
||||
// Make sure the user belongs to the created group
|
||||
assert.True(strings.Contains(string(finalResponse), groupName))
|
||||
}
|
||||
printEndFunc("TestUsersGroupsBulk")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user