testutil: remove unnecessary testutil.MockCmd.Restore()

While looking over the code I noticed that the `Restore()` helper
is not needed (and arguably wrong as it does not reset PATH).
We already use `t.TempDir()` and `t.Setenv()` as part of the
command setup so manually cleanup is not neccessary (and is today
even incomplete). So YAGNI and we can remove Restore().
This commit is contained in:
Michael Vogt 2025-07-16 10:53:52 +02:00
parent 9717980d3f
commit bb45b89d84
4 changed files with 7 additions and 22 deletions

View file

@ -41,10 +41,6 @@ func (mc *MockCmd) Path() string {
return filepath.Join(mc.binDir, mc.name)
}
func (mc *MockCmd) Restore() error {
return os.RemoveAll(mc.binDir)
}
func (mc *MockCmd) Calls() [][]string {
b, err := os.ReadFile(mc.Path() + ".run")
if os.IsNotExist(err) {

View file

@ -13,7 +13,6 @@ import (
func TestMockCommand(t *testing.T) {
fakeCmd := testutil.MockCommand(t, "false", "exit 0")
defer fakeCmd.Restore()
err := exec.Command("false", "run1-arg1", "run1-arg2").Run()
assert.NoError(t, err)