Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated ioutil pkg with os & io #228

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package formatter_test
import (
"bytes"
"flag"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -24,10 +23,10 @@ func TestFormatter_FormatSchema(t *testing.T) {

executeGoldenTesting(t, &goldenConfig{
SourceDir: testSourceDir,
BaselineFileName: func(cfg *goldenConfig, f os.FileInfo) string {
BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string {
return path.Join(testBaselineDir, f.Name())
},
Run: func(t *testing.T, cfg *goldenConfig, f os.FileInfo) []byte {
Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte {
// load stuff
schema, gqlErr := gqlparser.LoadSchema(&ast.Source{
Name: f.Name(),
Expand Down Expand Up @@ -62,10 +61,10 @@ func TestFormatter_FormatSchemaDocument(t *testing.T) {

executeGoldenTesting(t, &goldenConfig{
SourceDir: testSourceDir,
BaselineFileName: func(cfg *goldenConfig, f os.FileInfo) string {
BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string {
return path.Join(testBaselineDir, f.Name())
},
Run: func(t *testing.T, cfg *goldenConfig, f os.FileInfo) []byte {
Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte {
// load stuff
doc, gqlErr := parser.ParseSchema(&ast.Source{
Name: f.Name(),
Expand Down Expand Up @@ -100,10 +99,10 @@ func TestFormatter_FormatQueryDocument(t *testing.T) {

executeGoldenTesting(t, &goldenConfig{
SourceDir: testSourceDir,
BaselineFileName: func(cfg *goldenConfig, f os.FileInfo) string {
BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string {
return path.Join(testBaselineDir, f.Name())
},
Run: func(t *testing.T, cfg *goldenConfig, f os.FileInfo) []byte {
Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte {
// load stuff
doc, gqlErr := parser.ParseQuery(&ast.Source{
Name: f.Name(),
Expand Down Expand Up @@ -135,8 +134,8 @@ func TestFormatter_FormatQueryDocument(t *testing.T) {
type goldenConfig struct {
SourceDir string
IsTarget func(f os.FileInfo) bool
BaselineFileName func(cfg *goldenConfig, f os.FileInfo) string
Run func(t *testing.T, cfg *goldenConfig, f os.FileInfo) []byte
BaselineFileName func(cfg *goldenConfig, f os.DirEntry) string
Run func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte
}

func executeGoldenTesting(t *testing.T, cfg *goldenConfig) {
Expand All @@ -154,7 +153,7 @@ func executeGoldenTesting(t *testing.T, cfg *goldenConfig) {
t.Fatal("Run function is required")
}

fs, err := ioutil.ReadDir(cfg.SourceDir)
fs, err := os.ReadDir(cfg.SourceDir)
if err != nil {
t.Fatal(fs)
}
Expand All @@ -177,13 +176,13 @@ func executeGoldenTesting(t *testing.T, cfg *goldenConfig) {
}
}

expected, err := ioutil.ReadFile(expectedFilePath)
expected, err := os.ReadFile(expectedFilePath)
if os.IsNotExist(err) {
err = os.MkdirAll(path.Dir(expectedFilePath), 0755)
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(expectedFilePath, result, 0444)
err = os.WriteFile(expectedFilePath, result, 0444)
if err != nil {
t.Fatal(err)
}
Expand All @@ -205,7 +204,7 @@ func executeGoldenTesting(t *testing.T, cfg *goldenConfig) {
}

func mustReadFile(name string) string {
src, err := ioutil.ReadFile(name)
src, err := os.ReadFile(name)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions parser/testrunner/runner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testrunner

import (
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (t Token) String() string {
}

func Test(t *testing.T, filename string, f func(t *testing.T, input string) Spec) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions validator/imported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package validator_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -172,7 +171,7 @@ func compareErrors(errors gqlerror.List) func(i, j int) bool {
}

func readYaml(filename string, result interface{}) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions validator/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package validator

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

"github.com/stretchr/testify/require"
Expand All @@ -20,7 +20,7 @@ func TestLoadSchema(t *testing.T) {
require.Equal(t, "The `Boolean` scalar type represents `true` or `false`.", boolDef.Description)
})
t.Run("swapi", func(t *testing.T) {
file, err := ioutil.ReadFile("testdata/swapi.graphql")
file, err := os.ReadFile("testdata/swapi.graphql")
require.Nil(t, err)
s, err := LoadSchema(Prelude, &ast.Source{Input: string(file), Name: "TestLoadSchema"})
require.Nil(t, err)
Expand All @@ -45,7 +45,7 @@ func TestLoadSchema(t *testing.T) {
})

t.Run("default root operation type names", func(t *testing.T) {
file, err := ioutil.ReadFile("testdata/default_root_operation_type_names.graphql")
file, err := os.ReadFile("testdata/default_root_operation_type_names.graphql")
require.Nil(t, err)
s, err := LoadSchema(Prelude, &ast.Source{Input: string(file), Name: "TestLoadSchema"})
require.Nil(t, err)
Expand All @@ -58,7 +58,7 @@ func TestLoadSchema(t *testing.T) {
})

t.Run("type extensions", func(t *testing.T) {
file, err := ioutil.ReadFile("testdata/extensions.graphql")
file, err := os.ReadFile("testdata/extensions.graphql")
require.Nil(t, err)
s, err := LoadSchema(Prelude, &ast.Source{Input: string(file), Name: "TestLoadSchema"})
require.Nil(t, err)
Expand All @@ -81,7 +81,7 @@ func TestLoadSchema(t *testing.T) {
})

t.Run("interfaces", func(t *testing.T) {
file, err := ioutil.ReadFile("testdata/interfaces.graphql")
file, err := os.ReadFile("testdata/interfaces.graphql")
require.Nil(t, err)
s, err := LoadSchema(Prelude, &ast.Source{Input: string(file), Name: "interfaces"})
require.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions validator/vars_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package validator_test

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

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestValidateVars(t *testing.T) {
}

func mustReadFile(name string) string {
src, err := ioutil.ReadFile(name)
src, err := os.ReadFile(name)
if err != nil {
panic(err)
}
Expand Down