Skip to content

Commit

Permalink
replace more deprecated io/ioutil calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pvormste committed Apr 17, 2023
1 parent 824136c commit 2de9f41
Show file tree
Hide file tree
Showing 39 changed files with 103 additions and 109 deletions.
3 changes: 1 addition & 2 deletions examples/chat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chat

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -63,7 +62,7 @@ func LoadSchemaFromExamplesDirectoryWithinPkg() ([]byte, error) {
}

absolutePath := filepath.Join(strings.Split(wd, "pkg")[0], chatExampleDirectoryRelativePath, "schema.graphql")
return ioutil.ReadFile(absolutePath)
return os.ReadFile(absolutePath)
}

func GraphQLRequestForOperation(operation string) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions examples/federation/gateway/datasource_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -196,7 +196,7 @@ func (d *DatasourcePollerPoller) fetchServiceSDL(ctx context.Context, serviceURL
Errors GQLErr `json:"errors,omitempty"`
}

bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("read bytes: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/kafka_pubsub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -102,7 +102,7 @@ func main() {

// Parse command line parameters
f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)
f.BoolVar(&args.help, "h", false, "")
f.BoolVar(&args.help, "help", false, "")
f.StringVar(&args.products, "p", "", "")
Expand Down
4 changes: 2 additions & 2 deletions examples/kafka_pubsub/transactional_producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -57,7 +57,7 @@ func main() {

// Parse command line parameters
f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)
f.BoolVar(&args.help, "h", false, "")
f.BoolVar(&args.help, "help", false, "")
f.BoolVar(&args.enableTransaction, "enable-transaction", false, "")
Expand Down
10 changes: 5 additions & 5 deletions pkg/astparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astparser

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/TykTechnologies/graphql-go-tools/pkg/ast"
Expand Down Expand Up @@ -2268,7 +2268,7 @@ func TestErrorReport(t *testing.T) {

func TestParseStarwars(t *testing.T) {

starWarsSchema, err := ioutil.ReadFile("./testdata/starwars.schema.graphql")
starWarsSchema, err := os.ReadFile("./testdata/starwars.schema.graphql")
if err != nil {
t.Fatal(err)
}
Expand All @@ -2282,7 +2282,7 @@ func TestParseStarwars(t *testing.T) {
func TestParseTodo(t *testing.T) {

inputFileName := "./testdata/todo.graphql"
schema, err := ioutil.ReadFile(inputFileName)
schema, err := os.ReadFile(inputFileName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -2298,7 +2298,7 @@ func TestParseTodo(t *testing.T) {
func BenchmarkParseStarwars(b *testing.B) {

inputFileName := "./testdata/starwars.schema.graphql"
starwarsSchema, err := ioutil.ReadFile(inputFileName)
starwarsSchema, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand All @@ -2325,7 +2325,7 @@ func BenchmarkParseStarwars(b *testing.B) {
func BenchmarkParseGithub(b *testing.B) {

inputFileName := "./testdata/github.schema.graphql"
schemaFile, err := ioutil.ReadFile(inputFileName)
schemaFile, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/astprinter/astprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astprinter

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestPrintSchemaDefinition(t *testing.T) {

goldie.Assert(t, "starwars_schema_definition", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/starwars_schema_definition.golden")
fixture, err := os.ReadFile("./fixtures/starwars_schema_definition.golden")
if err != nil {
t.Fatal(err)
}
Expand All @@ -545,7 +545,7 @@ func TestPrintOperationDefinition(t *testing.T) {

goldie.Assert(t, "introspectionquery", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/introspectionquery.golden")
fixture, err := os.ReadFile("./fixtures/introspectionquery.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/asttransform/baseschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package asttransform

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand All @@ -27,7 +27,7 @@ func runTestMerge(definition, fixtureName string) func(t *testing.T) {
got := buf.Bytes()
goldie.Assert(t, fixtureName, got)
if t.Failed() {
want, err := ioutil.ReadFile("./fixtures/" + fixtureName + ".golden")
want, err := os.ReadFile("./fixtures/" + fixtureName + ".golden")
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/astvalidation/reference/testsgo/harness_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsgo

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -236,6 +236,7 @@ func ExpectValidationErrorMessage(t *testing.T, schema string, queryStr string)
}

// ExtendSchema - helper to extend schema with provided sdl
//
//nolint:unused
func ExtendSchema(schema string, sdlStr string) string {
if sdlStr != "" {
Expand Down Expand Up @@ -313,7 +314,7 @@ func hasReportError(t *testing.T, report operationreport.Report) MessageCompare
var testSchema string

func init() {
content, err := ioutil.ReadFile("test_schema.graphql")
content, err := os.ReadFile("test_schema.graphql")
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/astvisitor/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestVisitOperation(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor.golden")
fixture, err := os.ReadFile("./fixtures/visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestVisitSchemaDefinition(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/schema_visitor.golden")
fixture, err := os.ReadFile("./fixtures/schema_visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestWalker_Path(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/path.golden")
fixture, err := os.ReadFile("./fixtures/path.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestVisitWithSkip(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor_skip.golden")
fixture, err := os.ReadFile("./fixtures/visitor_skip.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/codegen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codegen

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/sebdah/goldie"
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCodeGen_GenerateDirectiveDefinitionStruct(t *testing.T) {
goldie.Assert(t, "DataSource", data)
if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/DataSource.golden")
fixture, err := os.ReadFile("./fixtures/DataSource.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/datasource/rest_datasource/rest_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest_datasource
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func TestHttpJsonDataSource_Load(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
actualBody, err := ioutil.ReadAll(r.Body)
actualBody, err := io.ReadAll(r.Body)
assert.NoError(t, err)
assert.Equal(t, string(actualBody), body)
_, _ = w.Write([]byte(`ok`))
Expand Down
3 changes: 1 addition & 2 deletions pkg/execution/datasource/datasource_http_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"

Expand Down Expand Up @@ -336,7 +335,7 @@ func (r *HttpJsonDataSource) Resolve(ctx context.Context, args ResolverArgs, out
return
}

data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
r.Log.Error("HttpJsonDataSource.Resolve.ioutil.ReadAll",
log.Error(err),
Expand Down
5 changes: 2 additions & 3 deletions pkg/execution/datasource/datasource_http_polling_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -172,9 +171,9 @@ func (h *HttpPollingStreamDataSource) startPolling(ctx context.Context) {
)
return
}
data, err = ioutil.ReadAll(response.Body)
data, err = io.ReadAll(response.Body)
if err != nil {
h.Log.Error("HttpPollingStreamDataSource.startPolling.ioutil.ReadAll",
h.Log.Error("HttpPollingStreamDataSource.startPolling.io.ReadAll",
log.Error(err),
)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource/datasource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"os"

log "github.com/jensneuse/abstractlogger"
"github.com/jensneuse/pipeline/pkg/pipe"
Expand Down Expand Up @@ -112,7 +112,7 @@ func (h *PipelineDataSourcePlanner) LeaveField(ref int) {
}
if h.dataSourceConfig.ConfigFilePath != nil {
var err error
h.rawPipelineConfig, err = ioutil.ReadFile(*h.dataSourceConfig.ConfigFilePath)
h.rawPipelineConfig, err = os.ReadFile(*h.dataSourceConfig.ConfigFilePath)
if err != nil {
h.Log.Error("PipelineDataSourcePlanner.readConfigFile", log.Error(err))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource_graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -239,7 +239,7 @@ func upstreamGraphqlServer(t *testing.T, assertRequestBody bool, expectedRequest
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.NotNil(t, r.Body)

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
require.NoError(t, err)

if assertRequestBody {
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource_http_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -844,7 +844,7 @@ func upstreamHttpJsonServer(t *testing.T, assertRequestBody bool, expectedReques
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.NotNil(t, r.Body)

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
require.NoError(t, err)

if assertRequestBody {
Expand Down
Loading

0 comments on commit 2de9f41

Please sign in to comment.