diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-16 15:15:24 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-20 17:22:33 +0300 |
commit | 127ca6b9de8d5cca31db5e2345519cf39b0a0e29 (patch) | |
tree | 74d34290ed1e9ca3b356094e68ff5ef7504fa8b9 | |
parent | 4311879356b4a4fcb704373b33afd41148e34fc7 (diff) |
global: Replace deprecated usage of `ioutil.ReadAll()`
With Go 1.16, the ioutil package was deprecated. Replace our usage of
`ioutil.ReadAll()` with `io.ReadAll()` to adapt accordingly.
50 files changed, 105 insertions, 120 deletions
diff --git a/internal/backup/filesystem_sink_test.go b/internal/backup/filesystem_sink_test.go index feeda5294..804f29413 100644 --- a/internal/backup/filesystem_sink_test.go +++ b/internal/backup/filesystem_sink_test.go @@ -2,6 +2,7 @@ package backup import ( "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -27,7 +28,7 @@ func TestFilesystemSink_GetReader(t *testing.T) { defer func() { require.NoError(t, reader.Close()) }() - data, err := ioutil.ReadAll(reader) + data, err := io.ReadAll(reader) require.NoError(t, err) require.Equal(t, []byte("test"), data) }) diff --git a/internal/backup/locator.go b/internal/backup/locator.go index 5e5d4e3f5..6110240b9 100644 --- a/internal/backup/locator.go +++ b/internal/backup/locator.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "path/filepath" "strings" @@ -110,7 +110,7 @@ func (l PointerLocator) findLatestID(ctx context.Context, backupPath string) (st } defer r.Close() - latest, err := ioutil.ReadAll(r) + latest, err := io.ReadAll(r) if err != nil { return "", fmt.Errorf("find latest ID: %w", err) } diff --git a/internal/backup/storage_service_sink_test.go b/internal/backup/storage_service_sink_test.go index 1e7f8a35d..5b740df46 100644 --- a/internal/backup/storage_service_sink_test.go +++ b/internal/backup/storage_service_sink_test.go @@ -3,7 +3,7 @@ package backup import ( "bytes" "fmt" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/require" @@ -30,7 +30,7 @@ func TestStorageServiceSink(t *testing.T) { require.NoError(t, err) defer func() { require.NoError(t, reader.Close()) }() - retrieved, err := ioutil.ReadAll(reader) + retrieved, err := io.ReadAll(reader) require.NoError(t, err) require.Equal(t, data, retrieved) }) diff --git a/internal/cache/diskcache_test.go b/internal/cache/diskcache_test.go index af858cbc9..04bc54964 100644 --- a/internal/cache/diskcache_test.go +++ b/internal/cache/diskcache_test.go @@ -3,7 +3,6 @@ package cache import ( "context" "io" - "io/ioutil" "strings" "sync" "testing" @@ -49,7 +48,7 @@ func TestStreamDBNaiveKeyer(t *testing.T) { expectGetHit := func(expectStr string, req *gitalypb.InfoRefsRequest) { actualStream, err := cache.GetStream(ctx, req.Repository, req) require.NoError(t, err) - actualBytes, err := ioutil.ReadAll(actualStream) + actualBytes, err := io.ReadAll(actualStream) require.NoError(t, err) require.Equal(t, expectStr, string(actualBytes)) } diff --git a/internal/git/catfile/batch_cache_test.go b/internal/git/catfile/batch_cache_test.go index 45fbe4c80..9816c0d7d 100644 --- a/internal/git/catfile/batch_cache_test.go +++ b/internal/git/catfile/batch_cache_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "io" - "io/ioutil" "os" "sync" "testing" @@ -218,7 +217,7 @@ func TestCache_BatchProcess(t *testing.T) { // batch processes and trying to read from their stdout. If the cancel did kill the // process as expected, then the stdout should be closed and we'll get an EOF. for _, reader := range []io.Reader{batch.objectInfoReader.cmd, batch.objectReader.cmd} { - output, err := ioutil.ReadAll(reader) + output, err := io.ReadAll(reader) if err != nil { require.True(t, errors.Is(err, os.ErrClosed)) } else { diff --git a/internal/git/catfile/batch_test.go b/internal/git/catfile/batch_test.go index db32c66be..95e62cb96 100644 --- a/internal/git/catfile/batch_test.go +++ b/internal/git/catfile/batch_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "os/exec" "strconv" @@ -123,7 +122,7 @@ func TestBlob(t *testing.T) { require.NoError(t, err) require.Equal(t, tc.objInfo, blobObj.ObjectInfo) - contents, err := ioutil.ReadAll(blobObj.Reader) + contents, err := io.ReadAll(blobObj.Reader) require.NoError(t, err) require.Equal(t, tc.content, contents) }) @@ -155,7 +154,7 @@ func TestCommit(t *testing.T) { commitReader, err := c.Commit(ctx, git.Revision(tc.revision)) require.NoError(t, err) - contents, err := ioutil.ReadAll(commitReader) + contents, err := io.ReadAll(commitReader) require.NoError(t, err) require.Equal(t, tc.output, string(contents)) @@ -218,7 +217,7 @@ func TestTag(t *testing.T) { require.NoError(t, err) require.Equal(t, tc.objInfo, tagObj.ObjectInfo) - contents, err := ioutil.ReadAll(tagObj.Reader) + contents, err := io.ReadAll(tagObj.Reader) require.NoError(t, err) require.Equal(t, tc.content, contents) }) @@ -280,7 +279,7 @@ func TestTree(t *testing.T) { require.NoError(t, err) require.Equal(t, tc.objInfo, treeObj.ObjectInfo) - contents, err := ioutil.ReadAll(treeObj.Reader) + contents, err := io.ReadAll(treeObj.Reader) require.NoError(t, err) require.Equal(t, tc.content, contents) }) @@ -299,7 +298,7 @@ func TestRepeatedCalls(t *testing.T) { tree1Obj, err := c.Tree(ctx, treeOid) require.NoError(t, err) - tree1, err := ioutil.ReadAll(tree1Obj.Reader) + tree1, err := io.ReadAll(tree1Obj.Reader) require.NoError(t, err) require.Equal(t, string(treeBytes), string(tree1)) @@ -322,7 +321,7 @@ func TestRepeatedCalls(t *testing.T) { tree2Obj, err := c.Tree(ctx, treeOid) require.NoError(t, err) - tree2, err := ioutil.ReadAll(tree2Obj.Reader) + tree2, err := io.ReadAll(tree2Obj.Reader) require.NoError(t, err, "request should succeed because blob was consumed") require.Equal(t, string(treeBytes), string(tree2)) diff --git a/internal/git/catfile/commit.go b/internal/git/catfile/commit.go index 32ff48706..3bf3f87c6 100644 --- a/internal/git/catfile/commit.go +++ b/internal/git/catfile/commit.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "strconv" "strings" @@ -80,7 +79,7 @@ func GetCommitMessage(ctx context.Context, c Batch, repo repository.GitRepo, rev } func splitRawCommit(r io.Reader) ([]byte, []byte, error) { - raw, err := ioutil.ReadAll(r) + raw, err := io.ReadAll(r) if err != nil { return nil, nil, err } @@ -143,7 +142,7 @@ func ParseCommit(r io.Reader, oid git.ObjectID) (*gitalypb.GitCommit, error) { } } - body, err := ioutil.ReadAll(b) + body, err := io.ReadAll(b) if err != nil { return nil, fmt.Errorf("parse raw commit: body: %w", err) } diff --git a/internal/git/catfile/object_reader_test.go b/internal/git/catfile/object_reader_test.go index dfb3dafe5..50f07c4e2 100644 --- a/internal/git/catfile/object_reader_test.go +++ b/internal/git/catfile/object_reader_test.go @@ -3,7 +3,6 @@ package catfile import ( "fmt" "io" - "io/ioutil" "testing" "github.com/prometheus/client_golang/prometheus" @@ -33,7 +32,7 @@ func TestObjectReader_reader(t *testing.T) { object, err := reader.reader(ctx, "refs/heads/master", "commit") require.NoError(t, err) - data, err := ioutil.ReadAll(object) + data, err := io.ReadAll(object) require.NoError(t, err) require.Equal(t, commitContents, data) }) @@ -45,7 +44,7 @@ func TestObjectReader_reader(t *testing.T) { object, err := reader.reader(ctx, commitID.Revision(), "commit") require.NoError(t, err) - data, err := ioutil.ReadAll(object) + data, err := io.ReadAll(object) require.NoError(t, err) require.Contains(t, string(data), "Merge branch 'cherry-pick-ce369011' into 'master'\n") @@ -62,7 +61,7 @@ func TestObjectReader_reader(t *testing.T) { object, err := reader.reader(ctx, commitID.Revision(), "commit") require.NoError(t, err) - data, err := ioutil.ReadAll(object) + data, err := io.ReadAll(object) require.NoError(t, err) require.Equal(t, commitContents, data) @@ -79,7 +78,7 @@ func TestObjectReader_reader(t *testing.T) { object, err := reader.reader(ctx, commitID.Revision(), "commit") require.NoError(t, err) - data, err := ioutil.ReadAll(object) + data, err := io.ReadAll(object) require.NoError(t, err) require.Equal(t, commitContents, data) diff --git a/internal/git/catfile/tag.go b/internal/git/catfile/tag.go index b0ac68d51..74826650a 100644 --- a/internal/git/catfile/tag.go +++ b/internal/git/catfile/tag.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "strings" "gitlab.com/gitlab-org/gitaly/v14/internal/git" @@ -59,7 +58,7 @@ type tagHeader struct { } func splitRawTag(r io.Reader, trimRightNewLine bool) (*tagHeader, []byte, error) { - raw, err := ioutil.ReadAll(r) + raw, err := io.ReadAll(r) if err != nil { return nil, nil, err } diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 566dbe6a1..6b3157791 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -2,7 +2,7 @@ package git_test import ( "bytes" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -77,7 +77,7 @@ func TestExecCommandFactory_NewWithDir(t *testing.T) { }, git.WithStderr(&stderr)) require.NoError(t, err) - revData, err := ioutil.ReadAll(cmd) + revData, err := io.ReadAll(cmd) require.NoError(t, err) require.NoError(t, cmd.Wait(), stderr.String()) diff --git a/internal/git/gitio/hashfile_test.go b/internal/git/gitio/hashfile_test.go index a7a317b91..a18dea7f8 100644 --- a/internal/git/gitio/hashfile_test.go +++ b/internal/git/gitio/hashfile_test.go @@ -1,7 +1,7 @@ package gitio import ( - "io/ioutil" + "io" "strings" "testing" @@ -42,7 +42,7 @@ func TestHashfileReader(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { r := NewHashfileReader(strings.NewReader(tc.in)) - out, err := ioutil.ReadAll(r) + out, err := io.ReadAll(r) if tc.fail { require.Error(t, err, "invalid input should cause error") return diff --git a/internal/git/gitio/trailer_test.go b/internal/git/gitio/trailer_test.go index d01a97119..a8731e331 100644 --- a/internal/git/gitio/trailer_test.go +++ b/internal/git/gitio/trailer_test.go @@ -1,7 +1,7 @@ package gitio import ( - "io/ioutil" + "io" "strings" "testing" @@ -42,7 +42,7 @@ func TestTrailerReaderSuccess(t *testing.T) { tr := NewTrailerReader(strings.NewReader(tc.in), trailerLen) require.Len(t, tc.trailer, trailerLen, "test case trailer sanity check") - out, err := ioutil.ReadAll(tr) + out, err := io.ReadAll(tr) require.NoError(t, err, "read all") require.Equal(t, tc.out, string(out), "compare output") @@ -63,7 +63,7 @@ func TestTrailerReaderFail(t *testing.T) { _, err := tr.Trailer() require.Error(t, err, "Trailer() should fail when called too early") - out, err := ioutil.ReadAll(tr) + out, err := io.ReadAll(tr) require.NoError(t, err, "read") require.Empty(t, out, "read output") diff --git a/internal/git/gitpipe/catfile_object_test.go b/internal/git/gitpipe/catfile_object_test.go index 4c8d4685e..dbf9eafef 100644 --- a/internal/git/gitpipe/catfile_object_test.go +++ b/internal/git/gitpipe/catfile_object_test.go @@ -2,7 +2,7 @@ package gitpipe import ( "errors" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/require" @@ -107,7 +107,7 @@ func TestCatfileObject(t *testing.T) { // this: it would just be too annoying. require.NotNil(t, result.ObjectReader) - objectData, err := ioutil.ReadAll(result.ObjectReader) + objectData, err := io.ReadAll(result.ObjectReader) require.NoError(t, err) require.Len(t, objectData, int(result.ObjectInfo.Size)) diff --git a/internal/git/gitpipe/pipeline_test.go b/internal/git/gitpipe/pipeline_test.go index 8546b7809..6ec16e2a4 100644 --- a/internal/git/gitpipe/pipeline_test.go +++ b/internal/git/gitpipe/pipeline_test.go @@ -3,7 +3,6 @@ package gitpipe import ( "errors" "io" - "io/ioutil" "sync" "testing" @@ -232,7 +231,7 @@ func TestPipeline_revlist(t *testing.T) { // this: it would just be too annoying. require.NotNil(t, result.ObjectReader) - objectData, err := ioutil.ReadAll(result.ObjectReader) + objectData, err := io.ReadAll(result.ObjectReader) require.NoError(t, err) require.Len(t, objectData, int(result.ObjectInfo.Size)) @@ -363,7 +362,7 @@ func TestPipeline_forEachRef(t *testing.T) { // this: it would just be too annoying. require.NotNil(t, result.ObjectReader) - objectData, err := ioutil.ReadAll(result.ObjectReader) + objectData, err := io.ReadAll(result.ObjectReader) require.NoError(t, err) require.Len(t, objectData, int(result.ObjectInfo.Size)) diff --git a/internal/git/gittest/delta_islands.go b/internal/git/gittest/delta_islands.go index 4bd7538b3..c278f0163 100644 --- a/internal/git/gittest/delta_islands.go +++ b/internal/git/gittest/delta_islands.go @@ -3,7 +3,6 @@ package gittest import ( "crypto/rand" "io" - "io/ioutil" "strings" "testing" @@ -17,7 +16,7 @@ import ( // https://github.com/git/git/blob/master/t/t5320-delta-islands.sh . func TestDeltaIslands(t *testing.T, cfg config.Cfg, repoPath string, repack func() error) { // Create blobs that we expect Git to use delta compression on. - blob1, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 100000)) + blob1, err := io.ReadAll(io.LimitReader(rand.Reader, 100000)) require.NoError(t, err) blob2 := append(blob1, "\nblob 2"...) diff --git a/internal/git/log/last_commit.go b/internal/git/log/last_commit.go index 6690dbc21..118742bbe 100644 --- a/internal/git/log/last_commit.go +++ b/internal/git/log/last_commit.go @@ -2,7 +2,7 @@ package log import ( "context" - "io/ioutil" + "io" "gitlab.com/gitlab-org/gitaly/v14/internal/command" "gitlab.com/gitlab-org/gitaly/v14/internal/git" @@ -24,7 +24,7 @@ func LastCommitForPath(ctx context.Context, gitCmdFactory git.CommandFactory, ba return nil, err } - commitID, err := ioutil.ReadAll(cmd) + commitID, err := io.ReadAll(cmd) if err != nil { return nil, err } diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go index 5a6e76859..45fc92de3 100644 --- a/internal/git/objectpool/fetch.go +++ b/internal/git/objectpool/fetch.go @@ -5,7 +5,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "os/exec" "path/filepath" "strconv" @@ -238,7 +238,7 @@ func sizeDir(ctx context.Context, dir string) (int64, error) { return 0, err } - sizeLine, err := ioutil.ReadAll(cmd) + sizeLine, err := io.ReadAll(cmd) if err != nil { return 0, err } diff --git a/internal/git/pktline/read_monitor_test.go b/internal/git/pktline/read_monitor_test.go index 5558dd5e5..e34cc2e6a 100644 --- a/internal/git/pktline/read_monitor_test.go +++ b/internal/git/pktline/read_monitor_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "os" "strings" "testing" @@ -41,7 +40,7 @@ func TestReadMonitorTimeout(t *testing.T) { require.True(t, elapsed < time.Second, "Expected context to be cancelled quickly, but it was not") // Verify that pipe is closed - _, err = ioutil.ReadAll(r) + _, err = io.ReadAll(r) require.Error(t, err) require.IsType(t, &os.PathError{}, err) } diff --git a/internal/git/updateref/update_with_hooks_test.go b/internal/git/updateref/update_with_hooks_test.go index a8775efdf..3ba066d30 100644 --- a/internal/git/updateref/update_with_hooks_test.go +++ b/internal/git/updateref/update_with_hooks_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "strings" "testing" @@ -137,7 +136,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) { { desc: "successful update", preReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error { - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes)) require.Empty(t, pushOptions) @@ -152,7 +151,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) { return nil }, postReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error { - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes)) require.Equal(t, env, expectedEnv) @@ -160,7 +159,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) { return nil }, referenceTransaction: func(t *testing.T, ctx context.Context, state hook.ReferenceTransactionState, env []string, stdin io.Reader) error { - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes)) diff --git a/internal/git/version.go b/internal/git/version.go index dddf152ee..7bb02eeb2 100644 --- a/internal/git/version.go +++ b/internal/git/version.go @@ -3,7 +3,7 @@ package git import ( "context" "fmt" - "io/ioutil" + "io" "strconv" "strings" @@ -64,7 +64,7 @@ func CurrentVersionForExecutor(ctx context.Context, executor RepositoryExecutor) } func parseVersionFromCommand(cmd *command.Command) (Version, error) { - versionOutput, err := ioutil.ReadAll(cmd) + versionOutput, err := io.ReadAll(cmd) if err != nil { return Version{}, fmt.Errorf("reading version output: %w", err) } diff --git a/internal/gitaly/hook/custom.go b/internal/gitaly/hook/custom.go index 8c894e09d..63d2fa3d1 100644 --- a/internal/gitaly/hook/custom.go +++ b/internal/gitaly/hook/custom.go @@ -57,7 +57,7 @@ func (m *GitLabHookManager) newCustomHooksExecutor(repo *gitalypb.Repository, ho return func(ctx context.Context, args, env []string, stdin io.Reader, stdout, stderr io.Writer) error { var stdinBytes []byte if stdin != nil { - stdinBytes, err = ioutil.ReadAll(stdin) + stdinBytes, err = io.ReadAll(stdin) if err != nil { return err } diff --git a/internal/gitaly/hook/postreceive.go b/internal/gitaly/hook/postreceive.go index a9082049e..1bfd40fe2 100644 --- a/internal/gitaly/hook/postreceive.go +++ b/internal/gitaly/hook/postreceive.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "strings" @@ -123,7 +122,7 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. return helper.ErrInternalf("extracting hooks payload: %w", err) } - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) if err != nil { return helper.ErrInternalf("reading stdin from request: %w", err) } diff --git a/internal/gitaly/hook/prereceive.go b/internal/gitaly/hook/prereceive.go index d0f6e4b35..1277fb541 100644 --- a/internal/gitaly/hook/prereceive.go +++ b/internal/gitaly/hook/prereceive.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "path/filepath" "strings" @@ -68,7 +67,7 @@ func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.R return helper.ErrInternalf("extracting hooks payload: %w", err) } - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) if err != nil { return helper.ErrInternalf("reading stdin from request: %w", err) } diff --git a/internal/gitaly/hook/referencetransaction.go b/internal/gitaly/hook/referencetransaction.go index 7d2fbd4ad..e75ea3cb0 100644 --- a/internal/gitaly/hook/referencetransaction.go +++ b/internal/gitaly/hook/referencetransaction.go @@ -7,7 +7,6 @@ import ( "crypto/sha1" "fmt" "io" - "io/ioutil" "gitlab.com/gitlab-org/gitaly/v14/internal/git" ) @@ -22,7 +21,7 @@ func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state return fmt.Errorf("extracting hooks payload: %w", err) } - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) if err != nil { return fmt.Errorf("reading stdin from request: %w", err) } diff --git a/internal/gitaly/hook/sidechannel_test.go b/internal/gitaly/hook/sidechannel_test.go index b142f1014..45341322d 100644 --- a/internal/gitaly/hook/sidechannel_test.go +++ b/internal/gitaly/hook/sidechannel_test.go @@ -3,7 +3,6 @@ package hook import ( "context" "io" - "io/ioutil" "net" "testing" @@ -30,7 +29,7 @@ func TestSidechannel(t *testing.T) { require.NoError(t, err) defer c.Close() - buf, err := ioutil.ReadAll(c) + buf, err := io.ReadAll(c) require.NoError(t, err) require.Equal(t, "ping", string(buf)) diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go index ebe9dd8d0..c815a5237 100644 --- a/internal/gitaly/linguist/linguist.go +++ b/internal/gitaly/linguist/linguist.go @@ -55,7 +55,7 @@ func (inst *Instance) Stats(ctx context.Context, cfg config.Cfg, repoPath string return nil, fmt.Errorf("starting linguist: %w", err) } - data, err := ioutil.ReadAll(cmd) + data, err := io.ReadAll(cmd) if err != nil { return nil, fmt.Errorf("reading linguist output: %w", err) } diff --git a/internal/gitaly/server/auth_test.go b/internal/gitaly/server/auth_test.go index 94f5e9ef5..2dbde3056 100644 --- a/internal/gitaly/server/auth_test.go +++ b/internal/gitaly/server/auth_test.go @@ -5,7 +5,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" + "io" "net" "os" "testing" @@ -292,7 +292,7 @@ func TestStreamingNoAuth(t *testing.T) { ) require.NoError(t, err) - _, err = ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) { + _, err = io.ReadAll(streamio.NewReader(func() ([]byte, error) { _, err = stream.Recv() return nil, err })) diff --git a/internal/gitaly/service/commit/count_commits.go b/internal/gitaly/service/commit/count_commits.go index 408a04d3c..6dc68e250 100644 --- a/internal/gitaly/service/commit/count_commits.go +++ b/internal/gitaly/service/commit/count_commits.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "strconv" "time" @@ -54,7 +54,7 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ } var count int64 - countStr, readAllErr := ioutil.ReadAll(cmd) + countStr, readAllErr := io.ReadAll(cmd) if readAllErr != nil { ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git rev-list error") } diff --git a/internal/gitaly/service/commit/count_diverging_commits.go b/internal/gitaly/service/commit/count_diverging_commits.go index a4ee6a903..f47b135da 100644 --- a/internal/gitaly/service/commit/count_diverging_commits.go +++ b/internal/gitaly/service/commit/count_diverging_commits.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "strconv" "strings" @@ -65,7 +65,7 @@ func (s *server) findLeftRightCount(ctx context.Context, repo *gitalypb.Reposito } var leftCount, rightCount int64 - countStr, err := ioutil.ReadAll(cmd) + countStr, err := io.ReadAll(cmd) if err != nil { return 0, 0, fmt.Errorf("git rev-list error: %v", err) } diff --git a/internal/gitaly/service/commit/raw_blame_test.go b/internal/gitaly/service/commit/raw_blame_test.go index cb4c21085..31abdc77b 100644 --- a/internal/gitaly/service/commit/raw_blame_test.go +++ b/internal/gitaly/service/commit/raw_blame_test.go @@ -2,7 +2,7 @@ package commit import ( "fmt" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/require" @@ -54,7 +54,7 @@ func TestSuccessfulRawBlameRequest(t *testing.T) { return response.GetData(), err }) - blame, err := ioutil.ReadAll(sr) + blame, err := io.ReadAll(sr) require.NoError(t, err) require.Equal(t, testCase.data, blame, "blame data mismatched") diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index 3c08fd012..cce440526 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -129,7 +129,7 @@ func TestSuccessfulResolveConflictsRequestHelper(t *testing.T) { hookCount := 0 verifyFunc := func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error { - changes, err := ioutil.ReadAll(stdin) + changes, err := io.ReadAll(stdin) require.NoError(t, err) pattern := fmt.Sprintf("%s .* refs/heads/%s\n", ourCommitOID, sourceBranch) require.Regexp(t, regexp.MustCompile(pattern), string(changes)) diff --git a/internal/gitaly/service/diff/raw_test.go b/internal/gitaly/service/diff/raw_test.go index 05b0a7c01..5a70e3eae 100644 --- a/internal/gitaly/service/diff/raw_test.go +++ b/internal/gitaly/service/diff/raw_test.go @@ -2,7 +2,7 @@ package diff import ( "fmt" - "io/ioutil" + "io" "regexp" "testing" @@ -197,7 +197,7 @@ func TestRawPatchContainsGitLabSignature(t *testing.T) { return response.GetData(), err }) - patch, err := ioutil.ReadAll(reader) + patch, err := io.ReadAll(reader) require.NoError(t, err) require.Regexp(t, regexp.MustCompile(`\n-- \nGitLab\s+$`), string(patch)) diff --git a/internal/gitaly/service/ref/tag_signatures.go b/internal/gitaly/service/ref/tag_signatures.go index 61239afae..57f656f4f 100644 --- a/internal/gitaly/service/ref/tag_signatures.go +++ b/internal/gitaly/service/ref/tag_signatures.go @@ -3,7 +3,7 @@ package ref import ( "errors" "fmt" - "io/ioutil" + "io" "strings" "gitlab.com/gitlab-org/gitaly/v14/internal/git" @@ -77,7 +77,7 @@ func (s *server) GetTagSignatures(req *gitalypb.GetTagSignaturesRequest, stream for catfileObjectIter.Next() { tag := catfileObjectIter.Result() - raw, err := ioutil.ReadAll(tag.ObjectReader) + raw, err := io.ReadAll(tag.ObjectReader) if err != nil { return helper.ErrInternal(err) } diff --git a/internal/gitaly/service/remote/find_remote_repository.go b/internal/gitaly/service/remote/find_remote_repository.go index 1d0088390..5504da686 100644 --- a/internal/gitaly/service/remote/find_remote_repository.go +++ b/internal/gitaly/service/remote/find_remote_repository.go @@ -3,7 +3,7 @@ package remote import ( "bytes" "context" - "io/ioutil" + "io" "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" @@ -29,7 +29,7 @@ func (s *server) FindRemoteRepository(ctx context.Context, req *gitalypb.FindRem return nil, status.Errorf(codes.Internal, "error executing git command: %s", err) } - output, err := ioutil.ReadAll(cmd) + output, err := io.ReadAll(cmd) if err != nil { return nil, status.Errorf(codes.Internal, "unable to read stdout: %s", err) } diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index 7098a4910..b902d0753 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -263,7 +264,7 @@ func TestGetArchiveWithLfsSuccess(t *testing.T) { require.NoError(t, err) defer fc.Close() - data, err := ioutil.ReadAll(fc) + data, err := io.ReadAll(fc) require.NoError(t, err) if tc.includeLfsBlobs { @@ -464,7 +465,7 @@ func TestGetArchivePathInjection(t *testing.T) { require.NoError(t, err) defer authorizedKeysFile.Close() - authorizedKeysFileBytes, err := ioutil.ReadAll(authorizedKeysFile) + authorizedKeysFileBytes, err := io.ReadAll(authorizedKeysFile) require.NoError(t, err) authorizedKeysFileStat, err := authorizedKeysFile.Stat() require.NoError(t, err) @@ -557,5 +558,5 @@ func consumeArchive(stream gitalypb.RepositoryService_GetArchiveClient) ([]byte, return response.GetData(), err }) - return ioutil.ReadAll(reader) + return io.ReadAll(reader) } diff --git a/internal/gitaly/service/repository/config_test.go b/internal/gitaly/service/repository/config_test.go index 8988ae6ef..29aa50153 100644 --- a/internal/gitaly/service/repository/config_test.go +++ b/internal/gitaly/service/repository/config_test.go @@ -4,7 +4,7 @@ import ( "bufio" "bytes" "context" - "io/ioutil" + "io" "os" "path/filepath" "strings" @@ -54,7 +54,7 @@ func TestGetConfig(t *testing.T) { return bytes, err }) - contents, err := ioutil.ReadAll(reader) + contents, err := io.ReadAll(reader) return string(contents), err } diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go index 429a2079a..23f4e915a 100644 --- a/internal/gitaly/service/repository/info_attributes_test.go +++ b/internal/gitaly/service/repository/info_attributes_test.go @@ -2,6 +2,7 @@ package repository import ( "bytes" + "io" "io/ioutil" "os" "path/filepath" @@ -33,7 +34,7 @@ func TestGetInfoAttributesExisting(t *testing.T) { stream, err := client.GetInfoAttributes(testCtx, request) require.NoError(t, err) - receivedData, err := ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) { + receivedData, err := io.ReadAll(streamio.NewReader(func() ([]byte, error) { response, err := stream.Recv() return response.GetAttributes(), err })) diff --git a/internal/gitaly/service/repository/merge_base.go b/internal/gitaly/service/repository/merge_base.go index 07f284cdd..52653d150 100644 --- a/internal/gitaly/service/repository/merge_base.go +++ b/internal/gitaly/service/repository/merge_base.go @@ -2,7 +2,7 @@ package repository import ( "context" - "io/ioutil" + "io" "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" @@ -34,7 +34,7 @@ func (s *server) FindMergeBase(ctx context.Context, req *gitalypb.FindMergeBaseR return nil, status.Errorf(codes.Internal, "FindMergeBase: cmd: %v", err) } - mergeBase, err := ioutil.ReadAll(cmd) + mergeBase, err := io.ReadAll(cmd) if err != nil { return nil, err } diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go index 8036b4b78..dc4e500dc 100644 --- a/internal/gitaly/service/repository/size.go +++ b/internal/gitaly/service/repository/size.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "os/exec" "strconv" @@ -38,7 +38,7 @@ func getPathSize(ctx context.Context, path string) int64 { return 0 } - sizeLine, err := ioutil.ReadAll(cmd) + sizeLine, err := io.ReadAll(cmd) if err != nil { ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring command read error") return 0 diff --git a/internal/gitaly/service/smarthttp/inforefs_test.go b/internal/gitaly/service/smarthttp/inforefs_test.go index 8a2244d83..c06b5274d 100644 --- a/internal/gitaly/service/smarthttp/inforefs_test.go +++ b/internal/gitaly/service/smarthttp/inforefs_test.go @@ -151,7 +151,7 @@ func makeInfoRefsUploadPackRequest(ctx context.Context, t *testing.T, serverSock c, err := client.InfoRefsUploadPack(ctx, rpcRequest) require.NoError(t, err) - response, err := ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) { + response, err := io.ReadAll(streamio.NewReader(func() ([]byte, error) { resp, err := c.Recv() return resp.GetData(), err })) @@ -254,7 +254,7 @@ func makeInfoRefsReceivePackRequest(ctx context.Context, t *testing.T, serverSoc c, err := client.InfoRefsReceivePack(ctx, rpcRequest) require.NoError(t, err) - response, err := ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) { + response, err := io.ReadAll(streamio.NewReader(func() ([]byte, error) { resp, err := c.Recv() return resp.GetData(), err })) diff --git a/internal/listenmux/mux.go b/internal/listenmux/mux.go index ad1f468a6..f5a1ed67a 100644 --- a/internal/listenmux/mux.go +++ b/internal/listenmux/mux.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "google.golang.org/grpc/credentials" @@ -73,7 +72,7 @@ func (m *Mux) ServerHandshake(conn net.Conn) (net.Conn, credentials.AuthInfo, er return nil, nil, fmt.Errorf("wrapped server handshake: %w", err) } - peeked, err := ioutil.ReadAll(io.LimitReader(conn, magicLen)) + peeked, err := io.ReadAll(io.LimitReader(conn, magicLen)) if err != nil { return nil, nil, fmt.Errorf("peek network stream: %w", err) } diff --git a/internal/listenmux/mux_test.go b/internal/listenmux/mux_test.go index 905329fbe..4ab8c488a 100644 --- a/internal/listenmux/mux_test.go +++ b/internal/listenmux/mux_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" "net" "syscall" @@ -253,7 +252,7 @@ func TestMux_concurrency(t *testing.T) { return err } - out, err := ioutil.ReadAll(c) + out, err := io.ReadAll(c) if err != nil { return err } diff --git a/internal/sidechannel/registry_test.go b/internal/sidechannel/registry_test.go index 5b8217e70..07d2f85c1 100644 --- a/internal/sidechannel/registry_test.go +++ b/internal/sidechannel/registry_test.go @@ -2,7 +2,7 @@ package sidechannel import ( "fmt" - "io/ioutil" + "io" "net" "strconv" "sync" @@ -60,7 +60,7 @@ func TestRegistry(t *testing.T) { } for i := 0; i < N; i++ { - out, err := ioutil.ReadAll(servers[i]) + out, err := io.ReadAll(servers[i]) require.NoError(t, err) require.Equal(t, strconv.Itoa(i), string(out)) } diff --git a/internal/sidechannel/sidechannel_test.go b/internal/sidechannel/sidechannel_test.go index bfcd4fa42..c85517952 100644 --- a/internal/sidechannel/sidechannel_test.go +++ b/internal/sidechannel/sidechannel_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "math/rand" "net" "sync" @@ -52,7 +51,7 @@ func TestSidechannel(t *testing.T) { errC := make(chan error, 1) go func() { var err error - out, err = ioutil.ReadAll(conn) + out, err = io.ReadAll(conn) errC <- err }() @@ -118,7 +117,7 @@ func TestSidechannelConcurrency(t *testing.T) { errC := make(chan error, 1) go func() { var err error - outs[i], err = ioutil.ReadAll(conn) + outs[i], err = io.ReadAll(conn) errC <- err }() diff --git a/internal/streamcache/cache_test.go b/internal/streamcache/cache_test.go index c8aaf17c1..708d09fd9 100644 --- a/internal/streamcache/cache_test.go +++ b/internal/streamcache/cache_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -49,7 +48,7 @@ func TestCache_writeOneReadMultiple(t *testing.T) { require.Equal(t, i == 0, created, "all calls except the first one should be cache hits") - out, err := ioutil.ReadAll(r) + out, err := io.ReadAll(r) require.NoError(t, err) require.NoError(t, r.Wait(context.Background())) require.Equal(t, content(0), string(out), "expect cache hits for all i > 0") @@ -89,7 +88,7 @@ func TestCache_manyConcurrentWrites(t *testing.T) { } defer r.Close() - out, err := ioutil.ReadAll(r) + out, err := io.ReadAll(r) if err != nil { return err } @@ -166,11 +165,11 @@ func TestCache_deletedFile(t *testing.T) { defer r2.Close() require.True(t, created, "because the first file is gone, cache is forced to create a new entry") - out1, err := ioutil.ReadAll(r1) + out1, err := io.ReadAll(r1) require.NoError(t, err) require.Equal(t, content(1), string(out1), "r1 should still see its original pre-wipe contents") - out2, err := ioutil.ReadAll(r2) + out2, err := io.ReadAll(r2) require.NoError(t, err) require.Equal(t, content(2), string(out2), "r2 should see the new post-wipe contents") } @@ -214,7 +213,7 @@ func TestCache_scope(t *testing.T) { for i := 0; i < N; i++ { r, content := reader[i], input[i] - out, err := ioutil.ReadAll(r) + out, err := io.ReadAll(r) require.NoError(t, err) require.NoError(t, r.Wait(context.Background())) @@ -269,7 +268,7 @@ func TestCache_diskCleanup(t *testing.T) { defer r1.Close() require.True(t, created) - out1, err := ioutil.ReadAll(r1) + out1, err := io.ReadAll(r1) require.NoError(t, err) require.Equal(t, content(1), string(out1)) require.NoError(t, r1.Wait(context.Background())) @@ -292,7 +291,7 @@ func TestCache_diskCleanup(t *testing.T) { defer r2.Close() require.True(t, created) - out2, err := ioutil.ReadAll(r2) + out2, err := io.ReadAll(r2) require.NoError(t, err) require.NoError(t, r2.Wait(context.Background())) @@ -339,7 +338,7 @@ func TestCache_failedWrite(t *testing.T) { defer r2.Close() require.True(t, created, "because the previous entry failed, a new one should have been created") - out, err := ioutil.ReadAll(r2) + out, err := io.ReadAll(r2) require.NoError(t, err) require.NoError(t, r2.Wait(context.Background())) require.Equal(t, happy, string(out)) @@ -377,7 +376,7 @@ func TestCache_unWriteableFile(t *testing.T) { require.NoError(t, err) require.True(t, created) - _, err = ioutil.ReadAll(r) + _, err = io.ReadAll(r) require.NoError(t, err) err = r.Wait(context.Background()) @@ -403,7 +402,7 @@ func TestCache_unCloseableFile(t *testing.T) { require.NoError(t, err) require.True(t, created) - _, err = ioutil.ReadAll(r) + _, err = io.ReadAll(r) require.NoError(t, err) err = r.Wait(context.Background()) @@ -494,7 +493,7 @@ func TestNullCache(t *testing.T) { return errors.New("created should be true") } - output, err := ioutil.ReadAll(s) + output, err := io.ReadAll(s) if err != nil { return err } diff --git a/internal/streamcache/pipe_test.go b/internal/streamcache/pipe_test.go index 87372cfc9..0f28a17b3 100644 --- a/internal/streamcache/pipe_test.go +++ b/internal/streamcache/pipe_test.go @@ -98,7 +98,7 @@ func TestPipe_readAfterClose(t *testing.T) { werr := make(chan error, 1) go func() { werr <- writeBytes(p, []byte(input), nil) }() - out1, err := ioutil.ReadAll(pr1) + out1, err := io.ReadAll(pr1) require.NoError(t, err) require.Equal(t, input, string(out1)) @@ -109,7 +109,7 @@ func TestPipe_readAfterClose(t *testing.T) { require.NoError(t, err) defer pr2.Close() - out2, err := ioutil.ReadAll(pr2) + out2, err := io.ReadAll(pr2) require.NoError(t, err) require.Equal(t, input, string(out2)) } @@ -140,7 +140,7 @@ func TestPipe_backpressure(t *testing.T) { time.Sleep(10 * time.Millisecond) require.Equal(t, int64(3), atomic.LoadInt64(&wprogress), "writer should be blocked after having advanced 1 byte") - rest, err := ioutil.ReadAll(pr) + rest, err := io.ReadAll(pr) require.NoError(t, err) output = append(output, rest...) require.Equal(t, input, string(output)) @@ -251,7 +251,7 @@ func TestPipe_closeOrderHappy(t *testing.T) { require.NoError(t, p.Close()) require.True(t, cs.closed) - out1, err := ioutil.ReadAll(pr1) + out1, err := io.ReadAll(pr1) require.NoError(t, err) require.Empty(t, out1) @@ -259,7 +259,7 @@ func TestPipe_closeOrderHappy(t *testing.T) { require.NoError(t, err, "opening reader after normal close should succeed") defer pr2.Close() - out2, err := ioutil.ReadAll(pr2) + out2, err := io.ReadAll(pr2) require.NoError(t, err) require.Empty(t, out2) } diff --git a/internal/streamcache/sendfile_test.go b/internal/streamcache/sendfile_test.go index 786c085b4..31df56df0 100644 --- a/internal/streamcache/sendfile_test.go +++ b/internal/streamcache/sendfile_test.go @@ -128,7 +128,7 @@ func TestPipe_WriteTo_EAGAIN(t *testing.T) { }() }() - out, err := ioutil.ReadAll(fr) + out, err := io.ReadAll(fr) require.NoError(t, err) // Don't use require.Equal because we don't want a 10MB error message. require.True(t, bytes.Equal(data, out)) diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go index d5e071d0c..eb01d4c69 100644 --- a/internal/supervisor/supervisor_test.go +++ b/internal/supervisor/supervisor_test.go @@ -2,6 +2,7 @@ package supervisor import ( "context" + "io" "io/ioutil" "net" "os" @@ -188,7 +189,7 @@ func getPid(ctx context.Context, socket string) (int, error) { } defer conn.Close() - response, err := ioutil.ReadAll(conn) + response, err := io.ReadAll(conn) if err != nil { return 0, err } diff --git a/proto/go/internal/cmd/protoc-gen-gitaly/main.go b/proto/go/internal/cmd/protoc-gen-gitaly/main.go index 40499a1fa..a364b68ee 100644 --- a/proto/go/internal/cmd/protoc-gen-gitaly/main.go +++ b/proto/go/internal/cmd/protoc-gen-gitaly/main.go @@ -73,7 +73,7 @@ const ( ) func main() { - data, err := ioutil.ReadAll(os.Stdin) + data, err := io.ReadAll(os.Stdin) if err != nil { log.Fatalf("reading input: %s", err) } diff --git a/streamio/stream_test.go b/streamio/stream_test.go index 2e879ab55..c91d5a58f 100644 --- a/streamio/stream_test.go +++ b/streamio/stream_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "strings" "sync" "testing" @@ -26,7 +25,7 @@ func TestReceiveSources(t *testing.T) { } for _, tc := range testCases { - data, err := ioutil.ReadAll(&opaqueReader{NewReader(receiverFromReader(tc.r))}) + data, err := io.ReadAll(&opaqueReader{NewReader(receiverFromReader(tc.r))}) require.NoError(t, err, tc.desc) require.Equal(t, testData, string(data), tc.desc) } |