-
Notifications
You must be signed in to change notification settings - Fork 19
/
mock_agent.go
94 lines (72 loc) · 1.75 KB
/
mock_agent.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
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package upload
import (
"bytes"
"io"
"sync"
)
type MockAgent struct {
InboundFiles []File
ReconciliationFiles []File
ReturnFiles []File
UploadedFile *File // non-nil on file upload
DeletedFile string // filepath of last deleted file
mu sync.RWMutex // protects all fields
Err error
}
func (a *MockAgent) ID() string {
return "mock-agent"
}
func (a *MockAgent) GetInboundFiles() ([]File, error) {
a.mu.RLock()
defer a.mu.RUnlock()
return a.InboundFiles, nil
}
func (a *MockAgent) GetReconciliationFiles() ([]File, error) {
a.mu.RLock()
defer a.mu.RUnlock()
return a.ReconciliationFiles, nil
}
func (a *MockAgent) GetReturnFiles() ([]File, error) {
a.mu.RLock()
defer a.mu.RUnlock()
return a.ReturnFiles, nil
}
func (a *MockAgent) UploadFile(f File) error {
a.mu.Lock()
defer a.mu.Unlock()
// read f.contents before callers close the underlying os.Open file descriptor
bs, _ := io.ReadAll(f.Contents)
a.UploadedFile = &f
a.UploadedFile.Contents = io.NopCloser(bytes.NewReader(bs))
return nil
}
func (a *MockAgent) Delete(path string) error {
a.mu.Lock()
defer a.mu.Unlock()
a.DeletedFile = path
return nil
}
func (a *MockAgent) InboundPath() string {
return "inbound/"
}
func (a *MockAgent) OutboundPath() string {
return "outbound/"
}
func (a *MockAgent) ReconciliationPath() string {
return "reconciliation/"
}
func (a *MockAgent) ReturnPath() string {
return "return/"
}
func (a *MockAgent) Hostname() string {
return "hostname"
}
func (a *MockAgent) Ping() error {
return a.Err
}
func (a *MockAgent) Close() error {
return nil
}