forked from wallix/awless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
56 lines (47 loc) · 1.04 KB
/
mock.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
package awsat
import (
"reflect"
"testing"
)
type mock interface {
Calls() map[string]int
SetInputs(map[string]interface{})
SetIgnored(map[string]struct{})
SetTesting(*testing.T)
}
type basicMock struct {
t *testing.T
calls map[string]int
expInputs map[string]interface{}
ignoredInputs map[string]struct{}
}
func (m *basicMock) addCall(call string) {
if m.calls == nil {
m.calls = make(map[string]int)
}
m.calls[call]++
}
func (m *basicMock) Calls() map[string]int {
return m.calls
}
func (m *basicMock) SetTesting(t *testing.T) {
m.t = t
}
func (m *basicMock) SetInputs(inputs map[string]interface{}) {
m.expInputs = inputs
}
func (m *basicMock) SetIgnored(ignored map[string]struct{}) {
m.ignoredInputs = ignored
}
func (m *basicMock) verifyInput(call string, got interface{}) {
m.t.Helper()
if m.expInputs == nil {
return
}
if _, isIgnored := m.ignoredInputs[call]; isIgnored {
return
}
if want := m.expInputs[call]; !reflect.DeepEqual(want, got) {
m.t.Fatalf("got %#v, want %#v", got, want)
}
}