Skip to content

Commit

Permalink
refactor: remove deprecated ioutil (#72)
Browse files Browse the repository at this point in the history
Since go 1.16, `ioutil` has been deprecated. Its use triggers warnings
when linting with `golangci-lint`.

Migrate from `ioutil` to `io` and `os`, as specified at:
https://go.dev/doc/go1.16#ioutil
  • Loading branch information
0xjac authored Aug 18, 2022
1 parent 176eeb1 commit 0abc883
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 65 deletions.
6 changes: 3 additions & 3 deletions example/author/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -30,11 +30,11 @@ func TestGenerate_Go_Example_Author(t *testing.T) {
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
"Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/complex_params/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -33,11 +33,11 @@ func TestGenerate_Go_Example_ComplexParams(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/composite/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -38,11 +38,11 @@ func TestGenerate_Go_Example_Composite(t *testing.T) {
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
"Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/custom_types/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -35,11 +35,11 @@ func TestGenerate_Go_Example_CustomTypes(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/device/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -29,11 +29,11 @@ func TestGenerate_Go_Example_Device(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/domain/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -29,11 +29,11 @@ func TestGenerate_Go_Example_Domain(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/enums/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -29,11 +29,11 @@ func TestGenerate_Go_Example_Enums(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/erp/order/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -35,14 +35,14 @@ func TestGenerate_Go_Example_Order(t *testing.T) {
}

for _, file := range []string{"customer.sql.go", "price.sql.go"} {
wantQueries, err := ioutil.ReadFile(file)
wantQueries, err := os.ReadFile(file)
if err != nil {
t.Fatalf("read wanted file %s: %s", file, err)
}

gotFile := filepath.Join(tmpDir, file)
assert.FileExists(t, gotFile, "Generate() should emit "+file)
gotQueries, err := ioutil.ReadFile(gotFile)
gotQueries, err := os.ReadFile(gotFile)
if err != nil {
t.Fatalf("read generated %s: %s", file, err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/function/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -30,11 +30,11 @@ func TestGenerate_Go_Example_Function(t *testing.T) {
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
"Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/go_pointer_types/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -36,11 +36,11 @@ func TestGenerate_Go_Example_GoPointerTypes(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/ltree/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -33,11 +33,11 @@ func TestGenerate_Go_Example_ltree(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/nested/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -33,11 +33,11 @@ func TestGenerate_Go_Example_nested(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/numeric_external/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -36,11 +36,11 @@ func TestGenerate_Go_Example_Numeric_External(t *testing.T) {
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
"Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/pgcrypto/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -29,11 +29,11 @@ func TestGenerate_Go_Example_Pgcrypto(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/separate_out_dir/out/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -37,14 +37,14 @@ func TestGenerate_Go_Example_SeparateOutDir(t *testing.T) {
"alpha_query.sql.1.go",
"bravo_query.sql.go",
} {
wantQueries, err := ioutil.ReadFile(file)
wantQueries, err := os.ReadFile(file)
if err != nil {
t.Fatalf("read wanted file %s: %s", file, err)
}

gotFile := filepath.Join(tmpDir, file)
assert.FileExists(t, gotFile, "Generate() should emit "+file)
gotQueries, err := ioutil.ReadFile(gotFile)
gotQueries, err := os.ReadFile(gotFile)
if err != nil {
t.Fatalf("read generated %s: %s", file, err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/syntax/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -31,11 +31,11 @@ func TestGenerate_Go_Example_Syntax(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/void/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
Expand All @@ -29,11 +29,11 @@ func TestGenerate_Go_Example_void(t *testing.T) {
wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := ioutil.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueriesFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := ioutil.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueriesFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
Expand Down
Loading

0 comments on commit 0abc883

Please sign in to comment.