-
Notifications
You must be signed in to change notification settings - Fork 13
/
mocksubscription.go
127 lines (108 loc) · 3.95 KB
/
mocksubscription.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
package apic
import "fmt"
// TODO - this file should be able to be removed once Unified Catalog support has been removed
// MockSubscription - use for ease of testing agents
type MockSubscription struct {
Subscription
ID string
Description string
Name string
ApicID string
RemoteAPIID string
RemoteAPIStage string
CatalogID string
UserID string
State SubscriptionState
PropertyVals map[string]interface{}
ReceivedValues map[string]interface{}
RemoteAPIAttributes map[string]string
ReceivedAppName string
ReceivedUpdatedEnum string
UpdateStateErr error
UpdateEnumErr error
UpdatePropertiesErr error
UpdatePropertyValErr error
UpdateStateWithPropertiesErr error
}
//GetID - mocked for testing
func (s *MockSubscription) GetID() string { return s.ID }
//GetName - mocked for testing
func (s *MockSubscription) GetName() string { return s.Name }
//GetApicID - mocked for testing
func (s *MockSubscription) GetApicID() string { return s.ApicID }
//GetRemoteAPIID - mocked for testing
func (s *MockSubscription) GetRemoteAPIID() string { return s.RemoteAPIID }
// GetRemoteAPIAttributes - mocked for testing
func (s *MockSubscription) GetRemoteAPIAttributes() map[string]string { return s.RemoteAPIAttributes }
//GetRemoteAPIStage - mocked for testing
func (s *MockSubscription) GetRemoteAPIStage() string { return s.RemoteAPIStage }
//GetCatalogItemID - mocked for testing
func (s *MockSubscription) GetCatalogItemID() string { return s.CatalogID }
//GetCreatedUserID - mocked for testing
func (s *MockSubscription) GetCreatedUserID() string { return s.UserID }
//GetState - mocked for testing
func (s *MockSubscription) GetState() SubscriptionState { return s.State }
//GetPropertyValue - mocked for testing
func (s *MockSubscription) GetPropertyValue(propertyKey string) string {
if s.PropertyVals[propertyKey] != nil {
return fmt.Sprintf("%v", s.PropertyVals[propertyKey])
}
return ""
}
//GetPropertyValues - mocked for testing
func (s *MockSubscription) GetPropertyValues(propertyKey string) []interface{} {
if valueI, ok := s.PropertyVals[propertyKey]; ok {
if valueC, isArray := valueI.([]float64); isArray {
values := []interface{}{}
for _, v := range valueC {
values = append(values, v)
}
return values
} else if valueC, isArrayOfMap := valueI.([]map[string]interface{}); isArrayOfMap {
values := []interface{}{}
for _, v := range valueC {
values = append(values, v)
}
return values
}
}
return nil
}
//UpdateState - mocked for testing
func (s *MockSubscription) UpdateState(newState SubscriptionState, description string) error {
if s.UpdateStateErr == nil {
s.State = newState
s.Description = description
}
return s.UpdateStateErr
}
//UpdateEnumProperty - mocked for testing
func (s *MockSubscription) UpdateEnumProperty(key, value, dataType string) error {
if s.UpdateEnumErr == nil {
s.ReceivedUpdatedEnum = fmt.Sprintf("%v---%v---%v", key, value, dataType)
}
return s.UpdateEnumErr
}
//UpdateProperties - mocked for testing
func (s *MockSubscription) UpdateProperties(appName string) error {
if s.UpdatePropertiesErr == nil {
s.ReceivedAppName = appName
}
return s.UpdatePropertiesErr
}
//UpdatePropertyValues - mocked for testing
func (s *MockSubscription) UpdatePropertyValues(values map[string]interface{}) error {
if s.UpdatePropertyValErr == nil {
s.ReceivedValues = values
}
return s.UpdatePropertyValErr
}
// UpdateStateWithProperties - mocked for testing
func (s *MockSubscription) UpdateStateWithProperties(newState SubscriptionState, _ string, props map[string]interface{}) error {
if s.UpdateStateWithPropertiesErr == nil {
s.State = newState
s.ReceivedValues = props
return nil
}
return s.UpdateStateWithPropertiesErr
}