Skip to content

Commit

Permalink
chore: enable testifylint linter
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Dec 31, 2024
1 parent 23087ff commit 4c365de
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ run:
issues:
exclude-dirs:
- vendor
linters:
enable:
- testifylint
linters-settings:
goimports:
local-prefixes: github.com/argoproj/pkg
testifylint:
enable-all: true
disable:
- float-compare
- require-error
4 changes: 2 additions & 2 deletions exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestRunCommandTimeout(t *testing.T) {
defer log.SetLevel(log.InfoLevel)

output, err := RunCommand("sh", CmdOpts{Timeout: 500 * time.Millisecond}, "-c", "echo hello world && echo my-error >&2 && sleep 2")
assert.Equal(t, output, "hello world")
assert.Equal(t, "hello world", output)
assert.EqualError(t, err, "`sh -c echo hello world && echo my-error >&2 && sleep 2` failed timeout after 500ms")

assert.Len(t, hook.Entries, 3)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestRunInDir(t *testing.T) {
cmd := exec.Command("pwd")
cmd.Dir = "/"
message, err := RunCommandExt(cmd, CmdOpts{})
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, "/", message)
}

Expand Down
6 changes: 3 additions & 3 deletions file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestIsDirectory(t *testing.T) {
testDir := filepath.Dir(filename)

isDir, err := IsDirectory(testDir)
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, isDir)

isDir, err = IsDirectory(filename)
assert.Nil(t, err)
assert.NoError(t, err)
assert.False(t, isDir)

isDir, err = IsDirectory("doesnt-exist")
assert.NotNil(t, err)
assert.Error(t, err)
assert.False(t, isDir)
}

Expand Down
14 changes: 7 additions & 7 deletions grpc/http/forwarders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestMarshalerIncludeFields(t *testing.T) {

out, err := m.Marshal(testVal)

assert.Nil(t, err)
assert.Equal(t, `{"metadata":{"name":"test"},"spec":{"source":{"path":"test_path"}}}`, string(out))
assert.NoError(t, err)
assert.JSONEq(t, `{"metadata":{"name":"test"},"spec":{"source":{"path":"test_path"}}}`, string(out))
}

func TestMarshalerExcludeFields(t *testing.T) {
Expand All @@ -51,16 +51,16 @@ func TestMarshalerExcludeFields(t *testing.T) {

out, err := m.Marshal(testVal)

assert.Nil(t, err)
assert.Equal(t, `{"metadata":{},"spec":{"source":{"path":"test_path"}},"status":{"message":"Failed"}}`, string(out))
assert.NoError(t, err)
assert.JSONEq(t, `{"metadata":{},"spec":{"source":{"path":"test_path"}},"status":{"message":"Failed"}}`, string(out))
}

func TestMarshalerSSE(t *testing.T) {
m := messageMarshaler{isSSE: true}

out, err := m.Marshal(testVal)

assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, `data: {"metadata":{"name":"test"},"spec":{"source":{"path":"test_path"}},"status":{"message":"Failed"}}
`, string(out))
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestFlushSuccess(t *testing.T) {
f := flusher{w: bufio.NewWriter(&buf)}
flush(&f)

assert.Equal(t, true, flushed)
assert.True(t, flushed)
}

func TestFlushFailed(t *testing.T) {
Expand All @@ -98,5 +98,5 @@ func TestFlushFailed(t *testing.T) {
f := flusher{}
flush(&f)

assert.Equal(t, false, flushed)
assert.False(t, flushed)
}
2 changes: 1 addition & 1 deletion kubeclientmetrics/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type fakeWrapper struct {
func (f fakeWrapper) RoundTrip(r *http.Request) (*http.Response, error) {
resp := httptest.NewRecorder()
resp.Code = 201
assert.Equal(f.t, f.currentCount, f.expectedCount)
assert.Equal(f.t, f.expectedCount, f.currentCount)
return resp.Result(), nil
}

Expand Down
6 changes: 3 additions & 3 deletions time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ func TestParseDuration(t *testing.T) {
}
for _, data := range testdata {
dur, err := ParseDuration(data.duration)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, dur.Nanoseconds(), data.xVal.Nanoseconds())
}
_, err := ParseDuration("1z")
assert.NotNil(t, err)
assert.Error(t, err)
}

// TestParseSince tests parsing of since strings
func TestParseSince(t *testing.T) {
oneDayAgo, err := ParseSince("1d")
assert.Nil(t, err)
assert.NoError(t, err)
yesterday := time.Now().UTC().Add(-24 * time.Hour)
assert.Equal(t, yesterday.Minute(), oneDayAgo.Minute())
}

0 comments on commit 4c365de

Please sign in to comment.