/
s3-client.go
217 lines (201 loc) · 6.55 KB
/
s3-client.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"context"
"github.com/ONSdigital/dp-cantabular-csv-exporter/handler"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"sync"
)
// Ensure, that S3ClientMock does implement handler.S3Client.
// If this is not the case, regenerate this file with moq.
var _ handler.S3Client = &S3ClientMock{}
// S3ClientMock is a mock implementation of handler.S3Client.
//
// func TestSomethingThatUsesS3Client(t *testing.T) {
//
// // make and configure a mocked handler.S3Client
// mockedS3Client := &S3ClientMock{
// BucketNameFunc: func() string {
// panic("mock out the BucketName method")
// },
// HeadFunc: func(key string) (*s3.HeadObjectOutput, error) {
// panic("mock out the Head method")
// },
// UploadWithContextFunc: func(ctx context.Context, input *s3manager.UploadInput, options ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) {
// panic("mock out the UploadWithContext method")
// },
// UploadWithPSKFunc: func(input *s3manager.UploadInput, psk []byte) (*s3manager.UploadOutput, error) {
// panic("mock out the UploadWithPSK method")
// },
// }
//
// // use mockedS3Client in code that requires handler.S3Client
// // and then make assertions.
//
// }
type S3ClientMock struct {
// BucketNameFunc mocks the BucketName method.
BucketNameFunc func() string
// HeadFunc mocks the Head method.
HeadFunc func(key string) (*s3.HeadObjectOutput, error)
// UploadWithContextFunc mocks the UploadWithContext method.
UploadWithContextFunc func(ctx context.Context, input *s3manager.UploadInput, options ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
// UploadWithPSKFunc mocks the UploadWithPSK method.
UploadWithPSKFunc func(input *s3manager.UploadInput, psk []byte) (*s3manager.UploadOutput, error)
// calls tracks calls to the methods.
calls struct {
// BucketName holds details about calls to the BucketName method.
BucketName []struct {
}
// Head holds details about calls to the Head method.
Head []struct {
// Key is the key argument value.
Key string
}
// UploadWithContext holds details about calls to the UploadWithContext method.
UploadWithContext []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Input is the input argument value.
Input *s3manager.UploadInput
// Options is the options argument value.
Options []func(*s3manager.Uploader)
}
// UploadWithPSK holds details about calls to the UploadWithPSK method.
UploadWithPSK []struct {
// Input is the input argument value.
Input *s3manager.UploadInput
// Psk is the psk argument value.
Psk []byte
}
}
lockBucketName sync.RWMutex
lockHead sync.RWMutex
lockUploadWithContext sync.RWMutex
lockUploadWithPSK sync.RWMutex
}
// BucketName calls BucketNameFunc.
func (mock *S3ClientMock) BucketName() string {
if mock.BucketNameFunc == nil {
panic("S3ClientMock.BucketNameFunc: method is nil but S3Client.BucketName was just called")
}
callInfo := struct {
}{}
mock.lockBucketName.Lock()
mock.calls.BucketName = append(mock.calls.BucketName, callInfo)
mock.lockBucketName.Unlock()
return mock.BucketNameFunc()
}
// BucketNameCalls gets all the calls that were made to BucketName.
// Check the length with:
// len(mockedS3Client.BucketNameCalls())
func (mock *S3ClientMock) BucketNameCalls() []struct {
} {
var calls []struct {
}
mock.lockBucketName.RLock()
calls = mock.calls.BucketName
mock.lockBucketName.RUnlock()
return calls
}
// Head calls HeadFunc.
func (mock *S3ClientMock) Head(key string) (*s3.HeadObjectOutput, error) {
if mock.HeadFunc == nil {
panic("S3ClientMock.HeadFunc: method is nil but S3Client.Head was just called")
}
callInfo := struct {
Key string
}{
Key: key,
}
mock.lockHead.Lock()
mock.calls.Head = append(mock.calls.Head, callInfo)
mock.lockHead.Unlock()
return mock.HeadFunc(key)
}
// HeadCalls gets all the calls that were made to Head.
// Check the length with:
// len(mockedS3Client.HeadCalls())
func (mock *S3ClientMock) HeadCalls() []struct {
Key string
} {
var calls []struct {
Key string
}
mock.lockHead.RLock()
calls = mock.calls.Head
mock.lockHead.RUnlock()
return calls
}
// UploadWithContext calls UploadWithContextFunc.
func (mock *S3ClientMock) UploadWithContext(ctx context.Context, input *s3manager.UploadInput, options ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) {
if mock.UploadWithContextFunc == nil {
panic("S3ClientMock.UploadWithContextFunc: method is nil but S3Client.UploadWithContext was just called")
}
callInfo := struct {
Ctx context.Context
Input *s3manager.UploadInput
Options []func(*s3manager.Uploader)
}{
Ctx: ctx,
Input: input,
Options: options,
}
mock.lockUploadWithContext.Lock()
mock.calls.UploadWithContext = append(mock.calls.UploadWithContext, callInfo)
mock.lockUploadWithContext.Unlock()
return mock.UploadWithContextFunc(ctx, input, options...)
}
// UploadWithContextCalls gets all the calls that were made to UploadWithContext.
// Check the length with:
// len(mockedS3Client.UploadWithContextCalls())
func (mock *S3ClientMock) UploadWithContextCalls() []struct {
Ctx context.Context
Input *s3manager.UploadInput
Options []func(*s3manager.Uploader)
} {
var calls []struct {
Ctx context.Context
Input *s3manager.UploadInput
Options []func(*s3manager.Uploader)
}
mock.lockUploadWithContext.RLock()
calls = mock.calls.UploadWithContext
mock.lockUploadWithContext.RUnlock()
return calls
}
// UploadWithPSK calls UploadWithPSKFunc.
func (mock *S3ClientMock) UploadWithPSK(input *s3manager.UploadInput, psk []byte) (*s3manager.UploadOutput, error) {
if mock.UploadWithPSKFunc == nil {
panic("S3ClientMock.UploadWithPSKFunc: method is nil but S3Client.UploadWithPSK was just called")
}
callInfo := struct {
Input *s3manager.UploadInput
Psk []byte
}{
Input: input,
Psk: psk,
}
mock.lockUploadWithPSK.Lock()
mock.calls.UploadWithPSK = append(mock.calls.UploadWithPSK, callInfo)
mock.lockUploadWithPSK.Unlock()
return mock.UploadWithPSKFunc(input, psk)
}
// UploadWithPSKCalls gets all the calls that were made to UploadWithPSK.
// Check the length with:
// len(mockedS3Client.UploadWithPSKCalls())
func (mock *S3ClientMock) UploadWithPSKCalls() []struct {
Input *s3manager.UploadInput
Psk []byte
} {
var calls []struct {
Input *s3manager.UploadInput
Psk []byte
}
mock.lockUploadWithPSK.RLock()
calls = mock.calls.UploadWithPSK
mock.lockUploadWithPSK.RUnlock()
return calls
}