/
lambda_moq.go
142 lines (132 loc) · 4.49 KB
/
lambda_moq.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
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package citlambda
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"sync"
)
// Ensure, that LambdaInterfaceMock does implement LambdaInterface.
// If this is not the case, regenerate this file with moq.
var _ LambdaInterface = &LambdaInterfaceMock{}
// LambdaInterfaceMock is a mock implementation of LambdaInterface.
//
// func TestSomethingThatUsesLambdaInterface(t *testing.T) {
//
// // make and configure a mocked LambdaInterface
// mockedLambdaInterface := &LambdaInterfaceMock{
// GetFunctionFunc: func(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error) {
// panic("mock out the GetFunction method")
// },
// InvokeFunc: func(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error) {
// panic("mock out the Invoke method")
// },
// }
//
// // use mockedLambdaInterface in code that requires LambdaInterface
// // and then make assertions.
//
// }
type LambdaInterfaceMock struct {
// GetFunctionFunc mocks the GetFunction method.
GetFunctionFunc func(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error)
// InvokeFunc mocks the Invoke method.
InvokeFunc func(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error)
// calls tracks calls to the methods.
calls struct {
// GetFunction holds details about calls to the GetFunction method.
GetFunction []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Params is the params argument value.
Params *lambda.GetFunctionInput
// OptFns is the optFns argument value.
OptFns []func(*lambda.Options)
}
// Invoke holds details about calls to the Invoke method.
Invoke []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Params is the params argument value.
Params *lambda.InvokeInput
// OptFns is the optFns argument value.
OptFns []func(*lambda.Options)
}
}
lockGetFunction sync.RWMutex
lockInvoke sync.RWMutex
}
// GetFunction calls GetFunctionFunc.
func (mock *LambdaInterfaceMock) GetFunction(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error) {
if mock.GetFunctionFunc == nil {
panic("LambdaInterfaceMock.GetFunctionFunc: method is nil but LambdaInterface.GetFunction was just called")
}
callInfo := struct {
Ctx context.Context
Params *lambda.GetFunctionInput
OptFns []func(*lambda.Options)
}{
Ctx: ctx,
Params: params,
OptFns: optFns,
}
mock.lockGetFunction.Lock()
mock.calls.GetFunction = append(mock.calls.GetFunction, callInfo)
mock.lockGetFunction.Unlock()
return mock.GetFunctionFunc(ctx, params, optFns...)
}
// GetFunctionCalls gets all the calls that were made to GetFunction.
// Check the length with:
// len(mockedLambdaInterface.GetFunctionCalls())
func (mock *LambdaInterfaceMock) GetFunctionCalls() []struct {
Ctx context.Context
Params *lambda.GetFunctionInput
OptFns []func(*lambda.Options)
} {
var calls []struct {
Ctx context.Context
Params *lambda.GetFunctionInput
OptFns []func(*lambda.Options)
}
mock.lockGetFunction.RLock()
calls = mock.calls.GetFunction
mock.lockGetFunction.RUnlock()
return calls
}
// Invoke calls InvokeFunc.
func (mock *LambdaInterfaceMock) Invoke(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error) {
if mock.InvokeFunc == nil {
panic("LambdaInterfaceMock.InvokeFunc: method is nil but LambdaInterface.Invoke was just called")
}
callInfo := struct {
Ctx context.Context
Params *lambda.InvokeInput
OptFns []func(*lambda.Options)
}{
Ctx: ctx,
Params: params,
OptFns: optFns,
}
mock.lockInvoke.Lock()
mock.calls.Invoke = append(mock.calls.Invoke, callInfo)
mock.lockInvoke.Unlock()
return mock.InvokeFunc(ctx, params, optFns...)
}
// InvokeCalls gets all the calls that were made to Invoke.
// Check the length with:
// len(mockedLambdaInterface.InvokeCalls())
func (mock *LambdaInterfaceMock) InvokeCalls() []struct {
Ctx context.Context
Params *lambda.InvokeInput
OptFns []func(*lambda.Options)
} {
var calls []struct {
Ctx context.Context
Params *lambda.InvokeInput
OptFns []func(*lambda.Options)
}
mock.lockInvoke.RLock()
calls = mock.calls.Invoke
mock.lockInvoke.RUnlock()
return calls
}