/
filesservice.go
137 lines (127 loc) · 3.84 KB
/
filesservice.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
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"context"
"github.com/ONSdigital/dp-healthcheck/healthcheck"
"github.com/ONSdigital/dp-static-file-publisher/file"
"sync"
)
// Ensure, that FilesServiceMock does implement file.FilesService.
// If this is not the case, regenerate this file with moq.
var _ file.FilesService = &FilesServiceMock{}
// FilesServiceMock is a mock implementation of file.FilesService.
//
// func TestSomethingThatUsesFilesService(t *testing.T) {
//
// // make and configure a mocked file.FilesService
// mockedFilesService := &FilesServiceMock{
// CheckerFunc: func(ctx context.Context, state *healthcheck.CheckState) error {
// panic("mock out the Checker method")
// },
// MarkFileMovedFunc: func(ctx context.Context, path string, etag string) error {
// panic("mock out the MarkFileMoved method")
// },
// }
//
// // use mockedFilesService in code that requires file.FilesService
// // and then make assertions.
//
// }
type FilesServiceMock struct {
// CheckerFunc mocks the Checker method.
CheckerFunc func(ctx context.Context, state *healthcheck.CheckState) error
// MarkFileMovedFunc mocks the MarkFileMoved method.
MarkFileMovedFunc func(ctx context.Context, path string, etag string) error
// calls tracks calls to the methods.
calls struct {
// Checker holds details about calls to the Checker method.
Checker []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// State is the state argument value.
State *healthcheck.CheckState
}
// MarkFileMoved holds details about calls to the MarkFileMoved method.
MarkFileMoved []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Path is the path argument value.
Path string
// Etag is the etag argument value.
Etag string
}
}
lockChecker sync.RWMutex
lockMarkFileMoved sync.RWMutex
}
// Checker calls CheckerFunc.
func (mock *FilesServiceMock) Checker(ctx context.Context, state *healthcheck.CheckState) error {
if mock.CheckerFunc == nil {
panic("FilesServiceMock.CheckerFunc: method is nil but FilesService.Checker was just called")
}
callInfo := struct {
Ctx context.Context
State *healthcheck.CheckState
}{
Ctx: ctx,
State: state,
}
mock.lockChecker.Lock()
mock.calls.Checker = append(mock.calls.Checker, callInfo)
mock.lockChecker.Unlock()
return mock.CheckerFunc(ctx, state)
}
// CheckerCalls gets all the calls that were made to Checker.
// Check the length with:
// len(mockedFilesService.CheckerCalls())
func (mock *FilesServiceMock) CheckerCalls() []struct {
Ctx context.Context
State *healthcheck.CheckState
} {
var calls []struct {
Ctx context.Context
State *healthcheck.CheckState
}
mock.lockChecker.RLock()
calls = mock.calls.Checker
mock.lockChecker.RUnlock()
return calls
}
// MarkFileMoved calls MarkFileMovedFunc.
func (mock *FilesServiceMock) MarkFileMoved(ctx context.Context, path string, etag string) error {
if mock.MarkFileMovedFunc == nil {
panic("FilesServiceMock.MarkFileMovedFunc: method is nil but FilesService.MarkFileMoved was just called")
}
callInfo := struct {
Ctx context.Context
Path string
Etag string
}{
Ctx: ctx,
Path: path,
Etag: etag,
}
mock.lockMarkFileMoved.Lock()
mock.calls.MarkFileMoved = append(mock.calls.MarkFileMoved, callInfo)
mock.lockMarkFileMoved.Unlock()
return mock.MarkFileMovedFunc(ctx, path, etag)
}
// MarkFileMovedCalls gets all the calls that were made to MarkFileMoved.
// Check the length with:
// len(mockedFilesService.MarkFileMovedCalls())
func (mock *FilesServiceMock) MarkFileMovedCalls() []struct {
Ctx context.Context
Path string
Etag string
} {
var calls []struct {
Ctx context.Context
Path string
Etag string
}
mock.lockMarkFileMoved.RLock()
calls = mock.calls.MarkFileMoved
mock.lockMarkFileMoved.RUnlock()
return calls
}