diff --git a/base64loader/base64loader.go b/base64loader/base64loader.go index 384ff16..ec7c7e2 100644 --- a/base64loader/base64loader.go +++ b/base64loader/base64loader.go @@ -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 ( @@ -14,7 +14,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "strings" "github.com/ory/jsonschema/v3" @@ -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() { diff --git a/httploader/httploader_test.go b/httploader/httploader_test.go index cb0037f..82e1c65 100644 --- a/httploader/httploader_test.go +++ b/httploader/httploader_test.go @@ -3,7 +3,7 @@ package httploader import ( "context" "errors" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -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) @@ -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) } @@ -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()) } diff --git a/schema_test.go b/schema_test.go index db6d679..df5e8be 100644 --- a/schema_test.go +++ b/schema_test.go @@ -10,7 +10,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -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 @@ -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) } @@ -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() @@ -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 @@ -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) } @@ -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 @@ -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") } @@ -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