-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_helper_test.go
169 lines (136 loc) · 3.51 KB
/
test_helper_test.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
package main
import (
"net/http"
"github.com/stretchr/testify/mock"
)
/* Mocked calls for running system commands */
type MockRunner struct {
mock.Mock
}
func (r *MockRunner) Run(command string, args ...string) (string, error) {
// weird way to get around passing in just args to the helper
pa := []string{}
pa = append(pa, args...)
_args := r.Mock.Called(command, pa)
return _args.String(0), _args.Error(1)
}
func (r *MockRunner) RunBytes(command string, args ...string) ([]byte, error) {
pa := []string{}
pa = append(pa, args...)
_args := r.Mock.Called(command, pa)
return []byte(_args.String(0)), _args.Error(1)
}
/* Mock writer for writing to files */
type MockWriter struct {
mock.Mock
}
func (r *MockWriter) AppendToFile(path string, contents string) {
r.Mock.Called(path, contents)
return
}
/* Mocked calls for reading files and checking if files exist */
type MockReader struct {
mock.Mock
}
func (r *MockReader) ReadFile(path string) ([]byte, error) {
args := r.Mock.Called(path)
return args.Get(0).([]byte), args.Error(1)
}
func (r *MockReader) FileExists(path string) bool {
args := r.Mock.Called(path)
return args.Bool(0)
}
/* Mock package manager calls */
type MockPackageManager struct {
mock.Mock
}
func (r *MockPackageManager) UpdatePackage(name string) error {
args := r.Mock.Called(name)
return args.Error(0)
}
func (r *MockPackageManager) HoldPackage(name string) error {
args := r.Mock.Called(name)
return args.Error(0)
}
func (r *MockPackageManager) UnholdPackage(name string) error {
args := r.Mock.Called(name)
return args.Error(0)
}
func (r *MockPackageManager) BuildPackageList() []OsPackage {
args := r.Mock.Called()
return args.Get(0).([]OsPackage)
}
func (r *MockPackageManager) GetSourcesList() []Source {
args := r.Mock.Called()
return args.Get(0).([]Source)
}
func (r *MockPackageManager) GetChangelog(name string) string {
args := r.Mock.Called(name)
return args.String(0)
}
func (r *MockPackageManager) BuildInstalledPackageList() []string {
args := r.Mock.Called()
return args.Get(0).([]string)
}
func (r *MockPackageManager) UpdatePackageLists() error {
args := r.Mock.Called()
return args.Error(0)
}
func (r *MockPackageManager) UpdateCounts() Updates {
args := r.Mock.Called()
return args.Get(0).(Updates)
}
/* Mock WebAPI calls */
type MockSyswardApi struct {
mock.Mock
httpClient *http.Client
}
func (r *MockSyswardApi) JobFailure(job Job, error_string string) {
r.Mock.Called(job, error_string)
return
}
func (r *MockSyswardApi) JobPostBack(job Job) {
r.Mock.Called(job)
return
}
func (r *MockSyswardApi) CheckIn(agentData AgentData) error {
args := r.Mock.Called(agentData)
return args.Error(0)
}
func (r *MockSyswardApi) GetJobs() string {
args := r.Mock.Called()
return args.String(0)
}
/* Mock Config calls */
type MockConfig struct {
mock.Mock
config ConfigSettings
}
func (c *MockConfig) Config() ConfigSettings {
args := c.Mock.Called()
return args.Get(0).(ConfigSettings)
}
func (c *MockConfig) SetProtocol(protocol string) {
c.Mock.Called(protocol)
return
}
func (c *MockConfig) agentPingUrl() string {
args := c.Mock.Called()
return args.String(0)
}
func (c *MockConfig) unregisterAgentUrl() string {
args := c.Mock.Called()
return args.String(0)
}
func (c *MockConfig) fetchJobUrl(uid string) string {
args := c.Mock.Called(uid)
return args.String(0)
}
func (c *MockConfig) fetchJobPostbackUrl() string {
args := c.Mock.Called()
return args.String(0)
}
func (c *MockConfig) agentCheckinUrl() string {
args := c.Mock.Called()
return args.String(0)
}