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:
parent
9717980d3f
commit
bb45b89d84
4 changed files with 7 additions and 22 deletions
|
|
@ -378,7 +378,6 @@ func TestBuildIntegrationHappy(t *testing.T) {
|
|||
|
||||
script := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
|
||||
var err error
|
||||
// run inside the tmpdir to validate that the default output dir
|
||||
|
|
@ -466,7 +465,6 @@ func TestBuildIntegrationArgs(t *testing.T) {
|
|||
|
||||
script := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
|
||||
err := main.Run()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -522,8 +520,7 @@ func TestBuildIntegrationErrorsProgressVerbose(t *testing.T) {
|
|||
})
|
||||
defer restore()
|
||||
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
|
||||
var err error
|
||||
stdout, stderr := testutil.CaptureStdio(t, func() {
|
||||
|
|
@ -563,8 +560,7 @@ echo "error on stdout"
|
|||
>&2 echo "error on stderr"
|
||||
exit 1
|
||||
`
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
|
||||
var err error
|
||||
stdout, _ := testutil.CaptureStdio(t, func() {
|
||||
|
|
@ -611,8 +607,7 @@ func TestBuildIntegrationErrorsProgressTerm(t *testing.T) {
|
|||
restore = main.MockOsArgs(cmd)
|
||||
defer restore()
|
||||
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", failingOsbuild)
|
||||
|
||||
var err error
|
||||
stdout, stderr := testutil.CaptureStdio(t, func() {
|
||||
|
|
@ -867,7 +862,6 @@ func TestBuildCrossArchSmoke(t *testing.T) {
|
|||
|
||||
script := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
|
||||
var err error
|
||||
_, stderr := testutil.CaptureStdio(t, func() {
|
||||
|
|
@ -925,8 +919,7 @@ func TestBuildIntegrationOutputFilename(t *testing.T) {
|
|||
defer restore()
|
||||
|
||||
script := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", script)
|
||||
|
||||
err := main.Run()
|
||||
assert.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -175,8 +175,7 @@ func TestBuildAndUploadWithAWSMock(t *testing.T) {
|
|||
|
||||
outputDir := t.TempDir()
|
||||
fakeOsbuildScript := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
|
||||
var fakeStdout bytes.Buffer
|
||||
restore = main.MockOsStdout(&fakeStdout)
|
||||
|
|
@ -224,8 +223,7 @@ func TestBuildAmiButNotUpload(t *testing.T) {
|
|||
|
||||
outputDir := t.TempDir()
|
||||
fakeOsbuildScript := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
|
||||
var fakeStdout bytes.Buffer
|
||||
restore = main.MockOsStdout(&fakeStdout)
|
||||
|
|
@ -255,8 +253,7 @@ func TestBuildAndUploadWithAWSPartialCmdlineErrors(t *testing.T) {
|
|||
|
||||
outputDir := t.TempDir()
|
||||
fakeOsbuildScript := makeFakeOsbuildScript()
|
||||
fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
defer fakeOsbuildCmd.Restore()
|
||||
testutil.MockCommand(t, "osbuild", fakeOsbuildScript)
|
||||
|
||||
restore := main.MockOsArgs([]string{
|
||||
"build",
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue