Skip to content

Commit

Permalink
Merge pull request #245 from thaJeztah/replace_ioutil
Browse files Browse the repository at this point in the history
drop go1.16 from test-matrix, replace deprecated io/ioutil, and update golangci-lint to v1.49.0
  • Loading branch information
dnephin authored Oct 6, 2022
2 parents 36dd5d1 + 5b51cec commit f086d27
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 88 deletions.
9 changes: 2 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ workflows:
ci:
jobs:
- lint
- go/test:
name: test-golang-1.16
executor:
name: go/golang
tag: 1.16-alpine
- go/test:
name: test-golang-1.17
executor:
Expand Down Expand Up @@ -55,8 +50,8 @@ jobs:
steps:
- checkout
- go/install-golangci-lint:
prefix: v1.48.0
version: 1.48.0
prefix: v1.49.0
version: 1.49.0
- go/install: {package: git}
- run:
name: Lint
Expand Down
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
Expand All @@ -42,11 +41,9 @@ linters:
- goconst
- gofmt
- goimports
- golint
- gosimple
- govet
- ineffassign
- interfacer
- lll
- maintidx
- misspell
Expand All @@ -56,13 +53,12 @@ linters:
- nilnil
- nolintlint
- prealloc
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
- whitespace
10 changes: 5 additions & 5 deletions assert/assert_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -33,7 +33,7 @@ that we are testing
`
assert.Equal(t, actual, expectedOne)

raw, err := ioutil.ReadFile(fileName(t))
raw, err := os.ReadFile(fileName(t))
assert.NilError(t, err)

expected := "var expectedOne = `this is the\nactual value\nthat we are testing\n`"
Expand All @@ -51,7 +51,7 @@ expected value
`
assert.Equal(t, actual, expectedTwo)

raw, err := ioutil.ReadFile(fileName(t))
raw, err := os.ReadFile(fileName(t))
assert.NilError(t, err)

expected := "const expectedTwo = `this is the new\nexpected value\n`"
Expand All @@ -72,7 +72,7 @@ for var inside function

assert.Equal(t, actual, expectedInsideFunc)

raw, err := ioutil.ReadFile(fileName(t))
raw, err := os.ReadFile(fileName(t))
assert.NilError(t, err)

expected := "expectedInsideFunc := `this is the new\nexpected value\nfor var inside function\n`"
Expand All @@ -93,7 +93,7 @@ for const inside function

assert.Equal(t, actual, expectedConstInsideFunc)

raw, err := ioutil.ReadFile(fileName(t))
raw, err := os.ReadFile(fileName(t))
assert.NilError(t, err)

