Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Apr 4, 2023
1 parent d4395d3 commit 19b089d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
5 changes: 2 additions & 3 deletions base64loader/base64loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// registering its Loaders.
//
// To use base64loader, link this package into your program:
// import _ "github.com/ory/jsonschema/v3/base64loader"
//
// import _ "github.com/ory/jsonschema/v3/base64loader"
package base64loader

import (
Expand All @@ -14,7 +14,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"strings"

"github.com/ory/jsonschema/v3"
Expand All @@ -31,7 +30,7 @@ func Load(ctx context.Context, url string) (_ io.ReadCloser, err error) {
return nil, fmt.Errorf("unable to decode std encoded base64 string: %s", err)
}

return ioutil.NopCloser(bytes.NewBuffer(raw)), nil
return io.NopCloser(bytes.NewBuffer(raw)), nil
}

func init() {
Expand Down
12 changes: 6 additions & 6 deletions httploader/httploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httploader
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -13,12 +13,12 @@ import (
"github.com/stretchr/testify/require"
)

var fooErr = errors.New("foo")
var errFoo = errors.New("foo")

type rt struct{}

func (r rt) RoundTrip(_ *http.Request) (*http.Response, error) {
return nil, fooErr
return nil, errFoo
}

var _ http.RoundTripper = new(rt)
Expand All @@ -34,7 +34,7 @@ func TestHTTPLoader(t *testing.T) {
res, err := Load(context.WithValue(context.Background(), ContextKey, retryablehttp.NewClient()), ts.URL)
require.NoError(t, err)
defer res.Close()
body, err := ioutil.ReadAll(res)
body, err := io.ReadAll(res)
require.NoError(t, err)
return string(body)
}
Expand All @@ -45,9 +45,9 @@ func TestHTTPLoader(t *testing.T) {
hc.RetryMax = 1
hc.HTTPClient.Transport = new(rt)
_, err := Load(context.WithValue(context.Background(), ContextKey, hc), ts.URL)
require.ErrorIs(t, err, fooErr)
require.ErrorIs(t, err, errFoo)

_, err = Load(context.WithValue(context.Background(), ContextKey, new(struct{})), ts.URL)
require.Error(t, err, fooErr)
require.Error(t, err, errFoo)
assert.Equal(t, "invalid context value for github.com/ory/jsonschema/v3/httploader.HTTPClient expected *retryablehttp.Client but got: *struct {}", err.Error())
}
25 changes: 11 additions & 14 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -22,10 +21,8 @@ import (

"github.com/hashicorp/go-retryablehttp"

"github.com/ory/jsonschema/v3/httploader"

"github.com/ory/jsonschema/v3"
_ "github.com/ory/jsonschema/v3/httploader"
"github.com/ory/jsonschema/v3/httploader"
)

var draft4, draft6, draft7 []byte
Expand All @@ -34,15 +31,15 @@ var ctx = context.WithValue(context.Background(), httploader.ContextKey, retryab

func init() {
var err error
draft4, err = ioutil.ReadFile("testdata/draft4.json")
draft4, err = os.ReadFile("testdata/draft4.json")
if err != nil {
panic(err)
}
draft6, err = ioutil.ReadFile("testdata/draft6.json")
draft6, err = os.ReadFile("testdata/draft6.json")
if err != nil {
panic(err)
}
draft7, err = ioutil.ReadFile("testdata/draft7.json")
draft7, err = os.ReadFile("testdata/draft7.json")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -74,7 +71,7 @@ func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) {
server := &http.Server{Addr: "localhost:1234", Handler: http.FileServer(http.Dir("testdata/remotes"))}
go func() {
if err := server.ListenAndServe(); err != http.ErrServerClosed {
t.Fatal(err)
t.Error(err)
}
}()
defer server.Close()
Expand All @@ -92,7 +89,7 @@ func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) {
}

t.Log(info.Name())
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Errorf(" FAIL: %v\n", err)
return nil
Expand Down Expand Up @@ -217,7 +214,7 @@ func TestInvalidSchema(t *testing.T) {
Schema json.RawMessage
Fragment string
}
data, err := ioutil.ReadFile("testdata/invalid_schemas.json")
data, err := os.ReadFile("testdata/invalid_schemas.json")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -307,7 +304,7 @@ func TestValidateInterface(t *testing.T) {
}
for _, file := range files {
t.Log(filepath.Base(file))
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Errorf(" FAIL: %v\n", err)
return
Expand Down Expand Up @@ -538,9 +535,9 @@ func TestCompiler_LoadURL(t *testing.T) {
c.LoadURL = func(ctx context.Context, s string) (io.ReadCloser, error) {
switch s {
case "base.json":
return ioutil.NopCloser(strings.NewReader(base)), nil
return io.NopCloser(strings.NewReader(base)), nil
case "schema.json":
return ioutil.NopCloser(strings.NewReader(schema)), nil
return io.NopCloser(strings.NewReader(schema)), nil
default:
return nil, errors.New("unsupported schema")
}
Expand All @@ -561,7 +558,7 @@ func TestSchemaReferencesDrafts(t *testing.T) {
c := jsonschema.NewCompiler()
file := "testdata/reference_draft.json"
t.Log(filepath.Base(file))
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Errorf(" FAIL: %v\n", err)
return
Expand Down

0 comments on commit 19b089d

Please sign in to comment.