s3manager-web/delete_object_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2017-05-08 23:07:07 +02:00
package s3manager_test
import (
"errors"
"net/http"
"net/http/httptest"
"testing"
2017-05-25 18:33:44 +02:00
. "github.com/mastertinner/s3manager"
"github.com/stretchr/testify/assert"
)
2017-04-03 14:08:01 +02:00
func TestDeleteObjectHandler(t *testing.T) {
assert := assert.New(t)
2017-05-08 23:07:07 +02:00
cases := map[string]struct {
2017-05-25 18:33:44 +02:00
s3 S3
2017-04-09 16:28:57 +02:00
expectedStatusCode int
expectedBodyContains string
}{
2017-04-03 14:08:01 +02:00
"success": {
2017-05-08 23:07:07 +02:00
s3: &s3Mock{},
2017-04-09 16:28:57 +02:00
expectedStatusCode: http.StatusNoContent,
2017-04-10 14:19:27 +02:00
expectedBodyContains: "",
},
2017-04-03 14:08:01 +02:00
"s3 error": {
2017-05-08 23:07:07 +02:00
s3: &s3Mock{
2017-04-03 23:52:41 +02:00
Err: errors.New("mocked S3 error"),
},
2017-04-09 16:28:57 +02:00
expectedStatusCode: http.StatusInternalServerError,
expectedBodyContains: http.StatusText(http.StatusInternalServerError),
},
}
2017-05-08 23:07:07 +02:00
for tcID, tc := range cases {
2017-04-07 08:59:24 +02:00
req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil)
2017-04-07 12:51:23 +02:00
assert.NoError(err, tcID)
rr := httptest.NewRecorder()
2017-05-25 18:33:44 +02:00
handler := DeleteObjectHandler(tc.s3)
handler.ServeHTTP(rr, req)
2017-04-07 12:51:23 +02:00
assert.Equal(tc.expectedStatusCode, rr.Code, tcID)
2017-04-09 16:28:57 +02:00
assert.Contains(rr.Body.String(), tc.expectedBodyContains, tcID)
}
}