expected := "const expectedConstInsideFunc = `this is the new\nexpected value\nfor const inside function\n`"
Expand Down
3 changes: 1 addition & 2 deletions assert/cmd/gty-migrate-from-testify/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ type call struct {

func (c call) String() string {
buf := new(bytes.Buffer)
//nolint: errcheck
format.Node(buf, token.NewFileSet(), c.expr)
_ = format.Node(buf, token.NewFileSet(), c.expr)
return buf.String()
}

Expand Down
3 changes: 1 addition & 2 deletions assert/cmd/gty-migrate-from-testify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"go/ast"
"go/format"
"go/token"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -126,7 +125,7 @@ func run(opts options) error {
return fmt.Errorf("failed to format %s: %w", filename, err)
}

if err := ioutil.WriteFile(absFilename, raw, 0); err != nil {
if err := os.WriteFile(absFilename, raw, 0); err != nil {
return fmt.Errorf("failed to write file %s: %w", filename, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions assert/cmd/gty-migrate-from-testify/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

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

"github.com/google/go-cmp/cmp"
Expand All @@ -25,7 +25,7 @@ func TestRun(t *testing.T) {
})
assert.NilError(t, err)

raw, err := ioutil.ReadFile(dir.Join("src/example.com/example/some_test.go"))
raw, err := os.ReadFile(dir.Join("src/example.com/example/some_test.go"))
assert.NilError(t, err)
golden.Assert(t, string(raw), "full-expected/some_test.go")
}
Expand Down
2 changes: 1 addition & 1 deletion assert/cmp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
//nolint: errorlint // unwrapping is not appropriate here
//nolint:errorlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down
5 changes: 2 additions & 3 deletions fs/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fs_test

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

Expand All @@ -18,7 +17,7 @@ func ExampleNewDir() {
dir := fs.NewDir(t, "test-name", fs.WithFile("file1", "content\n"))
defer dir.Remove()

files, err := ioutil.ReadDir(dir.Path())
files, err := os.ReadDir(dir.Path())
assert.NilError(t, err)
assert.Assert(t, cmp.Len(files, 0))
}
Expand All @@ -28,7 +27,7 @@ func ExampleNewFile() {
file := fs.NewFile(t, "test-name", fs.WithContent("content\n"), fs.AsUser(0, 0))
defer file.Remove()

content, err := ioutil.ReadFile(file.Path())
content, err := os.ReadFile(file.Path())
assert.NilError(t, err)
assert.Equal(t, "content\n", content)
}
Expand Down
11 changes: 4 additions & 7 deletions fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ contents and structure of a directory.
package fs // import "gotest.tools/v3/fs"

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -46,7 +45,7 @@ func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
tempfile, err := ioutil.TempFile("", cleanPrefix(prefix)+"-")
tempfile, err := os.CreateTemp("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)

file := &File{path: tempfile.Name()}
Expand All @@ -72,8 +71,7 @@ func (f *File) Path() string {

// Remove the file
func (f *File) Remove() {
//nolint: errcheck
os.Remove(f.path)
_ = os.Remove(f.path)
}

// Dir is a temporary directory
Expand All @@ -90,7 +88,7 @@ func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
path, err := ioutil.TempDir("", cleanPrefix(prefix)+"-")
path, err := os.MkdirTemp("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)
dir := &Dir{path: path}
cleanup.Cleanup(t, dir.Remove)
Expand All @@ -106,8 +104,7 @@ func (d *Dir) Path() string {

// Remove the directory
func (d *Dir) Remove() {
//nolint: errcheck
os.RemoveAll(d.path)
_ = os.RemoveAll(d.path)
}

// Join returns a new path with this directory as the base of the path
Expand Down
9 changes: 2 additions & 7 deletions fs/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fs_test

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -97,15 +96,11 @@ func TestNewDir_IntegrationWithCleanup(t *testing.T) {
}

func TestDirFromPath(t *testing.T) {
tmpdir, err := ioutil.TempDir("", t.Name())
assert.NilError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpdir)
})
tmpdir := t.TempDir()

dir := fs.DirFromPath(t, tmpdir, fs.WithFile("newfile", ""))

_, err = os.Stat(dir.Join("newfile"))
_, err := os.Stat(dir.Join("newfile"))
assert.NilError(t, err)

assert.Equal(t, dir.Path(), tmpdir)
Expand Down
9 changes: 6 additions & 3 deletions fs/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fs
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -84,7 +83,7 @@ func manifestFromDir(path string) (Manifest, error) {

func newDirectory(path string, info os.FileInfo) (*directory, error) {
items := make(map[string]dirEntry)
children, err := ioutil.ReadDir(path)
children, err := os.ReadDir(path)
if err != nil {
return nil, err
}
Expand All @@ -103,7 +102,11 @@ func newDirectory(path string, info os.FileInfo) (*directory, error) {
}, nil
}

func getTypedResource(path string, info os.FileInfo) (dirEntry, error) {
func getTypedResource(path string, entry os.DirEntry) (dirEntry, error) {
info, err := entry.Info()
if err != nil {
return nil, err
}
switch {
case info.IsDir():
return newDirectory(path, info)
Expand Down
7 changes: 3 additions & 4 deletions fs/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fs
import (
"bytes"
"io"
"io/ioutil"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -92,12 +91,12 @@ var cmpManifest = cmp.Options{
if x == nil || y == nil {
return x == y
}
xContent, err := ioutil.ReadAll(x)
xContent, err := io.ReadAll(x)
if err != nil {
return false
}

yContent, err := ioutil.ReadAll(y)
yContent, err := io.ReadAll(y)
if err != nil {
return false
}
Expand All @@ -106,5 +105,5 @@ var cmpManifest = cmp.Options{
}

func readCloser(s string) io.ReadCloser {
return ioutil.NopCloser(strings.NewReader(s))
return io.NopCloser(strings.NewReader(s))
}
Loading

0 comments on commit f086d27

Please sign in to comment.