-
Notifications
You must be signed in to change notification settings - Fork 18
/
module_mock.go
143 lines (130 loc) · 3.26 KB
/
module_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package modules
import (
"sync"
lua "github.com/yuin/gopher-lua"
)
// ModuleMock is a mock implementation of Module.
//
// func TestSomethingThatUsesModule(t *testing.T) {
//
// // make and configure a mocked Module
// mockedModule := &ModuleMock{
// GetLoaderFunc: func(j Job) lua.LGFunction {
// panic("mock out the GetLoader method")
// },
// NameFunc: func() string {
// panic("mock out the Name method")
// },
// StopFunc: func() error {
// panic("mock out the Stop method")
// },
// }
//
// // use mockedModule in code that requires Module
// // and then make assertions.
//
// }
type ModuleMock struct {
// GetLoaderFunc mocks the GetLoader method.
GetLoaderFunc func(j Job) lua.LGFunction
// NameFunc mocks the Name method.
NameFunc func() string
// StopFunc mocks the Stop method.
StopFunc func() error
// calls tracks calls to the methods.
calls struct {
// GetLoader holds details about calls to the GetLoader method.
GetLoader []struct {
// J is the j argument value.
J Job
}
// Name holds details about calls to the Name method.
Name []struct {
}
// Stop holds details about calls to the Stop method.
Stop []struct {
}
}
lockGetLoader sync.RWMutex
lockName sync.RWMutex
lockStop sync.RWMutex
}
// GetLoader calls GetLoaderFunc.
func (mock *ModuleMock) GetLoader(j Job) lua.LGFunction {
if mock.GetLoaderFunc == nil {
panic("ModuleMock.GetLoaderFunc: method is nil but Module.GetLoader was just called")
}
callInfo := struct {
J Job
}{
J: j,
}
mock.lockGetLoader.Lock()
mock.calls.GetLoader = append(mock.calls.GetLoader, callInfo)
mock.lockGetLoader.Unlock()
return mock.GetLoaderFunc(j)
}
// GetLoaderCalls gets all the calls that were made to GetLoader.
// Check the length with:
// len(mockedModule.GetLoaderCalls())
func (mock *ModuleMock) GetLoaderCalls() []struct {
J Job
} {
var calls []struct {
J Job
}
mock.lockGetLoader.RLock()
calls = mock.calls.GetLoader
mock.lockGetLoader.RUnlock()
return calls
}
// Name calls NameFunc.
func (mock *ModuleMock) Name() string {
if mock.NameFunc == nil {
panic("ModuleMock.NameFunc: method is nil but Module.Name was just called")
}
callInfo := struct {
}{}
mock.lockName.Lock()
mock.calls.Name = append(mock.calls.Name, callInfo)
mock.lockName.Unlock()
return mock.NameFunc()
}
// NameCalls gets all the calls that were made to Name.
// Check the length with:
// len(mockedModule.NameCalls())
func (mock *ModuleMock) NameCalls() []struct {
} {
var calls []struct {
}
mock.lockName.RLock()
calls = mock.calls.Name
mock.lockName.RUnlock()
return calls
}
// Stop calls StopFunc.
func (mock *ModuleMock) Stop() error {
if mock.StopFunc == nil {
panic("ModuleMock.StopFunc: method is nil but Module.Stop was just called")
}
callInfo := struct {
}{}
mock.lockStop.Lock()
mock.calls.Stop = append(mock.calls.Stop, callInfo)
mock.lockStop.Unlock()
return mock.StopFunc()
}
// StopCalls gets all the calls that were made to Stop.
// Check the length with:
// len(mockedModule.StopCalls())
func (mock *ModuleMock) StopCalls() []struct {
} {
var calls []struct {
}
mock.lockStop.RLock()
calls = mock.calls.Stop
mock.lockStop.RUnlock()
return calls
}