-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: clean code arround CLI args usage (#4557)
- Loading branch information
Showing
10 changed files
with
219 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package lint | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_buildArgs(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
args []string | ||
expected []string | ||
}{ | ||
{ | ||
desc: "empty", | ||
args: nil, | ||
expected: []string{"./..."}, | ||
}, | ||
{ | ||
desc: "start with a dot", | ||
args: []string{filepath.FromSlash("./foo")}, | ||
expected: []string{filepath.FromSlash("./foo")}, | ||
}, | ||
{ | ||
desc: "start without a dot", | ||
args: []string{"foo"}, | ||
expected: []string{filepath.FromSlash("./foo")}, | ||
}, | ||
{ | ||
desc: "absolute path", | ||
args: []string{mustAbs(t, "/tmp/foo")}, | ||
expected: []string{mustAbs(t, "/tmp/foo")}, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
results := buildArgs(test.args) | ||
|
||
assert.Equal(t, test.expected, results) | ||
}) | ||
} | ||
} | ||
|
||
func mustAbs(t *testing.T, p string) string { | ||
t.Helper() | ||
|
||
abs, err := filepath.Abs(filepath.FromSlash(p)) | ||
require.NoError(t, err) | ||
|
||
return abs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.