-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocktest_test.go
70 lines (54 loc) · 1.32 KB
/
mocktest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package awsmocker_test
import (
"fmt"
"github.com/webdestroya/awsmocker"
)
// A fake testing.T object used for testing the test
type TestingMock struct {
og awsmocker.TestingT
failed bool
errored bool
logged bool
helperCalled bool
errorMessages []string
logMessages []string
envvars map[string]string
}
func NewTestingMock(og awsmocker.TestingT) *TestingMock {
return &TestingMock{
og: og,
envvars: make(map[string]string),
logMessages: make([]string, 0),
errorMessages: make([]string, 0),
}
}
func (tm *TestingMock) Cleanup(f func()) {
tm.og.Cleanup(f)
}
func (tm *TestingMock) Errorf(f string, args ...any) {
tm.errored = true
tm.errorMessages = append(tm.errorMessages, fmt.Sprintf(f, args...))
}
func (tm *TestingMock) Logf(f string, args ...any) {
tm.logged = true
tm.logMessages = append(tm.logMessages, fmt.Sprintf(f, args...))
}
func (tm *TestingMock) Fail() {
tm.failed = true
}
func (tm *TestingMock) Setenv(k, v string) {
tm.envvars[k] = v
tm.og.Setenv(k, v)
}
func (tm *TestingMock) TempDir() string {
return tm.og.TempDir()
}
func (tm *TestingMock) Helper() {
tm.helperCalled = true
if h, ok := tm.og.(awsmocker.THelper); ok {
h.Helper()
}
}
// interface adherence
var _ = (awsmocker.TestingT)(&TestingMock{})
var _ = (awsmocker.THelper)(&TestingMock{})