testutil: rename Calls() -> CallArgsList() for clarity
The current MockCmd.Calls() is a bit ambiguous so follow the example of pytest here and rename to the cleaner CallArgsList() that captures more closely what the helper is actually doing.
This commit is contained in:
parent
bb45b89d84
commit
ad20533d87
3 changed files with 8 additions and 8 deletions
|
|
@ -41,7 +41,7 @@ func (mc *MockCmd) Path() string {
|
|||
return filepath.Join(mc.binDir, mc.name)
|
||||
}
|
||||
|
||||
func (mc *MockCmd) Calls() [][]string {
|
||||
func (mc *MockCmd) CallArgsList() [][]string {
|
||||
b, err := os.ReadFile(mc.Path() + ".run")
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
|
|
@ -49,15 +49,15 @@ func (mc *MockCmd) Calls() [][]string {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var calls [][]string
|
||||
var callArgsList [][]string
|
||||
for _, line := range strings.Split(string(b), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
call := strings.Split(line, "\000")
|
||||
calls = append(calls, call[0:len(call)-1])
|
||||
callArgsList = append(callArgsList, call[0:len(call)-1])
|
||||
}
|
||||
return calls
|
||||
return callArgsList
|
||||
}
|
||||
|
||||
// CaptureStdio runs the given function f() in an environment that
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func TestMockCommand(t *testing.T) {
|
|||
assert.Equal(t, [][]string{
|
||||
{"run1-arg1", "run1-arg2"},
|
||||
{"run2-arg1", "run2-arg2"},
|
||||
}, fakeCmd.Calls())
|
||||
}, fakeCmd.CallArgsList())
|
||||
}
|
||||
|
||||
func TestCaptureStdout(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue