fix: remove use of the deprecated io/ioutil lib

This commit is contained in:
Davide Bianchi
2022-11-17 09:29:43 +01:00
parent 047317ef17
commit e5f3c438b4
4 changed files with 11 additions and 13 deletions

View File

@@ -13,7 +13,6 @@ all: test
.PHONY: test
test:
go test ./... -coverprofile coverage.out
$(MAKE) clean
.PHONY: version
version:

View File

@@ -3,7 +3,6 @@ package swagger_test
import (
"context"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
@@ -171,7 +170,7 @@ func TestIntegration(t *testing.T) {
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := ioutil.ReadAll(requestBody)
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)

View File

@@ -4,9 +4,9 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
@@ -229,7 +229,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/users_employees.json")
actual, err := os.ReadFile("testdata/users_employees.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
@@ -257,7 +257,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/users_employees.json")
actual, err := os.ReadFile("testdata/users_employees.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
@@ -284,7 +284,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
expected, err := os.ReadFile("testdata/users_employees.yaml")
require.NoError(t, err)
require.YAMLEq(t, string(expected), body, string(body))
})
@@ -312,7 +312,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
expected, err := os.ReadFile("testdata/users_employees.yaml")
require.NoError(t, err)
require.YAMLEq(t, string(expected), body, string(body))
})
@@ -367,7 +367,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/subrouter.json")
actual, err := os.ReadFile("testdata/subrouter.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
@@ -403,7 +403,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/router_with_prefix.json")
actual, err := os.ReadFile("testdata/router_with_prefix.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
@@ -412,7 +412,7 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := ioutil.ReadAll(requestBody)
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)

View File

@@ -3,9 +3,9 @@ package swagger
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/davidebianchi/gswagger/apirouter"
@@ -477,7 +477,7 @@ func TestAddRoutes(t *testing.T) {
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile(test.fixturesPath)
expected, err := os.ReadFile(test.fixturesPath)
require.NoError(t, err)
require.JSONEq(t, string(expected), body, "actual json data: %s", body)
})