Commit c8575e0b authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-remove-assert-final' into 'master'

Remove last cases of testify/assert NO CHANGELOG

See merge request gitlab-org/gitlab-workhorse!604
parents fdf60f09 3701cc77
...@@ -112,7 +112,7 @@ testdata/scratch: ...@@ -112,7 +112,7 @@ testdata/scratch:
mkdir -p testdata/scratch mkdir -p testdata/scratch
.PHONY: verify .PHONY: verify
verify: lint vet detect-context check-formatting staticcheck verify: lint vet detect-context detect-assert check-formatting staticcheck
.PHONY: lint .PHONY: lint
lint: $(TARGET_SETUP) lint: $(TARGET_SETUP)
...@@ -130,6 +130,11 @@ detect-context: $(TARGET_SETUP) ...@@ -130,6 +130,11 @@ detect-context: $(TARGET_SETUP)
$(call message,Verify: $@) $(call message,Verify: $@)
_support/detect-context.sh _support/detect-context.sh
.PHONY: detect-assert
detect-assert:
$(call message,Verify: $@)
_support/detect-assert.sh
.PHONY: check-formatting .PHONY: check-formatting
check-formatting: $(TARGET_SETUP) install-goimports check-formatting: $(TARGET_SETUP) install-goimports
$(call message,Verify: $@) $(call message,Verify: $@)
......
#!/bin/sh
git grep 'testify/assert"' | \
grep -e '^[^:]*\.go' | \
awk '{
print "error: please use testify/require instead of testify/assert"
print
exit 1
}'
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
...@@ -178,10 +177,10 @@ func TestAllowedGetGitBlob(t *testing.T) { ...@@ -178,10 +177,10 @@ func TestAllowedGetGitBlob(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
shortBody := string(body[:len(expectedBody)]) shortBody := string(body[:len(expectedBody)])
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
testhelper.RequireResponseHeader(t, resp, "Content-Length", strconv.Itoa(bodyLen)) 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) { func TestAllowedGetGitArchive(t *testing.T) {
...@@ -205,8 +204,8 @@ func TestAllowedGetGitArchive(t *testing.T) { ...@@ -205,8 +204,8 @@ func TestAllowedGetGitArchive(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams) resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL) requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
// Ensure the tar file is readable // Ensure the tar file is readable
foundEntry := false foundEntry := false
...@@ -223,7 +222,7 @@ func TestAllowedGetGitArchive(t *testing.T) { ...@@ -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) { func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
...@@ -250,8 +249,8 @@ func TestAllowedGetGitArchiveOldPayload(t *testing.T) { ...@@ -250,8 +249,8 @@ func TestAllowedGetGitArchiveOldPayload(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams) resp, body, err := doSendDataRequest("/archive.tar", "git-archive", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL) requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
// Ensure the tar file is readable // Ensure the tar file is readable
foundEntry := false foundEntry := false
...@@ -268,7 +267,7 @@ func TestAllowedGetGitArchiveOldPayload(t *testing.T) { ...@@ -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) { func TestAllowedGetGitDiff(t *testing.T) {
...@@ -293,9 +292,9 @@ func TestAllowedGetGitDiff(t *testing.T) { ...@@ -293,9 +292,9 @@ func TestAllowedGetGitDiff(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
shortBody := string(body[:len(expectedBody)]) shortBody := string(body[:len(expectedBody)])
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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, expectedBody, shortBody, "GET %q: response body", resp.Request.URL)
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 TestAllowedGetGitFormatPatch(t *testing.T) { func TestAllowedGetGitFormatPatch(t *testing.T) {
...@@ -317,8 +316,8 @@ func TestAllowedGetGitFormatPatch(t *testing.T) { ...@@ -317,8 +316,8 @@ func TestAllowedGetGitFormatPatch(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams) resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL)
assertNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL) requireNginxResponseBuffering(t, "no", resp, "GET %q: nginx response buffering", resp.Request.URL)
requirePatchSeries( requirePatchSeries(
t, t,
......
...@@ -19,7 +19,6 @@ import ( ...@@ -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/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/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" "github.com/stretchr/testify/require"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
...@@ -53,7 +52,7 @@ func TestFailedCloneNoGitaly(t *testing.T) { ...@@ -53,7 +52,7 @@ func TestFailedCloneNoGitaly(t *testing.T) {
cloneCmd := exec.Command("git", "clone", fmt.Sprintf("%s/%s", ws.URL, testRepo), checkoutDir) cloneCmd := exec.Command("git", "clone", fmt.Sprintf("%s/%s", ws.URL, testRepo), checkoutDir)
out, err := cloneCmd.CombinedOutput() out, err := cloneCmd.CombinedOutput()
t.Log(string(out)) 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) { func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
...@@ -214,14 +213,14 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { ...@@ -214,14 +213,14 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
gitalyRequest := &gitalypb.PostReceivePackRequest{} gitalyRequest := &gitalypb.PostReceivePackRequest{}
require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest)) require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest))
assert.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName) require.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
assert.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath) require.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath)
assert.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId) require.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId)
assert.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername) require.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername)
assert.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions) require.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions)
assert.Equal(t, gitProtocol, gitalyRequest.GitProtocol) 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]) require.Equal(t, string(testhelper.GitalyReceivePackResponseMock), split[1])
testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result") testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result")
} }
...@@ -246,7 +245,7 @@ func TestPostReceivePackProxiedToGitalyInterrupted(t *testing.T) { ...@@ -246,7 +245,7 @@ func TestPostReceivePackProxiedToGitalyInterrupted(t *testing.T) {
bytes.NewReader(testhelper.GitalyReceivePackResponseMock), bytes.NewReader(testhelper.GitalyReceivePackResponseMock),
) )
require.NoError(t, err) 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. // This causes the server stream to be interrupted instead of consumed entirely.
resp.Body.Close() resp.Body.Close()
...@@ -363,7 +362,7 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) { ...@@ -363,7 +362,7 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
bytes.NewReader(testhelper.GitalyUploadPackResponseMock), bytes.NewReader(testhelper.GitalyUploadPackResponseMock),
) )
require.NoError(t, err) 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. // This causes the server stream to be interrupted instead of consumed entirely.
resp.Body.Close() resp.Body.Close()
...@@ -393,8 +392,8 @@ func TestGetDiffProxiedToGitalySuccessfully(t *testing.T) { ...@@ -393,8 +392,8 @@ func TestGetDiffProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-diff", jsonParams) resp, body, err := doSendDataRequest("/something", "git-diff", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
} }
func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) { func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) {
...@@ -413,8 +412,8 @@ func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) { ...@@ -413,8 +412,8 @@ func TestGetPatchProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams) resp, body, err := doSendDataRequest("/something", "git-format-patch", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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, expectedBody, string(body), "GET %q: response body", resp.Request.URL)
} }
func TestGetBlobProxiedToGitalyInterruptedStream(t *testing.T) { func TestGetBlobProxiedToGitalyInterruptedStream(t *testing.T) {
...@@ -469,9 +468,9 @@ func TestGetArchiveProxiedToGitalySuccessfully(t *testing.T) { ...@@ -469,9 +468,9 @@ func TestGetArchiveProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/archive.tar.gz", "git-archive", jsonParams) resp, body, err := doSendDataRequest("/archive.tar.gz", "git-archive", jsonParams)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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, 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, archiveLength, len(body), "GET %q: body size", resp.Request.URL)
if tc.cacheDisabled { if tc.cacheDisabled {
_, err := os.Stat(tc.archivePath) _, err := os.Stat(tc.archivePath)
...@@ -578,9 +577,9 @@ func TestGetSnapshotProxiedToGitalySuccessfully(t *testing.T) { ...@@ -578,9 +577,9 @@ func TestGetSnapshotProxiedToGitalySuccessfully(t *testing.T) {
resp, body, err := doSendDataRequest("/api/v4/projects/:id/snapshot", "git-snapshot", params) resp, body, err := doSendDataRequest("/api/v4/projects/:id/snapshot", "git-snapshot", params)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode, "GET %q: status code", resp.Request.URL) require.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) require.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, 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-Disposition", `attachment; filename="snapshot.tar"`)
testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-tar") testhelper.RequireResponseHeader(t, resp, "Content-Type", "application/x-tar")
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/require"
) )
func startWorkhorseServerWithLongPolling(authBackend string, pollingDuration time.Duration) *httptest.Server { func startWorkhorseServerWithLongPolling(authBackend string, pollingDuration time.Duration) *httptest.Server {
...@@ -33,7 +33,7 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob ...@@ -33,7 +33,7 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob
defer ws.Close() defer ws.Close()
resp, err := requestJob(ws.URL, nil) resp, err := requestJob(ws.URL, nil)
assert.NoError(t, err) require.NoError(t, err)
defer resp.Body.Close() defer resp.Body.Close()
return resp return resp
...@@ -41,12 +41,12 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob ...@@ -41,12 +41,12 @@ func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob
func testJobsLongPollingEndpointDisabled(t *testing.T, requestJob requestJobFunction) { func testJobsLongPollingEndpointDisabled(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, 0, requestJob) 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) { func testJobsLongPollingEndpoint(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, time.Minute, requestJob) 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) { func TestJobsLongPollingEndpointDisabled(t *testing.T) {
......
This diff is collapsed.
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"testing" "testing"
"github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api" "gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
...@@ -49,10 +48,10 @@ func testArtifactsUpload(t *testing.T, uploadArtifacts uploadArtifactsFunction) ...@@ -49,10 +48,10 @@ func testArtifactsUpload(t *testing.T, uploadArtifacts uploadArtifactsFunction)
defer ws.Close() defer ws.Close()
resp, resource, err := uploadArtifacts(ws.URL, contentType, reqBody) resp, resource, err := uploadArtifacts(ws.URL, contentType, reqBody)
assert.NoError(t, err) require.NoError(t, err)
defer resp.Body.Close() 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) { 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