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:
Michael Vogt 2025-07-16 11:16:19 +02:00
parent bb45b89d84
commit ad20533d87
3 changed files with 8 additions and 8 deletions

View file

@ -392,8 +392,8 @@ centos-9-qcow2-x86_64/centos-9-qcow2-x86_64.qcow2
`)
// ensure osbuild was run exactly one
require.Equal(t, 1, len(fakeOsbuildCmd.Calls()))
osbuildCall := fakeOsbuildCmd.Calls()[0]
require.Equal(t, 1, len(fakeOsbuildCmd.CallArgsList()))
osbuildCall := fakeOsbuildCmd.CallArgsList()[0]
// --cache is passed correctly to osbuild
storePos := slices.Index(osbuildCall, "--store")
assert.True(t, storePos > -1)
@ -470,7 +470,7 @@ func TestBuildIntegrationArgs(t *testing.T) {
require.NoError(t, err)
// ensure output dir override works
osbuildCall := fakeOsbuildCmd.Calls()[0]
osbuildCall := fakeOsbuildCmd.CallArgsList()[0]
outputDirPos := slices.Index(osbuildCall, "--output-directory")
assert.True(t, outputDirPos > -1)
assert.Equal(t, outputDir, osbuildCall[outputDirPos+1])

View file

@ -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

View file

@ -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) {