Skip to content

Commit 04f01f6

Browse files
committed
ci: add staticcheck
1 parent bc77ccb commit 04f01f6

File tree

15 files changed

+3754
-20
lines changed

15 files changed

+3754
-20
lines changed

.github/workflows/lint.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
name: commit_lint
2-
on: [pull_request]
1+
name: lint
32

4-
permissions:
5-
contents: read
6-
pull-requests: read
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
78

89
jobs:
9-
commitlint:
10+
staticcheck:
1011
runs-on: ubuntu-latest
1112
steps:
1213
- uses: actions/checkout@v3
13-
- uses: wagoid/commitlint-github-action@v5
14+
- uses: actions/setup-go@v3
15+
- run: go install honnef.co/go/tools/cmd/staticcheck@latest
16+
- run: ~/go/bin/staticcheck -checks all
File renamed without changes.

.github/workflows/validation.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: validation
2+
3+
on: [pull_request]
4+
5+
permissions:
6+
contents: read
7+
pull-requests: read
8+
9+
jobs:
10+
commitlint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: wagoid/commitlint-github-action@v5

command.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package cmd is a simple package
2+
// to execute shell commeand on linux,
3+
// windows, and osx.
14
package cmd
25

36
import (
@@ -245,12 +248,12 @@ func (c *Command) ExecuteContext(ctx context.Context) error {
245248
select {
246249
case <-ctx.Done():
247250
if err := cmd.Process.Kill(); err != nil {
248-
return fmt.Errorf("Timeout occurred and can not kill process with pid %v", cmd.Process.Pid)
251+
return fmt.Errorf("timeout occurred and can not kill process with pid %v", cmd.Process.Pid)
249252
}
250253

251254
err := ctx.Err()
252255
if c.Timeout > 0 && !hasDeadline {
253-
err = fmt.Errorf("Command timed out after %v", c.Timeout)
256+
err = fmt.Errorf("command timed out after %v", c.Timeout)
254257
}
255258
return err
256259
case err := <-done:

command_darwin_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
func TestCommand_ExecuteStderr(t *testing.T) {
1212
cmd := NewCommand(">&2 echo hello")
13-
1413
err := cmd.Execute()
1514

1615
assert.Nil(t, err)
@@ -23,7 +22,7 @@ func TestCommand_WithTimeout(t *testing.T) {
2322
err := cmd.Execute()
2423

2524
assert.NotNil(t, err)
26-
assert.Equal(t, "Command timed out after 5ms", err.Error())
25+
assert.Equal(t, "command timed out after 5ms", err.Error())
2726
}
2827

2928
func TestCommand_WithValidTimeout(t *testing.T) {

command_linux_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"bytes"
55
"context"
6-
"io/ioutil"
76
"os"
87
"os/exec"
98
"strings"
@@ -12,6 +11,7 @@ import (
1211
"time"
1312

1413
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1515
)
1616

1717
func TestCommand_ExecuteStderr(t *testing.T) {
@@ -27,10 +27,9 @@ func TestCommand_WithTimeout(t *testing.T) {
2727
cmd := NewCommand("sleep 0.1;", WithTimeout(1*time.Millisecond))
2828

2929
err := cmd.Execute()
30-
3130
assert.NotNil(t, err)
3231
// Sadly a process can not be killed every time :(
33-
containsMsg := strings.Contains(err.Error(), "Timeout occurred and can not kill process with pid") || strings.Contains(err.Error(), "Command timed out after 1ms")
32+
containsMsg := strings.Contains(err.Error(), "timeout occurred and can not kill process with pid") || strings.Contains(err.Error(), "command timed out after 1ms")
3433
assert.True(t, containsMsg)
3534
}
3635

@@ -54,7 +53,8 @@ func TestCommand_WithWorkingDir(t *testing.T) {
5453
}
5554

5655
func TestCommand_WithStandardStreams(t *testing.T) {
57-
tmpFile, _ := ioutil.TempFile("/tmp", "stdout_")
56+
tmpFile, err := os.CreateTemp("/tmp", "stdout_")
57+
require.NoError(t, err)
5858
originalStdout := os.Stdout
5959
os.Stdout = tmpFile
6060

@@ -66,8 +66,8 @@ func TestCommand_WithStandardStreams(t *testing.T) {
6666
cmd := NewCommand("echo hey", WithStandardStreams)
6767
cmd.Execute()
6868

69-
r, err := ioutil.ReadFile(tmpFile.Name())
70-
assert.Nil(t, err)
69+
r, err := os.ReadFile(tmpFile.Name())
70+
require.NoError(t, err)
7171
assert.Equal(t, "hey\n", string(r))
7272
}
7373

@@ -137,7 +137,7 @@ func TestCommand_WithContext(t *testing.T) {
137137
cmd := NewCommand("sleep 3;", WithTimeout(1*time.Second))
138138
err := cmd.Execute()
139139
assert.NotNil(t, err)
140-
assert.Equal(t, "Command timed out after 1s", err.Error())
140+
assert.Equal(t, "command timed out after 1s", err.Error())
141141

142142
// set context timeout to 2 seconds to ensure
143143
// context takes precedence over timeout

command_windows_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ func TestCommand_ExecuteStderr(t *testing.T) {
2121

2222
func TestCommand_WithTimeout(t *testing.T) {
2323
cmd := NewCommand("timeout 0.005;", WithTimeout(5*time.Millisecond))
24-
2524
err := cmd.Execute()
2625

2726
assert.NotNil(t, err)
2827
// This is needed because windows sometimes can not kill the process :(
29-
containsMsg := strings.Contains(err.Error(), "Timeout occurred and can not kill process with pid") || strings.Contains(err.Error(), "Command timed out after 5ms")
28+
containsMsg := strings.Contains(err.Error(), "timeout occurred and can not kill process with pid") || strings.Contains(err.Error(), "command timed out after 5ms")
3029
assert.True(t, containsMsg)
3130
}
3231

vendor/github.com/stretchr/testify/require/doc.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/stretchr/testify/require/forward_requirements.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)