Skip to content

Commit

Permalink
Delete Bucket Event Test (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
cniackz committed Feb 28, 2022
1 parent 3395d1c commit 96d59fb
Showing 1 changed file with 161 additions and 0 deletions.
161 changes: 161 additions & 0 deletions integration/user_api_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2535,3 +2535,164 @@ func TestAddBucket(t *testing.T) {
})
}
}

func CreateBucketEvent(bucketName string, ignoreExisting bool, arn string, prefix string, suffix string, events []string) (*http.Response, error) {
/*
Helper function to create bucket event
POST: /buckets/{bucket_name}/events
{
"configuration":
{
"arn":"arn:minio:sqs::_:postgresql",
"events":["put"],
"prefix":"",
"suffix":""
},
"ignoreExisting":true
}
*/
configuration := map[string]interface{}{
"arn": arn,
"events": events,
"prefix": prefix,
"suffix": suffix,
}
requestDataAdd := map[string]interface{}{
"configuration": configuration,
"ignoreExisting": ignoreExisting,
}
requestDataJSON, _ := json.Marshal(requestDataAdd)
requestDataBody := bytes.NewReader(requestDataJSON)
request, err := http.NewRequest(
"POST",
"http://localhost:9090/api/v1/buckets/"+bucketName+"/events",
requestDataBody,
)
if err != nil {
log.Println(err)
}
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
request.Header.Add("Content-Type", "application/json")
client := &http.Client{
Timeout: 2 * time.Second,
}
response, err := client.Do(request)
return response, err
}

func DeleteBucketEvent(bucketName string, arn string, events []string, prefix string, suffix string) (*http.Response, error) {
/*
Helper function to test Delete Bucket Event
DELETE: /buckets/{bucket_name}/events/{arn}
{
"events":["put"],
"prefix":"",
"suffix":""
}
*/
requestDataAdd := map[string]interface{}{
"events": events,
"prefix": prefix,
"suffix": suffix,
}
requestDataJSON, _ := json.Marshal(requestDataAdd)
requestDataBody := bytes.NewReader(requestDataJSON)
request, err := http.NewRequest(
"DELETE",
"http://localhost:9090/api/v1/buckets/"+bucketName+"/events/"+arn,
requestDataBody,
)
if err != nil {
log.Println(err)
}
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
request.Header.Add("Content-Type", "application/json")
client := &http.Client{
Timeout: 2 * time.Second,
}
response, err := client.Do(request)
return response, err
}

func TestDeleteBucketEvent(t *testing.T) {

// Variables
assert := assert.New(t)

// 1. Add postgres notification
response, err := NotifyPostgres()
finalResponse := inspectHTTPResponse(response)
assert.Nil(err)
if err != nil {
log.Println(err)
assert.Fail(finalResponse)
return
}
if response != nil {
assert.Equal(200, response.StatusCode, finalResponse)
}

// 2. Restart the system
restartResponse, restartError := RestartService()
assert.Nil(restartError)
if restartError != nil {
log.Println(restartError)
return
}
addObjRsp := inspectHTTPResponse(restartResponse)
if restartResponse != nil {
assert.Equal(
204,
restartResponse.StatusCode,
addObjRsp,
)
}

// 3. Subscribe bucket to event
events := make([]string, 1)
events[0] = "put"
eventResponse, eventError := CreateBucketEvent(
"testputobjectslegalholdstatus", // bucket name
true, // ignore existing param
"arn:minio:sqs::_:postgresql", // arn
"", // prefix
"", // suffix
events, // events
)
assert.Nil(eventError)
if eventError != nil {
log.Println(eventError)
return
}
finalResponseEvent := inspectHTTPResponse(eventResponse)
if eventResponse != nil {
assert.Equal(
201,
eventResponse.StatusCode,
finalResponseEvent,
)
}

// 4. Delete Bucket Event
events[0] = "put"
deletEventResponse, deventError := DeleteBucketEvent(
"testputobjectslegalholdstatus", // bucket name
"arn:minio:sqs::_:postgresql", // arn
events, // events
"", // prefix
"", // suffix
)
assert.Nil(deventError)
if deventError != nil {
log.Println(deventError)
return
}
efinalResponseEvent := inspectHTTPResponse(deletEventResponse)
if deletEventResponse != nil {
assert.Equal(
204,
deletEventResponse.StatusCode,
efinalResponseEvent,
)
}
}

0 comments on commit 96d59fb

Please sign in to comment.