Commit 3701cc77 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Remove last cases of testify/assert

parent 7d8c1f55
......@@ -16,7 +16,6 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
......@@ -178,10 +177,10 @@ func TestAllowedGetGitBlob(t *testing.T) {
require.NoError(t, err)
shortBody := string(body[:len(expectedBody)])
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
testhelper.RequireResponseHeader(t, resp, "Content-Length", strconv.Itoa(bodyLen))
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
}
func TestAllowedGetGitArchive(t *testing.T) {
......@@ -205,8 +204,8 @@ func TestAllowedGetGitArchive(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
// Ensure the tar file is readable
foundEntry := false
......@@ -223,7 +222,7 @@ func TestAllowedGetGitArchive(t *testing.T) {
}
}
assert.True(t, foundEntry, "Couldn't find %v directory entry", archivePrefix)
require.True(t, foundEntry, "Couldn't find %v directory entry", archivePrefix)
}
func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
......@@ -250,8 +249,8 @@ func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
// Ensure the tar file is readable
foundEntry := false
......@@ -268,7 +267,7 @@ func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
}
}
assert.True(t, foundEntry, "Couldn't find %v directory entry", archivePrefix)
require.True(t, foundEntry, "Couldn't find %v directory entry", archivePrefix)
}
func TestAllowedGetGitDiff(t *testing.T) {
......@@ -293,9 +292,9 @@ func TestAllowedGetGitDiff(t *testing.T) {
require.NoError(t, err)
shortBody := string(body[:len(expectedBody)])
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
}
func TestAllowedGetGitFormatPatch(t *testing.T) {
......@@ -317,8 +316,8 @@ func TestAllowedGetGitFormatPatch(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
requirePatchSeries(
t,
......
......@@ -19,7 +19,6 @@ import (
"github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/274
"github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/274
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
......@@ -53,7 +52,7 @@ func TestFailedCloneNoGitaly(t *testing.T) {
cloneCmd := exec.Command("git", "clone", fmt.Sprintf("%s/%s", ws.URL, testRepo), checkoutDir)
out, err := cloneCmd.CombinedOutput()
t.Log(string(out))
assert.Error(t, err, "git clone should have failed")
require.Error(t, err, "git clone should have failed")
}
func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
......@@ -214,14 +213,14 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
gitalyRequest := &gitalypb.PostReceivePackRequest{}
require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest))
assert.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
assert.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath)
assert.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId)
assert.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername)
assert.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions)
assert.Equal(t, gitProtocol, gitalyRequest.GitProtocol)
require.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
require.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath)
require.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId)
require.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername)
require.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions)
require.Equal(t, gitProtocol, gitalyRequest.GitProtocol)
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
require.Equal(t, 200, resp.StatusCode, "POST %q", resource)
require.Equal(t, string(testhelper.GitalyReceivePackResponseMock), split[1])
testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result")
}
......@@ -246,7 +245,7 @@ func TestPostReceivePackProxiedToGitalyInterrupted(t *testing.T) {
bytes.NewReader(testhelper.GitalyReceivePackResponseMock),
)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
require.Equal(t, 200, resp.StatusCode, "POST %q", resource)
// This causes the server stream to be interrupted instead of consumed entirely.
resp.Body.Close()
......@@ -363,7 +362,7 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
bytes.NewReader(testhelper.GitalyUploadPackResponseMock),
)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
require.Equal(t, 200, resp.StatusCode, "POST %q", resource)
// This causes the server stream to be interrupted instead of consumed entirely.
resp.Body.Close()
......@@ -393,8 +392,8 @@ func TestGetDiffProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-diff", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
}
func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) {
......@@ -413,8 +412,8 @@ func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
}
func TestGetBlobProxiedToGitalyInterruptedStream(t *testing.T) {
......@@ -469,9 +468,9 @@ func TestGetArchiveProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar.gz", "git-archive", jsonParams)
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
assert.Equal(t, archiveLength, len(body), "GET %q: body size", resp.Request.URL)
require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
require.Equal(t, archiveLength, len(body), "GET %q: body size", resp.Request.URL)
if tc.cacheDisabled {
_, err := os.Stat(tc.archivePath)
......@@ -578,9 +577,9 @@ func TestGetSnapshotProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/api/v4/projects/:id/snapshot", "git-snapshot", params)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assert.Equal(t, expectedBody, string(body), "GET %q: body", resp.Request.URL)
assert.Equal(t, archiveLength, len(body), "GET %q: body size", resp.Request.URL)
require.Equal(t, http.StatusOK, resp.StatusCode, "GET %q: status code", resp.Request.URL)
require.Equal(t, expectedBody, string(body), "GET %q: body", resp.Request.URL)
require.Equal(t, archiveLength, len(body), "GET %q: body size", resp.Request.URL)
testhelper.RequireResponseHeader(t, resp, "Content-Disposition", `attachment; filename="snapshot.tar"`)
testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-tar")
......
......@@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func startWorkhorseServerWithLongPolling(authBackend string, pollingDuration time.Duration) *httptest.Server {
......@@ -33,7 +33,7 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob
defer ws.Close()
resp, err := requestJob(ws.URL, nil)
assert.NoError(t, err)
require.NoError(t, err)
defer resp.Body.Close()
return resp
......@@ -41,12 +41,12 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob
func testJobsLongPollingEndpointDisabled(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, 0, requestJob)
assert.NotEqual(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
require.NotEqual(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
}
func testJobsLongPollingEndpoint(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, time.Minute, requestJob)
assert.Equal(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
require.Equal(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
}
func TestJobsLongPollingEndpointDisabled(t *testing.T) {
......
This diff is collapsed.
......@@ -15,7 +15,6 @@ import (
"testing"
"github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
......@@ -49,10 +48,10 @@ func testArtifactsUpload(t *testing.T, uploadArtifacts uploadArtifactsFunction)
defer ws.Close()
resp, resource, err := uploadArtifacts(ws.URL, contentType, reqBody)
assert.NoError(t, err)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, 200, resp.StatusCode, "GET %q: expected 200, got %d", resource, resp.StatusCode)
require.Equal(t, 200, resp.StatusCode, "GET %q: expected 200, got %d", resource, resp.StatusCode)
}
func TestArtifactsUpload(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment