Skip to content

Commit 83e714f

Browse files
committed
migrate deprecated io/ioutil package to io and os packages
1 parent 2071a52 commit 83e714f

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

oapi_validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"net/http"
2323
"strings"
2424

@@ -41,7 +41,7 @@ const (
4141

4242
// Create validator middleware from a YAML file path
4343
func OapiValidatorFromYamlFile(path string) (echo.MiddlewareFunc, error) {
44-
data, err := ioutil.ReadFile(path)
44+
data, err := os.ReadFile(path)
4545
if err != nil {
4646
return nil, fmt.Errorf("error reading %s: %s", path, err)
4747
}

oapi_validate_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
_ "embed"
2020
"errors"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"net/url"
@@ -250,7 +250,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
250250
{
251251
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=50")
252252
assert.Equal(t, http.StatusBadRequest, rec.Code)
253-
body, err := ioutil.ReadAll(rec.Body)
253+
body, err := io.ReadAll(rec.Body)
254254
if assert.NoError(t, err) {
255255
assert.Contains(t, string(body), "parameter \\\"id2\\\"")
256256
assert.Contains(t, string(body), "value is required but missing")
@@ -264,7 +264,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
264264
{
265265
rec := doGet(t, e, "http://deepmap.ai/multiparamresource")
266266
assert.Equal(t, http.StatusBadRequest, rec.Code)
267-
body, err := ioutil.ReadAll(rec.Body)
267+
body, err := io.ReadAll(rec.Body)
268268
if assert.NoError(t, err) {
269269
assert.Contains(t, string(body), "parameter \\\"id\\\"")
270270
assert.Contains(t, string(body), "value is required but missing")
@@ -280,7 +280,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
280280
{
281281
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=500")
282282
assert.Equal(t, http.StatusBadRequest, rec.Code)
283-
body, err := ioutil.ReadAll(rec.Body)
283+
body, err := io.ReadAll(rec.Body)
284284
if assert.NoError(t, err) {
285285
assert.Contains(t, string(body), "parameter \\\"id\\\"")
286286
assert.Contains(t, string(body), "number must be at most 100")
@@ -296,7 +296,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
296296
{
297297
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=abc&id2=1")
298298
assert.Equal(t, http.StatusBadRequest, rec.Code)
299-
body, err := ioutil.ReadAll(rec.Body)
299+
body, err := io.ReadAll(rec.Body)
300300
if assert.NoError(t, err) {
301301
assert.Contains(t, string(body), "parameter \\\"id\\\"")
302302
assert.Contains(t, string(body), "parsing \\\"abc\\\": invalid syntax")
@@ -358,7 +358,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
358358
{
359359
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=50")
360360
assert.Equal(t, http.StatusTeapot, rec.Code)
361-
body, err := ioutil.ReadAll(rec.Body)
361+
body, err := io.ReadAll(rec.Body)
362362
if assert.NoError(t, err) {
363363
assert.Contains(t, string(body), "parameter \\\"id2\\\"")
364364
assert.Contains(t, string(body), "value is required but missing")
@@ -372,7 +372,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
372372
{
373373
rec := doGet(t, e, "http://deepmap.ai/multiparamresource")
374374
assert.Equal(t, http.StatusTeapot, rec.Code)
375-
body, err := ioutil.ReadAll(rec.Body)
375+
body, err := io.ReadAll(rec.Body)
376376
if assert.NoError(t, err) {
377377
assert.Contains(t, string(body), "parameter \\\"id\\\"")
378378
assert.Contains(t, string(body), "value is required but missing")
@@ -388,7 +388,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
388388
{
389389
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=500")
390390
assert.Equal(t, http.StatusTeapot, rec.Code)
391-
body, err := ioutil.ReadAll(rec.Body)
391+
body, err := io.ReadAll(rec.Body)
392392
if assert.NoError(t, err) {
393393
assert.Contains(t, string(body), "parameter \\\"id\\\"")
394394
assert.Contains(t, string(body), "number must be at most 100")
@@ -404,7 +404,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
404404
{
405405
rec := doGet(t, e, "http://deepmap.ai/multiparamresource?id=abc&id2=1")
406406
assert.Equal(t, http.StatusTeapot, rec.Code)
407-
body, err := ioutil.ReadAll(rec.Body)
407+
body, err := io.ReadAll(rec.Body)
408408
if assert.NoError(t, err) {
409409
assert.Contains(t, string(body), "parameter \\\"id\\\"")
410410
assert.Contains(t, string(body), "parsing \\\"abc\\\": invalid syntax")

0 commit comments

Comments
 (0)