Skip to content

Commit

Permalink
ioutil deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
kfcampbell authored and wlynch committed May 29, 2024
1 parent a2841b0 commit 48c7bda
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions appsTransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/rsa"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
"time"

Expand All @@ -30,7 +30,7 @@ type AppsTransport struct {

// NewAppsTransportKeyFromFile returns a AppsTransport using a private key from file.
func NewAppsTransportKeyFromFile(tr http.RoundTripper, appID int64, privateKeyFile string) (*AppsTransport, error) {
privateKey, err := ioutil.ReadFile(privateKeyFile)
privateKey, err := os.ReadFile(privateKeyFile)
if err != nil {
return nil, fmt.Errorf("could not read private key: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions appsTransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ghinstallation
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -15,7 +14,7 @@ import (
)

func TestNewAppsTransportKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ http.RoundTripper = &Transport{}

// NewKeyFromFile returns a Transport using a private key from file.
func NewKeyFromFile(tr http.RoundTripper, appID, installationID int64, privateKeyFile string) (*Transport, error) {
privateKey, err := ioutil.ReadFile(privateKeyFile)
privateKey, err := os.ReadFile(privateKeyFile)
if err != nil {
return nil, fmt.Errorf("could not read private key: %s", err)
}
Expand Down
20 changes: 10 additions & 10 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestNew(t *testing.T) {
}

func TestNewKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -226,8 +226,8 @@ func TestRefreshTokenWithParameters(t *testing.T) {
rt: func(req *http.Request) (*http.Response, error) {
// Convert io.ReadCloser to String without deleting body data.
var gotBodyBytes []byte
gotBodyBytes, _ = ioutil.ReadAll(req.Body)
req.Body = ioutil.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyBytes, _ = io.ReadAll(req.Body)
req.Body = io.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyString := string(gotBodyBytes)

// Compare request sent with request received.
Expand All @@ -251,7 +251,7 @@ func TestRefreshTokenWithParameters(t *testing.T) {
if err != nil {
return nil, fmt.Errorf("error converting token into io.ReadWriter: %+v", err)
}
tokenBody := ioutil.NopCloser(tokenReadWriter)
tokenBody := io.NopCloser(tokenReadWriter)
return &http.Response{
Body: tokenBody,
StatusCode: 200,
Expand Down Expand Up @@ -295,22 +295,22 @@ func TestRefreshTokenWithTrailingSlashBaseURL(t *testing.T) {
rt: func(req *http.Request) (*http.Response, error) {
if strings.Contains(req.URL.Path, "//") {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader("Forbidden\n")),
Body: io.NopCloser(strings.NewReader("Forbidden\n")),
StatusCode: 401,
}, fmt.Errorf("Got simulated 401 Github Forbidden response")
}

if req.URL.Path == "test_endpoint/" && req.Header.Get("Authorization") == fmt.Sprintf("token %s", tokenToBe) {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader("Beautiful\n")),
Body: io.NopCloser(strings.NewReader("Beautiful\n")),
StatusCode: 200,
}, nil
}

// Convert io.ReadCloser to String without deleting body data.
var gotBodyBytes []byte
gotBodyBytes, _ = ioutil.ReadAll(req.Body)
req.Body = ioutil.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyBytes, _ = io.ReadAll(req.Body)
req.Body = io.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyString := string(gotBodyBytes)

// Compare request sent with request received.
Expand All @@ -334,7 +334,7 @@ func TestRefreshTokenWithTrailingSlashBaseURL(t *testing.T) {
if err != nil {
return nil, fmt.Errorf("error converting token into io.ReadWriter: %+v", err)
}
tokenBody := ioutil.NopCloser(tokenReadWriter)
tokenBody := io.NopCloser(tokenReadWriter)
return &http.Response{
Body: tokenBody,
StatusCode: 200,
Expand Down

0 comments on commit 48c7bda

Please sign in to comment.