-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathservice_discovery_test.go
57 lines (48 loc) · 1.72 KB
/
service_discovery_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
package main
import (
"github.com/stretchr/testify/mock"
)
// Mock
type ServiceDiscoveryMock struct {
mock.Mock
}
func (m *ServiceDiscoveryMock) GetScaleCalc(address, serviceName, scale string) (int, error) {
args := m.Called(address, serviceName, scale)
return args.Int(0), args.Error(1)
}
func (m *ServiceDiscoveryMock) GetNextColor(currentColor string) string {
args := m.Called(currentColor)
return args.String(0)
}
func (m *ServiceDiscoveryMock) GetColor(address, serviceName string) (string, error) {
args := m.Called(address, serviceName)
return args.String(0), args.Error(1)
}
func (m *ServiceDiscoveryMock) PutScale(address, serviceName string, value int) (string, error) {
args := m.Called(address, serviceName, value)
return args.String(0), args.Error(1)
}
func (m *ServiceDiscoveryMock) PutColor(address, serviceName, value string) (string, error) {
args := m.Called(address, serviceName, value)
return args.String(0), args.Error(1)
}
func getServiceDiscoveryMock(opts Opts, skipMethod string) *ServiceDiscoveryMock {
mockObj := new(ServiceDiscoveryMock)
scaleCalc := 5
if skipMethod != "GetScaleCalc" {
mockObj.On("GetScaleCalc", opts.ServiceDiscoveryAddress, opts.ServiceName, opts.Scale).Return(scaleCalc, nil)
}
if skipMethod != "PutScale" {
mockObj.On("PutScale", opts.ServiceDiscoveryAddress, opts.ServiceName, scaleCalc).Return("", nil)
}
if skipMethod != "GetColor" {
mockObj.On("GetColor", opts.ServiceDiscoveryAddress, opts.ServiceName).Return("orange", nil)
}
if skipMethod != "GetNextColor" {
mockObj.On("GetNextColor", opts.CurrentColor).Return("pink")
}
if skipMethod != "PutColor" {
mockObj.On("PutColor", mock.Anything, mock.Anything, mock.Anything).Return("", nil)
}
return mockObj
}