Skip to content

Commit

Permalink
migrate from deprecated ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckeyeCoder committed Aug 25, 2022
1 parent 282bdb1 commit 8f692c9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

Artyom Pervukhin <[email protected]>
Dan Peterson <[email protected]>
David Walton <[email protected]>
Davsk Ltd Co <[email protected]>
Jaap Aarts <[email protected]>
Jan Mercl <[email protected]>
Logan Snow <[email protected]>
Michael Hoffmann <[email protected]>
Ross Light <[email protected]>
Steffen Butzer <steffen(dot)[email protected]>
Saed SayedAhmed <[email protected]>
Steffen Butzer <steffen(dot)[email protected]>
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ Alexander Menzhinsky <[email protected]>
Artyom Pervukhin <[email protected]>
Dan Peterson <[email protected]>
David Skinner <[email protected]>
David Walton <[email protected]>
Gleb Sakhnov <[email protected]>
Jaap Aarts <[email protected]>
Jan Mercl <[email protected]>
Logan Snow <[email protected]>
Matthew Gabeler-Lee <[email protected]>
Michael Hoffmann <[email protected]>
Ross Light <[email protected]>
Saed SayedAhmed <[email protected]>
Steffen Butzer <steffen(dot)[email protected]>
Yaacov Akiba Slama <[email protected]>
Saed SayedAhmed <[email protected]>
47 changes: 23 additions & 24 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"net/url"
"os"
Expand Down Expand Up @@ -126,7 +125,7 @@ func TestMain(m *testing.M) {

func testMain(m *testing.M) int {
var err error
tempDir, err = ioutil.TempDir("", "sqlite-test-")
tempDir, err = os.MkdirTemp("", "sqlite-test-")
if err != nil {
panic(err) //TODOOK
}
Expand All @@ -137,7 +136,7 @@ func testMain(m *testing.M) int {
}

func tempDB(t testing.TB) (string, *sql.DB) {
dir, err := ioutil.TempDir("", "sqlite-test-")
dir, err := os.MkdirTemp("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -778,7 +777,7 @@ func TestConcurrentGoroutines(t *testing.T) {
nrows = 5000
)

dir, err := ioutil.TempDir("", "sqlite-test-")
dir, err := os.MkdirTemp("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -890,7 +889,7 @@ func TestConcurrentProcesses(t *testing.T) {
t.Skip("skipping test")
}

dir, err := ioutil.TempDir("", "sqlite-test-")
dir, err := os.MkdirTemp("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
Expand All @@ -909,7 +908,7 @@ func TestConcurrentProcesses(t *testing.T) {
continue
}

b, err := ioutil.ReadFile(v)
b, err := os.ReadFile(v)
if err != nil {
t.Fatal(err)
}
Expand All @@ -922,7 +921,7 @@ func TestConcurrentProcesses(t *testing.T) {
b = bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n"))
}

if err := ioutil.WriteFile(filepath.Join(dir, filepath.Base(v)), b, 0666); err != nil {
if err := os.WriteFile(filepath.Join(dir, filepath.Base(v)), b, 0666); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -1026,7 +1025,7 @@ INSERT INTO "products" ("id", "user_id", "name", "description", "created_at", "c
`
)

dir, err := ioutil.TempDir("", "sqlite-test-")
dir, err := os.MkdirTemp("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1124,7 +1123,7 @@ func mustExec(t *testing.T, db *sql.DB, sql string, args ...interface{}) sql.Res
func TestIssue20(t *testing.T) {
const TablePrefix = "gosqltest_"

tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1184,7 +1183,7 @@ func TestIssue20(t *testing.T) {
}

func TestNoRows(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1277,7 +1276,7 @@ func TestColumnsNoRows(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/28
func TestIssue28(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1306,7 +1305,7 @@ func TestIssue28(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/30
func TestColumnTypes(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1375,7 +1374,7 @@ Col 3: DatabaseTypeName "DATE", DecimalSize 0 0 false, Length 922337203685477580

// https://gitlab.com/cznic/sqlite/-/issues/32
func TestColumnTypesNoRows(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1803,7 +1802,7 @@ func TestIssue51(t *testing.T) {
t.Skip("skipping test in short mode")
}

tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1942,7 +1941,7 @@ const charset = "abcdefghijklmnopqrstuvwxyz" +

// https://gitlab.com/cznic/sqlite/-/issues/53
func TestIssue53(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1999,7 +1998,7 @@ CREATE TABLE IF NOT EXISTS loginst (

// https://gitlab.com/cznic/sqlite/-/issues/37
func TestPersistPragma(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2100,7 +2099,7 @@ func checkPragmas(db *sql.DB, pragmas []pragmaCfg) error {
}

func TestInMemory(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2154,13 +2153,13 @@ func testInMemory(db *sql.DB) error {
return err
}

files, err := ioutil.ReadDir("./")
dirEntries, err := os.ReadDir("./")
if err != nil {
return err
}

for _, file := range files {
if strings.Contains(file.Name(), "memory") {
for _, dirEntry := range dirEntries {
if strings.Contains(dirEntry.Name(), "memory") {
return fmt.Errorf("file was created for in memory database")
}
}
Expand Down Expand Up @@ -2225,7 +2224,7 @@ func TestIssue70(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/66
func TestIssue66(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2289,7 +2288,7 @@ func TestIssue66(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/65
func TestIssue65(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2469,7 +2468,7 @@ func TestConstraintUniqueError(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/92
func TestBeginMode(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2535,7 +2534,7 @@ func TestBeginMode(t *testing.T) {

// https://gitlab.com/cznic/sqlite/-/issues/94
func TestCancelRace(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// +build ignore cgo,cgotest

package sqlite // import "modernc.org/sqlite"

import (
"database/sql"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -18,7 +18,7 @@ import (

// https://gitlab.com/cznic/sqlite/-/issues/65
func TestIssue65CGo(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"database/sql"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -18,7 +17,7 @@ func main() {
}

func main1() error {
dir, err := ioutil.TempDir("", "test-")
dir, err := os.MkdirTemp("", "test-")
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -263,7 +262,7 @@ var (
)

func download() {
tmp, err := ioutil.TempDir("", "")
tmp, err := os.MkdirTemp("", "")
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
Expand Down
7 changes: 3 additions & 4 deletions tcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -57,7 +56,7 @@ func TestTclTest(t *testing.T) {
t.Fatal(err)
}

dir, err := ioutil.TempDir("", "sqlite-test-")
dir, err := os.MkdirTemp("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -99,12 +98,12 @@ func TestTclTest(t *testing.T) {

s := filepath.Join(wd, v)
d := filepath.Join(dir, filepath.Base(v))
f, err := ioutil.ReadFile(s)
f, err := os.ReadFile(s)
if err != nil {
t.Fatal(err)
}

if err := ioutil.WriteFile(d, f, 0660); err != nil {
if err := os.WriteFile(d, f, 0660); err != nil {
t.Fatal(err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions tpch/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"database/sql"
"fmt"
"io/ioutil"
"math"
"math/big"
"os"
Expand Down Expand Up @@ -628,7 +627,7 @@ func pthForSUT(sut driver.SUT, sf int) string {
}

func dbGen(sut driver.SUT, sf int) (err error) {
if pseudotext, err = ioutil.ReadFile(filepath.Join("testdata", "pseudotext")); err != nil {
if pseudotext, err = os.ReadFile(filepath.Join("testdata", "pseudotext")); err != nil {
return fmt.Errorf("Run this program with -pseudotext: %v", err)
}

Expand Down

0 comments on commit 8f692c9

Please sign in to comment.