Delete Bucket Event Test (#1633)
This commit is contained in:
committed by
GitHub
parent
3395d1c853
commit
96d59fb7cc
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user