forked from openshift/route-monitor-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.go
More file actions
48 lines (45 loc) · 1.03 KB
/
helper.go
File metadata and controls
48 lines (45 loc) · 1.03 KB
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
package helper
import (
consterror "github.com/openshift/route-monitor-operator/pkg/consts/test/error"
)
// MockHelper is a struct that makes using mocks easier
// without MockHelper we needed to have two fields on every fuction we wanted to mock
//
// for example:
//
// var (
//
// getCalledTimes int
// getErrorResponse error
//
// )
//
// BeforeEach(func() {
// getCalledTimes = 0
// getErrorResponse = nil
// }
//
// JustBeforeEach(func() {
// mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).
// Return(getErrorResponse).
// Times(getCalledTimes)
// }
//
// this made the tests full of variables that were used separately
// by joining them into one struct, a more unified way was introduced
type MockHelper struct {
CalledTimes int
ErrorResponse error
}
func NotFoundErrorHappensOnce() MockHelper {
return MockHelper{
CalledTimes: 1,
ErrorResponse: consterror.NotFoundErr,
}
}
func CustomErrorHappensOnce() MockHelper {
return MockHelper{
CalledTimes: 1,
ErrorResponse: consterror.ErrCustomError,
}
}