/
file_helper_mock.go
40 lines (37 loc) · 1 KB
/
file_helper_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
package mocks
// FileHelperMock mock-impl of FileHelper-interface
type FileHelperMock struct {
ExistsCall struct {
Receives struct {
Paths []string
}
Returns map[string]bool
DefaultReturn bool
}
WriteCall struct {
Receives struct {
Path string
Data string
}
Returns struct {
Error error
}
}
}
// Exists records callers arguments in ExistsCall.Receives and Returns values of ExistsCall.Returns based on given path.
// if path not found it returns ExistsCall.DefaultReturn
func (fh *FileHelperMock) Exists(path string) bool {
if fh.ExistsCall.Receives.Paths == nil {
fh.ExistsCall.Receives.Paths = []string{}
}
fh.ExistsCall.Receives.Paths = append(fh.ExistsCall.Receives.Paths, path)
if returnBool, found := fh.ExistsCall.Returns[path]; found {
return returnBool
}
return fh.ExistsCall.DefaultReturn
}
func (fh *FileHelperMock) Write(path string, data string) error {
fh.WriteCall.Receives.Path = path
fh.WriteCall.Receives.Data = data
return fh.WriteCall.Returns.Error
}