Skip to content

Commit

Permalink
Merge pull request #496 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
camathieu authored Sep 1, 2023
2 parents ad7212f + e456fd2 commit 58de560
Show file tree
Hide file tree
Showing 41 changed files with 151 additions and 163 deletions.
3 changes: 1 addition & 2 deletions client/plik.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"runtime"
Expand Down Expand Up @@ -239,7 +238,7 @@ Options:
fmt.Fprintf(os.Stderr, "Unable to encrypt file :%s", err)
os.Exit(1)
}
return ioutil.NopCloser(reader)
return io.NopCloser(reader)
})
}

Expand Down
3 changes: 1 addition & 2 deletions client/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (p *Progress) register(file *plik.File) {
p.mu.Unlock()

file.WrapReader(func(fileReader io.ReadCloser) io.ReadCloser {
return ioutil.NopCloser(io.TeeReader(fileReader, bar))
return io.NopCloser(io.TeeReader(fileReader, bar))
})

file.RegisterUploadCallback(func(metadata *common.File, err error) {
Expand Down
3 changes: 1 addition & 2 deletions client/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -143,7 +142,7 @@ func update(client *plik.Client, updateFlag bool) (err error) {
}

var body []byte
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("Unable to get release notes for version %s : %s", release.Name, err)
}
Expand Down
5 changes: 2 additions & 3 deletions plik/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"runtime"

Expand Down Expand Up @@ -102,7 +101,7 @@ func (c *Client) GetServerVersion() (bi *common.BuildInfo, err error) {
}

defer func() { _ = resp.Body.Close() }()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -131,7 +130,7 @@ func (c *Client) GetServerConfig() (config *common.Configuration, err error) {
}

defer func() { _ = resp.Body.Close() }()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
28 changes: 14 additions & 14 deletions plik/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package plik
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -160,13 +160,13 @@ func TestUploadReader(t *testing.T) {
require.NoError(t, err, "unable to start plik server")

data := "data data data"
upload, file, err := pc.UploadReader("filename", ioutil.NopCloser(bytes.NewBufferString(data)))
upload, file, err := pc.UploadReader("filename", io.NopCloser(bytes.NewBufferString(data)))
require.NoError(t, err, "unable to upload file")
require.Len(t, upload.Metadata().Files, 0, "invalid file count")

reader, err := pc.downloadFile(upload.getParams(), file.getParams())
require.NoError(t, err, "unable to download file")
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read file")
require.Equal(t, data, string(content), "invalid file content")
}
Expand All @@ -179,13 +179,13 @@ func TestUploadReadCloser(t *testing.T) {
require.NoError(t, err, "unable to start plik server")

data := "data data data"
upload, file, err := pc.UploadReader("filename", ioutil.NopCloser(bytes.NewBufferString(data)))
upload, file, err := pc.UploadReader("filename", io.NopCloser(bytes.NewBufferString(data)))
require.NoError(t, err, "unable to upload file")
require.Len(t, upload.Metadata().Files, 0, "invalid file count")

reader, err := pc.downloadFile(upload.getParams(), file.getParams())
require.NoError(t, err, "unable to download file")
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read file")
require.Equal(t, data, string(content), "invalid file content")
}
Expand All @@ -197,7 +197,7 @@ func TestUploadFiles(t *testing.T) {
err := start(ps)
require.NoError(t, err, "unable to start plik server")

tmpFile, err := ioutil.TempFile("", "pliktmpfile")
tmpFile, err := os.CreateTemp("", "pliktmpfile")
require.NoError(t, err, "unable to create tmp file")
defer os.Remove(tmpFile.Name())

Expand All @@ -207,7 +207,7 @@ func TestUploadFiles(t *testing.T) {
err = tmpFile.Close()
require.NoError(t, err, "unable to close tmp file")

tmpFile2, err := ioutil.TempFile("", "pliktmpfile")
tmpFile2, err := os.CreateTemp("", "pliktmpfile")
require.NoError(t, err, "unable to create tmp file")
defer os.Remove(tmpFile.Name())

Expand All @@ -231,7 +231,7 @@ func TestUploadFiles(t *testing.T) {
for _, file := range upload.Metadata().Files {
reader, err := pc.downloadFile(upload.Metadata(), file)
require.NoError(t, err, "unable to download file")
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read file")
require.Equal(t, data, string(content), "invalid file content")
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestUploadMultipleFiles(t *testing.T) {

reader, err := pc.downloadFile(upload.Metadata(), file.Metadata())
require.NoError(t, err, "unable to download file")
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read file")
require.Equal(t, fmt.Sprintf("data data data %s", file.Name), string(content), "invalid file content")
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestCreateAndGetUploadFiles(t *testing.T) {

reader, err := file.Download()
require.NoError(t, err, "unable to download file")
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read file")
require.Equal(t, fmt.Sprintf("data data data %s", file.Name), string(content), "invalid file content")
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestRemoveFile(t *testing.T) {
require.NoError(t, err, "unable to start plik server")

data := "data data data"
upload, file, err := pc.UploadReader("filename", ioutil.NopCloser(bytes.NewBufferString(data)))
upload, file, err := pc.UploadReader("filename", io.NopCloser(bytes.NewBufferString(data)))
require.NoError(t, err, "unable to upload file")
require.Len(t, upload.Metadata().Files, 0, "invalid file count")

Expand Down Expand Up @@ -380,7 +380,7 @@ func TestDeleteUpload(t *testing.T) {
require.NoError(t, err, "unable to start plik server")

data := "data data data"
upload, file, err := pc.UploadReader("filename", ioutil.NopCloser(bytes.NewBufferString(data)))
upload, file, err := pc.UploadReader("filename", io.NopCloser(bytes.NewBufferString(data)))
require.NoError(t, err, "unable to upload file")
require.Len(t, upload.Metadata().Files, 0, "invalid file count")

Expand Down Expand Up @@ -436,15 +436,15 @@ func TestDownloadArchive(t *testing.T) {
require.NoError(t, err, "unable to start plik server")

data := "data data data"
upload, _, err := pc.UploadReader("filename", ioutil.NopCloser(bytes.NewBufferString(data)))
upload, _, err := pc.UploadReader("filename", io.NopCloser(bytes.NewBufferString(data)))
require.NoError(t, err, "unable to upload file")
require.Len(t, upload.Metadata().Files, 0, "invalid file count")

reader, err := upload.DownloadZipArchive()
require.NoError(t, err, "unable to download archive")

defer reader.Close()
content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read archive")

require.NotEmpty(t, content, "empty archive")
Expand Down
3 changes: 1 addition & 2 deletions plik/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plik
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -40,7 +39,7 @@ func newFileFromReadCloser(upload *Upload, name string, reader io.ReadCloser) *F

// NewFileFromReader creates a File from a filename and an io.Reader
func newFileFromReader(upload *Upload, name string, reader io.Reader) *File {
return newFileFromReadCloser(upload, name, ioutil.NopCloser(reader))
return newFileFromReadCloser(upload, name, io.NopCloser(reader))
}

// NewFileFromPath creates a File from a filesystem path
Expand Down
4 changes: 2 additions & 2 deletions plik/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package plik

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -33,7 +33,7 @@ func TestGetFileURL(t *testing.T) {
require.NoError(t, err, "unable to execute request")
require.Equal(t, http.StatusOK, resp.StatusCode, "invalid response status code")

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "unable to read response body")

require.Equal(t, data, string(body), "invalid file content")
Expand Down
9 changes: 4 additions & 5 deletions plik/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -43,7 +42,7 @@ func (c *Client) create(uploadParams *common.Upload) (uploadMetadata *common.Upl
}

defer func() { _ = resp.Body.Close() }()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -137,7 +136,7 @@ func (c *Client) uploadFile(upload *common.Upload, fileParams *common.File, read
}

defer func() { _ = resp.Body.Close() }()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -195,7 +194,7 @@ func (c *Client) getUploadWithParams(uploadParams *common.Upload) (upload *Uploa
}

defer func() { _ = resp.Body.Close() }()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -347,7 +346,7 @@ func parseErrorResponse(resp *http.Response) (err error) {
// Reade response body

var body []byte
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions plik/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package plik

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"os"
"testing"
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestMakeRequestDebug(t *testing.T) {
err = writer.Close()
require.NoError(t, err, "unable to close writer")

printed, err := ioutil.ReadAll(reader)
printed, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read output")

require.Contains(t, string(printed), "X-Clientapp", "invalid output")
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestMakeRequestDebugFile(t *testing.T) {
err = writer.Close()
require.NoError(t, err, "unable to close writer")

printed, err := ioutil.ReadAll(reader)
printed, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read output")
require.Contains(t, string(printed), "X-Clientapp", "invalid output")
require.Contains(t, string(printed), "X-Clientversion", "invalid output")
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestMakeRequestDebugStream(t *testing.T) {
err = writer.Close()
require.NoError(t, err, "unable to close writer")

printed, err := ioutil.ReadAll(reader)
printed, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read output")
require.Contains(t, string(printed), "X-Clientapp", "invalid output")
require.Contains(t, string(printed), "X-Clientversion", "invalid output")
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestMakeRequestDebugGetFile(t *testing.T) {
err = writer.Close()
require.NoError(t, err, "unable to close writer")

printed, err := ioutil.ReadAll(reader)
printed, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read output")
require.Contains(t, string(printed), "X-Clientapp", "invalid output")
require.Contains(t, string(printed), "X-Clientversion", "invalid output")
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestMakeRequestDebugGetArchive(t *testing.T) {
err = writer.Close()
require.NoError(t, err, "unable to close writer")

printed, err := ioutil.ReadAll(reader)
printed, err := io.ReadAll(reader)
require.NoError(t, err, "unable to read output")
require.Contains(t, string(printed), "X-Clientapp", "invalid output")
require.Contains(t, string(printed), "X-Clientversion", "invalid output")
Expand Down
3 changes: 1 addition & 2 deletions plik/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"testing"
Expand Down Expand Up @@ -71,7 +70,7 @@ func TestMain(m *testing.M) {
// Setup data backend
switch testConfig.DataBackend {
case "file":
dir, err := ioutil.TempDir("", "pliktest_file_")
dir, err := os.MkdirTemp("", "pliktest_file_")
if err != nil {
fmt.Printf("Unable to setup file data backend : %s\n", err)
os.Exit(1)
Expand Down
Loading

0 comments on commit 58de560

Please sign in to comment.