diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-20 15:11:54 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-20 17:22:33 +0300 |
commit | af5cd856461519c3f6c1d508eabb40aced2ff384 (patch) | |
tree | 11754fa3b0691a68c3b99c2d302e3a4f6d9536c2 /internal/streamcache | |
parent | 4267fbceffbc57def115a294d6ace2c71de76a93 (diff) |
global: Replace deprecated usage of `ioutil.TempFile()`
With Go 1.16, the ioutil package was deprecated. Replace our usage of
`ioutil.TempFile()` with `os.CreateTemp()` to adapt accordingly.
Diffstat (limited to 'internal/streamcache')
-rw-r--r-- | internal/streamcache/filestore.go | 2 | ||||
-rw-r--r-- | internal/streamcache/pipe_test.go | 8 | ||||
-rw-r--r-- | internal/streamcache/sendfile_test.go | 5 |
3 files changed, 7 insertions, 8 deletions
diff --git a/internal/streamcache/filestore.go b/internal/streamcache/filestore.go index 4fc6a5100..67337c95f 100644 --- a/internal/streamcache/filestore.go +++ b/internal/streamcache/filestore.go @@ -83,7 +83,7 @@ type namedWriteCloser interface { io.WriteCloser } -// Create creates a new tempfile. It does not use ioutil.TempFile because +// Create creates a new tempfile. It does not use os.CreateTemp because // the documentation of TempFile makes no promises about reusing tempfile // names after a file has been deleted. By using a very large (uint64) // counter, Create makes it clear / explicit how unlikely reuse is. diff --git a/internal/streamcache/pipe_test.go b/internal/streamcache/pipe_test.go index 0f28a17b3..17c73f9fb 100644 --- a/internal/streamcache/pipe_test.go +++ b/internal/streamcache/pipe_test.go @@ -3,8 +3,8 @@ package streamcache import ( "bytes" "io" - "io/ioutil" "math/rand" + "os" "sync" "sync/atomic" "testing" @@ -16,7 +16,7 @@ import ( func createPipe(t *testing.T) (*pipeReader, *pipe) { t.Helper() - f, err := ioutil.TempFile("", "gitaly-streamcache-test") + f, err := os.CreateTemp("", "gitaly-streamcache-test") require.NoError(t, err) pr, p, err := newPipe(f) @@ -200,7 +200,7 @@ func (cs *closeSpy) Close() error { // Closing the last reader _before_ closing the writer is a failure // condition. After this happens, opening new readers should fail. func TestPipe_closeWrongOrder(t *testing.T) { - f, err := ioutil.TempFile("", "gitaly-streamcache-test") + f, err := os.CreateTemp("", "gitaly-streamcache-test") require.NoError(t, err) cs := &closeSpy{namedWriteCloser: f} @@ -233,7 +233,7 @@ func TestPipe_closeWrongOrder(t *testing.T) { // Closing last reader after closing the writer is the happy path. After // this happens, opening new readers should work. func TestPipe_closeOrderHappy(t *testing.T) { - f, err := ioutil.TempFile("", "gitaly-streamcache-test") + f, err := os.CreateTemp("", "gitaly-streamcache-test") require.NoError(t, err) cs := &closeSpy{namedWriteCloser: f} diff --git a/internal/streamcache/sendfile_test.go b/internal/streamcache/sendfile_test.go index 9e7306ec5..b349c6331 100644 --- a/internal/streamcache/sendfile_test.go +++ b/internal/streamcache/sendfile_test.go @@ -6,7 +6,6 @@ package streamcache import ( "bytes" "io" - "io/ioutil" "math/rand" "os" "testing" @@ -34,7 +33,7 @@ func TestPipe_WriteTo(t *testing.T) { { desc: "os.File", create: func(t *testing.T) namedWriteCloser { - f, err := ioutil.TempFile("", "pipe write to") + f, err := os.CreateTemp("", "pipe write to") require.NoError(t, err) t.Cleanup(func() { require.NoError(t, os.Remove(f.Name())) }) return f @@ -44,7 +43,7 @@ func TestPipe_WriteTo(t *testing.T) { { desc: "non-file writer", create: func(t *testing.T) namedWriteCloser { - f, err := ioutil.TempFile("", "pipe write to") + f, err := os.CreateTemp("", "pipe write to") require.NoError(t, err) t.Cleanup(func() { require.NoError(t, os.Remove(f.Name())) }) return &wrappedFile{f} |