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

drop go1.16 from test-matrix, replace deprecated io/ioutil, and update golangci-lint to v1.49.0 #245

Merged
merged 5 commits into from
Oct 6, 2022
Merged
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
9 changes: 2 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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:
@@ -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
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
@@ -42,11 +41,9 @@ linters:
- goconst
- gofmt
- goimports
- golint
- gosimple
- govet
- ineffassign
- interfacer
- lll
- maintidx
- misspell
@@ -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
@@ -4,7 +4,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"
@@ -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`"
@@ -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`"
@@ -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`"
@@ -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`"
3 changes: 1 addition & 2 deletions assert/cmd/gty-migrate-from-testify/call.go
Original file line number Diff line number Diff line change
@@ -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()
}

3 changes: 1 addition & 2 deletions assert/cmd/gty-migrate-from-testify/main.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import (
"go/ast"
"go/format"
"go/token"
"io/ioutil"
"log"
"os"
"path"
@@ -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)
}
}
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"
@@ -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")
}
2 changes: 1 addition & 1 deletion assert/cmp/compare.go
Original file line number Diff line number Diff line change
@@ -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)
}
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"

@@ -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))
}
@@ -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)
}
11 changes: 4 additions & 7 deletions fs/file.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ contents and structure of a directory.
package fs // import "gotest.tools/v3/fs"

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -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()}
@@ -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
@@ -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)
@@ -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
9 changes: 2 additions & 7 deletions fs/file_test.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package fs_test

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -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)
9 changes: 6 additions & 3 deletions fs/manifest.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package fs
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

@@ -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
}
@@ -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)
7 changes: 3 additions & 4 deletions fs/manifest_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package fs
import (
"bytes"
"io"
"io/ioutil"
"os"
"runtime"
"strings"
@@ -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
}
@@ -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