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

replaces ioutil to io #96

Merged
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
8 changes: 4 additions & 4 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package cmd

import (
"context"
"errors"
"fmt"
"io/ioutil"
"context"
"os"

"github.com/cloudspannerecosystem/wrench/pkg/spanner"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,7 +57,7 @@ func apply(c *cobra.Command, _ []string) error {
return errors.New("cannot specify DDL and DML at same time")
}

ddl, err := ioutil.ReadFile(ddlFile)
ddl, err := os.ReadFile(ddlFile)
if err != nil {
return &Error{
err: err,
Expand All @@ -81,7 +81,7 @@ func apply(c *cobra.Command, _ []string) error {
}

// apply dml
dml, err := ioutil.ReadFile(dmlFile)
dml, err := os.ReadFile(dmlFile)
if err != nil {
return &Error{
err: err,
Expand Down
4 changes: 2 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package cmd

import (
"context"
"io/ioutil"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -43,7 +43,7 @@ func create(c *cobra.Command, _ []string) error {
defer client.Close()

filename := schemaFilePath(c)
ddl, err := ioutil.ReadFile(filename)
ddl, err := os.ReadFile(filename)
if err != nil {
return &Error{
err: err,
Expand Down
4 changes: 2 additions & 2 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package cmd

import (
"context"
"io/ioutil"
"os"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func load(c *cobra.Command, _ []string) error {
}
}

err = ioutil.WriteFile(schemaFilePath(c), ddl, 0o664)
err = os.WriteFile(schemaFilePath(c), ddl, 0o664)
if err != nil {
return &Error{
err: err,
Expand Down
9 changes: 4 additions & 5 deletions pkg/spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package spanner
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -74,7 +73,7 @@ func TestLoadDDL(t *testing.T) {
t.Fatalf("failed to load ddl: %v", err)
}

wantDDL, err := ioutil.ReadFile("testdata/schema.sql")
wantDDL, err := os.ReadFile("testdata/schema.sql")
if err != nil {
t.Fatalf("failed to read ddl file: %v", err)
}
Expand All @@ -88,7 +87,7 @@ func TestApplyDDLFile(t *testing.T) {
t.Parallel()
ctx := context.Background()

ddl, err := ioutil.ReadFile("testdata/ddl.sql")
ddl, err := os.ReadFile("testdata/ddl.sql")
if err != nil {
t.Fatalf("failed to read ddl file: %v", err)
}
Expand Down Expand Up @@ -171,7 +170,7 @@ func TestApplyDMLFile(t *testing.T) {
t.Fatalf("failed to apply mutation: %v", err)
}

dml, err := ioutil.ReadFile("testdata/dml.sql")
dml, err := os.ReadFile("testdata/dml.sql")
if err != nil {
t.Fatalf("failed to read dml file: %v", err)
}
Expand Down Expand Up @@ -474,7 +473,7 @@ func testClientWithDatabase(t *testing.T, ctx context.Context) (*Client, func())
t.Fatalf("failed to create spanner client: %v", err)
}

ddl, err := ioutil.ReadFile("testdata/schema.sql")
ddl, err := os.ReadFile("testdata/schema.sql")
if err != nil {
t.Fatalf("failed to read schema file: %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/spanner/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package spanner
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -80,7 +80,7 @@ func (ms Migrations) Less(i, j int) bool {
}

func LoadMigrations(dir string) (Migrations, error) {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
Expand All @@ -94,7 +94,9 @@ func LoadMigrations(dir string) (Migrations, error) {
continue
}

matches := migrationFileRegex.FindStringSubmatch(f.Name())
filename := f.Name()

matches := migrationFileRegex.FindStringSubmatch(filename)
if len(matches) != 4 {
continue
}
Expand All @@ -104,9 +106,7 @@ func LoadMigrations(dir string) (Migrations, error) {
continue
}

fileName := f.Name()

file, err := ioutil.ReadFile(filepath.Join(dir, fileName))
file, err := os.ReadFile(filepath.Join(dir, filename))
if err != nil {
continue
}
Expand All @@ -133,9 +133,9 @@ func LoadMigrations(dir string) (Migrations, error) {
})

if prevFileName, ok := versions[version]; ok {
return nil, fmt.Errorf("colliding version number \"%d\" between file names \"%s\" and \"%s\"", version, prevFileName, fileName)
return nil, fmt.Errorf("colliding version number \"%d\" between file names \"%s\" and \"%s\"", version, prevFileName, filename)
}
versions[version] = fileName
versions[version] = filename
}

return migrations, nil
Expand Down
Loading