diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-14 15:50:31 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-14 16:06:07 +0300 |
commit | 9aacb55c9b85c1fc7e080c54ededcf692aee92a5 (patch) | |
tree | 4d758ab1a376532c2b7a76f572002d3cabb8a0bc | |
parent | 412b51fc5e86ff5f0075ddadce3e248fa47ae598 (diff) |
tests: Fix random set of missing error checks
Various functions return error which we do not check. Fix these by
calling `require.NoError()` to catch any unexpected issues.
-rw-r--r-- | internal/command/command_test.go | 3 | ||||
-rw-r--r-- | internal/git/housekeeping/housekeeping_test.go | 8 | ||||
-rw-r--r-- | internal/git/stats/analyzehttp_test.go | 8 | ||||
-rw-r--r-- | internal/gitaly/service/repository/create_from_url_test.go | 4 | ||||
-rw-r--r-- | internal/middleware/limithandler/concurrency_limiter_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/coordinator_test.go | 4 | ||||
-rw-r--r-- | internal/praefect/server_test.go | 9 | ||||
-rw-r--r-- | internal/praefect/transaction_test.go | 4 | ||||
-rw-r--r-- | internal/tempdir/tempdir_test.go | 2 |
9 files changed, 27 insertions, 18 deletions
diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 2f81f24ad..74c250a6b 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -118,7 +118,8 @@ func TestRejectEmptyContextDone(t *testing.T) { } }() - New(context.Background(), exec.Command("true"), nil, nil, nil) + _, err := New(context.Background(), exec.Command("true"), nil, nil, nil) + require.NoError(t, err) } func TestNewCommandTimeout(t *testing.T) { diff --git a/internal/git/housekeeping/housekeeping_test.go b/internal/git/housekeeping/housekeeping_test.go index 3e8457294..d8e3a6e7b 100644 --- a/internal/git/housekeeping/housekeeping_test.go +++ b/internal/git/housekeeping/housekeeping_test.go @@ -208,7 +208,9 @@ func TestPerform(t *testing.T) { // We need to fix permissions so we don't fail to // remove the temporary directory after the test. - defer FixDirectoryPermissions(ctx, repoPath) + defer func() { + require.NoError(t, FixDirectoryPermissions(ctx, repoPath)) + }() for _, e := range tc.entries { e.create(t, repoPath) @@ -304,14 +306,14 @@ func TestPerform_references(t *testing.T) { require.NoError(t, Perform(ctx, repo)) var actual []string - filepath.Walk(filepath.Join(repoPath, "refs"), func(path string, info os.FileInfo, _ error) error { + require.NoError(t, filepath.Walk(filepath.Join(repoPath, "refs"), func(path string, info os.FileInfo, _ error) error { if !info.IsDir() { ref, err := filepath.Rel(repoPath, path) require.NoError(t, err) actual = append(actual, ref) } return nil - }) + })) require.ElementsMatch(t, tc.expected, actual) }) diff --git a/internal/git/stats/analyzehttp_test.go b/internal/git/stats/analyzehttp_test.go index d4971a34b..26b5f4405 100644 --- a/internal/git/stats/analyzehttp_test.go +++ b/internal/git/stats/analyzehttp_test.go @@ -20,7 +20,9 @@ func TestClone(t *testing.T) { defer cancel() serverPort, stopGitServer := gittest.GitServer(t, cfg, repoPath, nil) - defer stopGitServer() + defer func() { + require.NoError(t, stopGitServer()) + }() clone := Clone{URL: fmt.Sprintf("http://localhost:%d/%s", serverPort, filepath.Base(repoPath))} require.NoError(t, clone.Perform(ctx), "perform analysis clone") @@ -94,7 +96,9 @@ func TestCloneWithAuth(t *testing.T) { next.ServeHTTP(w, r) }) - defer stopGitServer() + defer func() { + require.NoError(t, stopGitServer()) + }() clone := Clone{ URL: fmt.Sprintf("http://localhost:%d/%s", serverPort, filepath.Base(repoPath)), diff --git a/internal/gitaly/service/repository/create_from_url_test.go b/internal/gitaly/service/repository/create_from_url_test.go index ae60f10fc..553dcae9b 100644 --- a/internal/gitaly/service/repository/create_from_url_test.go +++ b/internal/gitaly/service/repository/create_from_url_test.go @@ -40,7 +40,9 @@ func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { user := "username123" password := "password321localhost" port, stopGitServer := gitServerWithBasicAuth(t, config.Config, user, password, testRepoPath) - defer stopGitServer() + defer func() { + require.NoError(t, stopGitServer()) + }() url := fmt.Sprintf("http://%s:%s@localhost:%d/%s", user, password, port, filepath.Base(testRepoPath)) diff --git a/internal/middleware/limithandler/concurrency_limiter_test.go b/internal/middleware/limithandler/concurrency_limiter_test.go index 7300fbacc..c5070fe39 100644 --- a/internal/middleware/limithandler/concurrency_limiter_test.go +++ b/internal/middleware/limithandler/concurrency_limiter_test.go @@ -161,7 +161,7 @@ func TestLimiter(t *testing.T) { for i := 0; i < tt.iterations; i++ { lockKey := strconv.Itoa((i ^ counter) % tt.buckets) - limiter.Limit(context.Background(), lockKey, func() (interface{}, error) { + _, err := limiter.Limit(context.Background(), lockKey, func() (interface{}, error) { primePump() current := gauge.currentVal() @@ -172,6 +172,7 @@ func TestLimiter(t *testing.T) { gauge.down() return nil, nil }) + require.NoError(t, err) } wg.Done() diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go index ae38bdca9..8ab075f20 100644 --- a/internal/praefect/coordinator_test.go +++ b/internal/praefect/coordinator_test.go @@ -208,7 +208,7 @@ func TestStreamDirectorMutator(t *testing.T) { replEventWait.Add(1) // expected only one event to be created // this call creates new events in the queue and simulates usual flow of the update operation - streamParams.RequestFinalizer() + require.NoError(t, streamParams.RequestFinalizer()) replEventWait.Wait() // wait until event persisted (async operation) events, err := queueInterceptor.Dequeue(ctx, "praefect", "praefect-internal-2", 10) @@ -1078,7 +1078,7 @@ func TestAbsentCorrelationID(t *testing.T) { replEventWait.Add(1) // expected only one event to be created // must be run as it adds replication events to the queue - streamParams.RequestFinalizer() + require.NoError(t, streamParams.RequestFinalizer()) replEventWait.Wait() // wait until event persisted (async operation) jobs, err := queueInterceptor.Dequeue(ctx, conf.VirtualStorages[0].Name, conf.VirtualStorages[0].Nodes[1].Storage, 1) diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index 57c618927..1e3531510 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -632,8 +632,7 @@ func (m *mockSmartHTTP) InfoRefsUploadPack(req *gitalypb.InfoRefsRequest, stream m.methodsCalled["InfoRefsUploadPack"]++ - stream.Send(&gitalypb.InfoRefsResponse{}) - return nil + return stream.Send(&gitalypb.InfoRefsResponse{}) } func (m *mockSmartHTTP) InfoRefsReceivePack(req *gitalypb.InfoRefsRequest, stream gitalypb.SmartHTTPService_InfoRefsReceivePackServer) error { @@ -645,8 +644,7 @@ func (m *mockSmartHTTP) InfoRefsReceivePack(req *gitalypb.InfoRefsRequest, strea m.methodsCalled["InfoRefsReceivePack"]++ - stream.Send(&gitalypb.InfoRefsResponse{}) - return nil + return stream.Send(&gitalypb.InfoRefsResponse{}) } func (m *mockSmartHTTP) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackServer) error { @@ -658,8 +656,7 @@ func (m *mockSmartHTTP) PostUploadPack(stream gitalypb.SmartHTTPService_PostUplo m.methodsCalled["PostUploadPack"]++ - stream.Send(&gitalypb.PostUploadPackResponse{}) - return nil + return stream.Send(&gitalypb.PostUploadPackResponse{}) } func (m *mockSmartHTTP) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePackServer) error { diff --git a/internal/praefect/transaction_test.go b/internal/praefect/transaction_test.go index d9a579949..0d1bf1d96 100644 --- a/internal/praefect/transaction_test.go +++ b/internal/praefect/transaction_test.go @@ -415,7 +415,9 @@ func TestTransactionReachesQuorum(t *testing.T) { transaction, cancel, err := txMgr.RegisterTransaction(ctx, voters, tc.threshold) require.NoError(t, err) - defer cancel() + defer func() { + require.NoError(t, cancel()) + }() var wg sync.WaitGroup for i, v := range tc.voters { diff --git a/internal/tempdir/tempdir_test.go b/internal/tempdir/tempdir_test.go index b792ae2c1..fef06b361 100644 --- a/internal/tempdir/tempdir_test.go +++ b/internal/tempdir/tempdir_test.go @@ -69,7 +69,7 @@ func TestCleanerSafety(t *testing.T) { //This directory is invalid because it does not end in '+gitaly/tmp' invalidDir := "testdata/does-not-exist" - clean(invalidDir) + require.NoError(t, clean(invalidDir)) t.Fatal("expected panic") } |