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
|
|
@ -392,8 +392,8 @@ centos-9-qcow2-x86_64/centos-9-qcow2-x86_64.qcow2
|
||||||
`)
|
`)
|
||||||
|
|
||||||
// ensure osbuild was run exactly one
|
// ensure osbuild was run exactly one
|
||||||
require.Equal(t, 1, len(fakeOsbuildCmd.Calls()))
|
require.Equal(t, 1, len(fakeOsbuildCmd.CallArgsList()))
|
||||||
osbuildCall := fakeOsbuildCmd.Calls()[0]
|
osbuildCall := fakeOsbuildCmd.CallArgsList()[0]
|
||||||
// --cache is passed correctly to osbuild
|
// --cache is passed correctly to osbuild
|
||||||
storePos := slices.Index(osbuildCall, "--store")
|
storePos := slices.Index(osbuildCall, "--store")
|
||||||
assert.True(t, storePos > -1)
|
assert.True(t, storePos > -1)
|
||||||
|
|
@ -470,7 +470,7 @@ func TestBuildIntegrationArgs(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// ensure output dir override works
|
// ensure output dir override works
|
||||||
osbuildCall := fakeOsbuildCmd.Calls()[0]
|
osbuildCall := fakeOsbuildCmd.CallArgsList()[0]
|
||||||
outputDirPos := slices.Index(osbuildCall, "--output-directory")
|
outputDirPos := slices.Index(osbuildCall, "--output-directory")
|
||||||
assert.True(t, outputDirPos > -1)
|
assert.True(t, outputDirPos > -1)
|
||||||
assert.Equal(t, outputDir, osbuildCall[outputDirPos+1])
|
assert.Equal(t, outputDir, osbuildCall[outputDirPos+1])
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (mc *MockCmd) Path() string {
|
||||||
return filepath.Join(mc.binDir, mc.name)
|
return filepath.Join(mc.binDir, mc.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MockCmd) Calls() [][]string {
|
func (mc *MockCmd) CallArgsList() [][]string {
|
||||||
b, err := os.ReadFile(mc.Path() + ".run")
|
b, err := os.ReadFile(mc.Path() + ".run")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -49,15 +49,15 @@ func (mc *MockCmd) Calls() [][]string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var calls [][]string
|
var callArgsList [][]string
|
||||||
for _, line := range strings.Split(string(b), "\n") {
|
for _, line := range strings.Split(string(b), "\n") {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
call := strings.Split(line, "\000")
|
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
|
// CaptureStdio runs the given function f() in an environment that
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func TestMockCommand(t *testing.T) {
|
||||||
assert.Equal(t, [][]string{
|
assert.Equal(t, [][]string{
|
||||||
{"run1-arg1", "run1-arg2"},
|
{"run1-arg1", "run1-arg2"},
|
||||||
{"run2-arg1", "run2-arg2"},
|
{"run2-arg1", "run2-arg2"},
|
||||||
}, fakeCmd.Calls())
|
}, fakeCmd.CallArgsList())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCaptureStdout(t *testing.T) {
|
func TestCaptureStdout(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue