Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Commit 6e0ace3

Browse files
committed
Refactor out the need for bou.ke/monkey, see it's LICENSE
1 parent 16d02fd commit 6e0ace3

File tree

12 files changed

+12
-401
lines changed

12 files changed

+12
-401
lines changed

Gopkg.lock

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/xterrafile/util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ import (
2727
jww "github.com/spf13/jwalterweatherman"
2828
)
2929

30+
// Used to avoid monkey patching in tests
31+
var osExit = os.Exit
32+
3033
// CheckIfError should be used to naively panics if an error is not nil.
3134
func CheckIfError(moduleName string, err error) {
3235
if err == nil {
3336
return
3437
}
3538
jww.FATAL.Printf("[%s] %s", moduleName, err)
36-
os.Exit(1)
39+
osExit(1)
3740
}
3841

3942
// IContains is case-insensitive string contains check

pkg/xterrafile/util_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package xterrafile
33
import (
44
"bytes"
55
"errors"
6-
"os"
76
"testing"
87

9-
"bou.ke/monkey"
108
"github.com/stretchr/testify/assert"
119
"github.com/stretchr/testify/require"
1210

@@ -18,14 +16,15 @@ func TestCheckIfError(t *testing.T) {
1816
var outputBuf bytes.Buffer
1917
jww.SetStdoutOutput(&outputBuf)
2018

21-
// Patch exit to ensure it gets called on error
22-
fakeExit := func(int) {
23-
panic("os.Exit called")
19+
// override osExit to test for usage
20+
oldOsExit := osExit
21+
defer func() { osExit = oldOsExit }()
22+
myExit := func(code int) {
23+
panic("osExit called")
2424
}
25-
patch := monkey.Patch(os.Exit, fakeExit)
26-
defer patch.Unpatch()
25+
osExit = myExit
2726

28-
assert.PanicsWithValue(t, "os.Exit called",
27+
assert.PanicsWithValue(t, "osExit called",
2928
func() { CheckIfError("test-error", errors.New("A test Error")) }, "os.Exit should be called")
3029

3130
require.Contains(t, outputBuf.String(), "FATAL")

vendor/bou.ke/monkey/LICENSE.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

vendor/bou.ke/monkey/README.md

Lines changed: 0 additions & 112 deletions
This file was deleted.

vendor/bou.ke/monkey/circle.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

vendor/bou.ke/monkey/monkey.go

Lines changed: 0 additions & 133 deletions
This file was deleted.

vendor/bou.ke/monkey/monkey_386.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

vendor/bou.ke/monkey/monkey_amd64.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)