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

refactor: simplify test asserts; enable testifylint #680

Merged
merged 1 commit into from
Nov 7, 2024
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ linters:
- revive # configurable linter for Go. Drop-in replacement of golint
- staticcheck # go vet on steroids
- stylecheck # static analysis, finds bugs and performance issues, offers simplifications, and enforces style rules
- testifylint # checks usage of github.com/stretchr/testify
- unconvert # Remove unnecessary type conversions
- unused # Checks Go code for unused constants, variables, functions and types
7 changes: 4 additions & 3 deletions runner/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFlag(t *testing.T) {
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestFlag(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
flag := flag.NewFlagSet(t.Name(), flag.ExitOnError)
cmdArgs := ParseConfigFlag(flag)
assert.NoError(t, flag.Parse(tc.args))
require.NoError(t, flag.Parse(tc.args))
assert.Equal(t, tc.expected, *cmdArgs[tc.key].Value)
})
}
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestConfigRuntimeArgs(t *testing.T) {
args: []string{"--build.exclude_unchanged", "true"},
key: "build.exclude_unchanged",
check: func(t *testing.T, conf *Config) {
assert.Equal(t, true, conf.Build.ExcludeUnchanged)
assert.True(t, conf.Build.ExcludeUnchanged)
},
},
{
Expand All @@ -121,7 +122,7 @@ func TestConfigRuntimeArgs(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.Chdir(dir))
require.NoError(t, os.Chdir(dir))
flag := flag.NewFlagSet(t.Name(), flag.ExitOnError)
cmdArgs := ParseConfigFlag(flag)
_ = flag.Parse(tc.args)
Expand Down
13 changes: 7 additions & 6 deletions runner/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type reloader struct {
Expand Down Expand Up @@ -97,8 +98,8 @@ func TestProxy_proxyHandler(t *testing.T) {
return req
},
assert: func(resp *http.Request) {
assert.NoError(t, resp.ParseForm())
assert.Equal(t, resp.Form.Get("foo"), "bar")
require.NoError(t, resp.ParseForm())
assert.Equal(t, "bar", resp.Form.Get("foo"))
},
},
{
Expand All @@ -108,7 +109,7 @@ func TestProxy_proxyHandler(t *testing.T) {
},
assert: func(resp *http.Request) {
q := resp.URL.Query()
assert.Equal(t, q.Encode(), "q=air")
assert.Equal(t, "q=air", q.Encode())
},
},
{
Expand All @@ -124,9 +125,9 @@ func TestProxy_proxyHandler(t *testing.T) {
Foo string `json:"foo"`
}
var r Response
assert.NoError(t, json.NewDecoder(resp.Body).Decode(&r))
assert.Equal(t, resp.URL.Path, "/a/b/c")
assert.Equal(t, r.Foo, "bar")
require.NoError(t, json.NewDecoder(resp.Body).Decode(&r))
assert.Equal(t, "/a/b/c", resp.URL.Path)
assert.Equal(t, "bar", r.Foo)
},
},
{
Expand Down
9 changes: 5 additions & 4 deletions runner/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIsDirRootPath(t *testing.T) {
Expand Down Expand Up @@ -219,7 +220,7 @@ func Test_killCmd_SendInterrupt_false(t *testing.T) {
// check processes were being killed
// read pids from file
bytesRead, err := os.ReadFile("pid")
assert.NoError(t, err)
require.NoError(t, err)
lines := strings.Split(string(bytesRead), "\n")
for _, line := range lines {
_, err := strconv.Atoi(line)
Expand Down Expand Up @@ -283,7 +284,7 @@ func TestCheckIncludeFile(t *testing.T) {
},
},
}
assert.Equal(t, e.checkIncludeFile("main.go"), true)
assert.Equal(t, e.checkIncludeFile("no.go"), false)
assert.Equal(t, e.checkIncludeFile("."), false)
assert.True(t, e.checkIncludeFile("main.go"))
assert.False(t, e.checkIncludeFile("no.go"))
assert.False(t, e.checkIncludeFile("."))
}
Loading