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

update ioutils for os and updated github dependencies to v58 #111

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions appsTransport.go
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
Expand Up @@ -3,7 +3,6 @@
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -15,7 +14,7 @@
)

func TestNewAppsTransportKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.TempFile("", "example")

Check failure on line 17 in appsTransport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.TempFile
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
t.Fatal(err)
}
Expand All @@ -28,7 +27,7 @@
t.Fatal(err)
}

_, err = NewAppsTransportKeyFromFile(&http.Transport{}, appID, tmpfile.Name())

Check failure on line 30 in appsTransport_test.go

View workflow job for this annotation

GitHub Actions / Build

cannot assign error to err in multiple assignment
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -5,5 +5,5 @@ go 1.13
require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v57 v57.0.0
github.com/google/go-github/v58 v58.0.0
)
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -3,8 +3,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v57 v57.0.0 h1:L+Y3UPTY8ALM8x+TV0lg+IEBI+upibemtBD8Q9u7zHs=
github.com/google/go-github/v57 v57.0.0/go.mod h1:s0omdnye0hvK/ecLvpsGfJMiRt85PimQh4oygmLIxHw=
github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw=
github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 3 additions & 3 deletions transport.go
Expand Up @@ -7,13 +7,13 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"

"github.com/google/go-github/v57/github"
"github.com/google/go-github/v58/github"
)

const (
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
23 changes: 11 additions & 12 deletions transport_test.go
Expand Up @@ -5,7 +5,6 @@
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -15,7 +14,7 @@
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-github/v57/github"
"github.com/google/go-github/v58/github"
)

const (
Expand Down Expand Up @@ -129,7 +128,7 @@
}

func TestNewKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.TempFile("", "example")

Check failure on line 131 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.TempFile
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
t.Fatal(err)
}
Expand All @@ -142,7 +141,7 @@
t.Fatal(err)
}

_, err = NewKeyFromFile(&http.Transport{}, appID, installationID, tmpfile.Name())

Check failure on line 144 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

cannot assign error to err in multiple assignment
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand All @@ -168,7 +167,7 @@
if err != nil {
t.Fatal("unexpected error:", err)
}
tr.BaseURL = ts.URL
itr.BaseURL = ts.URL

Check failure on line 170 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: itr
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved

client := http.Client{Transport: tr}
_, err = client.Do(req)
Expand Down Expand Up @@ -226,8 +225,8 @@
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, _ = os.ReadAll(req.Body)

Check failure on line 228 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.ReadAll
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
req.Body = os.NopCloser(bytes.NewBuffer(gotBodyBytes))

Check failure on line 229 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.NopCloser
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
gotBodyString := string(gotBodyBytes)

// Compare request sent with request received.
Expand All @@ -251,7 +250,7 @@
if err != nil {
return nil, fmt.Errorf("error converting token into io.ReadWriter: %+v", err)
}
tokenBody := ioutil.NopCloser(tokenReadWriter)
tokenBody := os.NopCloser(tokenReadWriter)

Check failure on line 253 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.NopCloser
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
return &http.Response{
Body: tokenBody,
StatusCode: 200,
Expand Down Expand Up @@ -295,22 +294,22 @@
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: os.NopCloser(strings.NewReader("Forbidden\n")),

Check failure on line 297 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.NopCloser
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
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: os.NopCloser(strings.NewReader("Beautiful\n")),

Check failure on line 304 in transport_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.NopCloser
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, _ = os.ReadAll(req.Body)
adrien-barret marked this conversation as resolved.
Show resolved Hide resolved
req.Body = os.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyString := string(gotBodyBytes)

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