-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): change the setCmdByOS function to include auxiliary routine…
…s and add test
- Loading branch information
Showing
2 changed files
with
65 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package report | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSetCmdByOS(t *testing.T) { | ||
tests := []struct { | ||
goos string | ||
wsl bool | ||
expected string | ||
args []string | ||
errExpected bool | ||
}{ | ||
{"windows", false, "cmd", []string{"/c", "start"}, false}, | ||
{"darwin", false, "open", nil, false}, | ||
{"freebsd", false, "xdg-open", nil, false}, | ||
{"linux", false, "xdg-open", nil, false}, | ||
{"linux", true, "sensible-browser", nil, false}, | ||
{"unknown", false, "", nil, true}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.goos, func(t *testing.T) { | ||
isWSLfake := func() (*bool, error) { | ||
return &test.wsl, nil | ||
} | ||
|
||
cmd, args, err := setCmdByOS(test.goos, isWSLfake) | ||
if test.errExpected { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Equal(t, test.expected, cmd) | ||
assert.Equal(t, test.args, args) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// TODO: test isWSL() and openURL(...) |