Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-7633: Optimize memory utilization during file uploads #9835

Merged
merged 14 commits into from Dec 13, 2018
115 changes: 34 additions & 81 deletions api4/apitestlib.go
Expand Up @@ -573,103 +573,71 @@ func CheckNoError(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error != nil {
t.Fatal("Expected no error, got " + resp.Error.Error())
t.Fatalf("Expected no error, got %q", resp.Error.Error())
}
}

func CheckCreatedStatus(t *testing.T, resp *model.Response) {
func checkHTTPStatus(t *testing.T, resp *model.Response, expectedStatus int, expectError bool) {
t.Helper()

if resp.StatusCode != http.StatusCreated {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusCreated))
t.Fatal("wrong status code")
switch {
case resp == nil:
t.Fatalf("Unexpected nil response, expected http:%v, expectError:%v)", expectedStatus, expectError)

case expectError && resp.Error == nil:
t.Fatalf("Expected a non-nil error and http status:%v, got nil, %v", expectedStatus, resp.StatusCode)

case !expectError && resp.Error != nil:
t.Fatalf("Expected no error and http status:%v, got %q, http:%v", expectedStatus, resp.Error, resp.StatusCode)

case resp.StatusCode != expectedStatus:
t.Fatalf("Expected http status:%v, got %v (err: %q)", expectedStatus, resp.StatusCode, resp.Error)
}
}

func CheckForbiddenStatus(t *testing.T, resp *model.Response) {
func CheckOKStatus(t *testing.T, resp *model.Response) {
t.Helper()
checkHTTPStatus(t, resp, http.StatusOK, false)
}

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusForbidden))
return
}
func CheckCreatedStatus(t *testing.T, resp *model.Response) {
t.Helper()
checkHTTPStatus(t, resp, http.StatusCreated, false)
}

if resp.StatusCode != http.StatusForbidden {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusForbidden))
t.Fatal("wrong status code")
}
func CheckForbiddenStatus(t *testing.T, resp *model.Response) {
t.Helper()
checkHTTPStatus(t, resp, http.StatusForbidden, true)
}

func CheckUnauthorizedStatus(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusUnauthorized))
return
}

if resp.StatusCode != http.StatusUnauthorized {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusUnauthorized))
t.Fatal("wrong status code")
}
checkHTTPStatus(t, resp, http.StatusUnauthorized, true)
}

func CheckNotFoundStatus(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusNotFound))
return
}

if resp.StatusCode != http.StatusNotFound {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusNotFound))
t.Fatal("wrong status code")
}
checkHTTPStatus(t, resp, http.StatusNotFound, true)
}

func CheckBadRequestStatus(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusBadRequest))
return
}

if resp.StatusCode != http.StatusBadRequest {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusBadRequest))
t.Fatal("wrong status code")
}
checkHTTPStatus(t, resp, http.StatusBadRequest, true)
}

func CheckNotImplementedStatus(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusNotImplemented))
return
}

if resp.StatusCode != http.StatusNotImplemented {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusNotImplemented))
t.Fatal("wrong status code")
}
checkHTTPStatus(t, resp, http.StatusNotImplemented, true)
}

func CheckOKStatus(t *testing.T, resp *model.Response) {
func CheckRequestEntityTooLargeStatus(t *testing.T, resp *model.Response) {
t.Helper()
checkHTTPStatus(t, resp, http.StatusRequestEntityTooLarge, true)
}

CheckNoError(t, resp)

if resp.StatusCode != http.StatusOK {
t.Fatalf("wrong status code. expected %d got %d", http.StatusOK, resp.StatusCode)
}
func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
levb marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()
checkHTTPStatus(t, resp, http.StatusInternalServerError, true)
}

func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
Expand All @@ -687,21 +655,6 @@ func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
}
}

func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
t.Helper()

if resp.Error == nil {
t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusInternalServerError))
return
}

if resp.StatusCode != http.StatusInternalServerError {
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
t.Log("expected: " + strconv.Itoa(http.StatusInternalServerError))
t.Fatal("wrong status code")
}
}

// Similar to s3.New() but allows initialization of signature v2 or signature v4 client.
// If signV2 input is false, function always returns signature v4.
//
Expand Down