tests: anonymous/unsigned tests for object handler API's . (#2881)

This commit is contained in:
Karthic Rao
2016-10-08 11:58:50 +05:30
committed by Harshavardhana
parent 30183c4a9a
commit 8f4cf2a7d0
2 changed files with 173 additions and 22 deletions

View File

@@ -1431,7 +1431,7 @@ func ExecObjectLayerAPIAnonTest(t *testing.T, testName, bucketName, objectName,
// read the response body.
actualContent, err := ioutil.ReadAll(rec.Body)
if err != nil {
failTest(fmt.Sprintf("Failed parsing response body: <ERROR> %v.", err))
failTest(fmt.Sprintf("Failed parsing response body: <ERROR> %v", err))
}
// verify whether actual error response (from the response body), matches the expected error response.
if !bytes.Equal(expectedErrResponse, actualContent) {
@@ -1451,9 +1451,19 @@ func ExecObjectLayerAPIAnonTest(t *testing.T, testName, bucketName, objectName,
anonReq.Body = readerTwo
apiRouter.ServeHTTP(rec, anonReq)
if rec.Code != http.StatusOK {
var expectedHTTPStatus int
// expectedHTTPStatus returns 204 (http.StatusNoContent) on success.
if testName == "TestAPIDeleteObjectHandler" {
expectedHTTPStatus = http.StatusNoContent
} else {
// other API handlers return 200OK on success.
expectedHTTPStatus = http.StatusOK
}
// compare the HTTP response status code with the expected one.
if rec.Code != expectedHTTPStatus {
failTest(fmt.Sprintf("Expected the anonymous HTTP request to be served after the policy changes\n,Expected response HTTP status code to be %d, got %d.",
http.StatusOK, rec.Code))
expectedHTTPStatus, rec.Code))
}
}