Allow go benchmarks to use api helpers functions (#19179)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0b1e9445c8
Коммит
b02e9ba5b0
@@ -903,106 +903,106 @@ func GenerateTestId() string {
|
|||||||
return model.NewId()
|
return model.NewId()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserSanitization(t *testing.T, user *model.User) {
|
func CheckUserSanitization(tb testing.TB, user *model.User) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.Equal(t, "", user.Password, "password wasn't blank")
|
require.Equal(tb, "", user.Password, "password wasn't blank")
|
||||||
require.Empty(t, user.AuthData, "auth data wasn't blank")
|
require.Empty(tb, user.AuthData, "auth data wasn't blank")
|
||||||
require.Equal(t, "", user.MfaSecret, "mfa secret wasn't blank")
|
require.Equal(tb, "", user.MfaSecret, "mfa secret wasn't blank")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckEtag(t *testing.T, data interface{}, resp *model.Response) {
|
func CheckEtag(tb testing.TB, data interface{}, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.Empty(t, data)
|
require.Empty(tb, data)
|
||||||
require.Equal(t, http.StatusNotModified, resp.StatusCode, "wrong status code for etag")
|
require.Equal(tb, http.StatusNotModified, resp.StatusCode, "wrong status code for etag")
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkHTTPStatus(t *testing.T, resp *model.Response, expectedStatus int) {
|
func checkHTTPStatus(tb testing.TB, resp *model.Response, expectedStatus int) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.NotNilf(t, resp, "Unexpected nil response, expected http status:%v", expectedStatus)
|
require.NotNilf(tb, resp, "Unexpected nil response, expected http status:%v", expectedStatus)
|
||||||
require.Equalf(t, expectedStatus, resp.StatusCode, "Expected http status:%v, got %v", expectedStatus, resp.StatusCode)
|
require.Equalf(tb, expectedStatus, resp.StatusCode, "Expected http status:%v, got %v", expectedStatus, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckOKStatus(t *testing.T, resp *model.Response) {
|
func CheckOKStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusOK)
|
checkHTTPStatus(tb, resp, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckCreatedStatus(t *testing.T, resp *model.Response) {
|
func CheckCreatedStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusCreated)
|
checkHTTPStatus(tb, resp, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckForbiddenStatus(t *testing.T, resp *model.Response) {
|
func CheckForbiddenStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusForbidden)
|
checkHTTPStatus(tb, resp, http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUnauthorizedStatus(t *testing.T, resp *model.Response) {
|
func CheckUnauthorizedStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusUnauthorized)
|
checkHTTPStatus(tb, resp, http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckNotFoundStatus(t *testing.T, resp *model.Response) {
|
func CheckNotFoundStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusNotFound)
|
checkHTTPStatus(tb, resp, http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckBadRequestStatus(t *testing.T, resp *model.Response) {
|
func CheckBadRequestStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusBadRequest)
|
checkHTTPStatus(tb, resp, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckNotImplementedStatus(t *testing.T, resp *model.Response) {
|
func CheckNotImplementedStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusNotImplemented)
|
checkHTTPStatus(tb, resp, http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckRequestEntityTooLargeStatus(t *testing.T, resp *model.Response) {
|
func CheckRequestEntityTooLargeStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusRequestEntityTooLarge)
|
checkHTTPStatus(tb, resp, http.StatusRequestEntityTooLarge)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
|
func CheckInternalErrorStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusInternalServerError)
|
checkHTTPStatus(tb, resp, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckServiceUnavailableStatus(t *testing.T, resp *model.Response) {
|
func CheckServiceUnavailableStatus(tb testing.TB, resp *model.Response) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
checkHTTPStatus(t, resp, http.StatusServiceUnavailable)
|
checkHTTPStatus(tb, resp, http.StatusServiceUnavailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckErrorID(t *testing.T, err error, errorId string) {
|
func CheckErrorID(tb testing.TB, err error, errorId string) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.Error(t, err, "should have errored with id: %s", errorId)
|
require.Error(tb, err, "should have errored with id: %s", errorId)
|
||||||
|
|
||||||
var appError *model.AppError
|
var appError *model.AppError
|
||||||
ok := errors.As(err, &appError)
|
ok := errors.As(err, &appError)
|
||||||
require.True(t, ok, "should have been a model.AppError")
|
require.True(tb, ok, "should have been a model.AppError")
|
||||||
|
|
||||||
require.Equalf(t, errorId, appError.Id, "incorrect error id, actual: %s, expected: %s", appError.Id, errorId)
|
require.Equalf(tb, errorId, appError.Id, "incorrect error id, actual: %s, expected: %s", appError.Id, errorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckErrorMessage(t *testing.T, err error, message string) {
|
func CheckErrorMessage(tb testing.TB, err error, message string) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.Error(t, err, "should have errored with message: %s", message)
|
require.Error(tb, err, "should have errored with message: %s", message)
|
||||||
|
|
||||||
var appError *model.AppError
|
var appError *model.AppError
|
||||||
ok := errors.As(err, &appError)
|
ok := errors.As(err, &appError)
|
||||||
require.True(t, ok, "should have been a model.AppError")
|
require.True(tb, ok, "should have been a model.AppError")
|
||||||
|
|
||||||
require.Equalf(t, message, appError.Message, "incorrect error message, actual: %s, expected: %s", appError.Id, message)
|
require.Equalf(tb, message, appError.Message, "incorrect error message, actual: %s, expected: %s", appError.Id, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckStartsWith(t *testing.T, value, prefix, message string) {
|
func CheckStartsWith(tb testing.TB, value, prefix, message string) {
|
||||||
t.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
require.True(t, strings.HasPrefix(value, prefix), message, value)
|
require.True(tb, strings.HasPrefix(value, prefix), message, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar to s3.New() but allows initialization of signature v2 or signature v4 client.
|
// Similar to s3.New() but allows initialization of signature v2 or signature v4 client.
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
expectedImageHasPreview []bool
|
expectedImageHasPreview []bool
|
||||||
expectedImageMiniPreview []bool
|
expectedImageMiniPreview []bool
|
||||||
setupConfig func(a *app.App) func(a *app.App)
|
setupConfig func(a *app.App) func(a *app.App)
|
||||||
checkResponse func(t *testing.T, resp *model.Response)
|
checkResponse func(t testing.TB, resp *model.Response)
|
||||||
}{
|
}{
|
||||||
// Upload a bunch of files, mixed images and non-images
|
// Upload a bunch of files, mixed images and non-images
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -642,7 +642,7 @@ func TestUpdateTeamPrivacy(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
team *model.Team
|
team *model.Team
|
||||||
privacy string
|
privacy string
|
||||||
errChecker func(t *testing.T, resp *model.Response)
|
errChecker func(t testing.TB, resp *model.Response)
|
||||||
wantType string
|
wantType string
|
||||||
wantOpenInvite bool
|
wantOpenInvite bool
|
||||||
wantInviteIdChanged bool
|
wantInviteIdChanged bool
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user