Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of deprecated io/ioutil package #1521

Merged
merged 1 commit into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_test.yml
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Lint and Test - ${{ matrix.go-version }}
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.x]
go-version: [1.18.x, 1.19.x, 1.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions commits_test.go
Expand Up @@ -19,7 +19,7 @@ package gitlab
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"testing"
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestSetCommitStatus(t *testing.T) {

mux.HandleFunc("/api/v4/projects/1/statuses/b0b3a907f41409829b307a28b82fdbd552ee5a27", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)

var content SetCommitStatusOptions
Expand Down
3 changes: 1 addition & 2 deletions gitlab.go
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -885,7 +884,7 @@ func CheckResponse(r *http.Response) error {
}

errorResponse := &ErrorResponse{Response: r}
data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err == nil && data != nil {
errorResponse.Body = data

Expand Down
5 changes: 2 additions & 3 deletions gitlab_test.go
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -135,7 +134,7 @@ func TestCheckResponse(t *testing.T) {
resp := &http.Response{
Request: req.Request,
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(strings.NewReader(`
Body: io.NopCloser(strings.NewReader(`
{
"message": {
"prop1": [
Expand Down Expand Up @@ -192,7 +191,7 @@ func TestRequestWithContext(t *testing.T) {
}

func loadFixture(filePath string) []byte {
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions group_import_export_test.go
Expand Up @@ -2,7 +2,7 @@ package gitlab

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestGroupExportDownload(t *testing.T) {
t.Errorf("GroupImportExport.ExportDownload returned error: %v", err)
}

data, err := ioutil.ReadAll(export)
data, err := io.ReadAll(export)
if err != nil {
t.Errorf("Error reading export: %v", err)
}
Expand All @@ -58,7 +58,7 @@ func TestGroupImport(t *testing.T) {
defer teardown(server)

content := []byte("temporary file's content")
tmpfile, err := ioutil.TempFile("", "example.*.tar.gz")
tmpfile, err := os.CreateTemp(os.TempDir(), "example.*.tar.gz")
if err != nil {
tmpfile.Close()
log.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions jobs_test.go
Expand Up @@ -18,7 +18,7 @@ package gitlab

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"testing"
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestDownloadSingleArtifactsFileByTagOrBranch(t *testing.T) {
t.Fatalf("Jobs.DownloadSingleArtifactsFileByTagOrBranch returns an error: %v", err)
}

content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
if err != nil {
t.Fatalf("Jobs.DownloadSingleArtifactsFileByTagOrBranch error reading: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions projects_test.go
Expand Up @@ -19,7 +19,6 @@ package gitlab
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"reflect"
Expand Down Expand Up @@ -452,7 +451,7 @@ func TestUploadFile_Retry(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)

tf, _ := ioutil.TempFile(os.TempDir(), "test")
tf, _ := os.CreateTemp(os.TempDir(), "test")
defer os.Remove(tf.Name())

isFirstRequest := true
Expand Down
18 changes: 9 additions & 9 deletions releases_test.go
Expand Up @@ -18,7 +18,7 @@ package gitlab

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestReleasesService_CreateRelease(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestReleasesService_CreateReleaseWithAsset(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestReleasesService_CreateReleaseWithAssetAndNameMetadata(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestReleasesService_CreateReleaseWithMilestones(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestReleasesService_CreateReleaseWithReleasedAt(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestReleasesService_UpdateRelease(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestReleasesService_UpdateReleaseWithMilestones(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestReleasesService_UpdateReleaseWithReleasedAt(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("unable to read request body")
}
Expand Down