forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_service_repo.go
259 lines (207 loc) · 8.96 KB
/
fake_service_repo.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package fakes
import (
"strings"
"github.com/cloudfoundry/cli/cf/api/resources"
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/generic"
)
type FakeServiceRepo struct {
GetServiceOfferingByGuidReturns struct {
ServiceOffering models.ServiceOffering
Error error
}
GetAllServiceOfferingsReturns struct {
ServiceOfferings []models.ServiceOffering
Error error
}
GetServiceOfferingsForSpaceReturns struct {
ServiceOfferings []models.ServiceOffering
Error error
}
GetServiceOfferingsForSpaceArgs struct {
SpaceGuid string
}
FindServiceOfferingsForSpaceByLabelArgs struct {
SpaceGuid string
Name string
}
FindServiceOfferingsForSpaceByLabelReturns struct {
ServiceOfferings models.ServiceOfferings
Error error
}
CreateServiceInstanceArgs struct {
Name string
PlanGuid string
Params map[string]interface{}
Tags []string
}
CreateServiceInstanceReturns struct {
Error error
}
UpdateServiceInstanceArgs struct {
InstanceGuid string
PlanGuid string
Params map[string]interface{}
Tags []string
}
UpdateServiceInstanceReturnsErr bool
FindInstanceByNameName string
FindInstanceByNameServiceInstance models.ServiceInstance
FindInstanceByNameErr bool
FindInstanceByNameNotFound bool
FindInstanceByNameMap generic.Map
DeleteServiceServiceInstance models.ServiceInstance
RenameServiceServiceInstance models.ServiceInstance
RenameServiceNewName string
PurgedServiceOffering models.ServiceOffering
PurgeServiceOfferingCalled bool
PurgeServiceOfferingApiResponse error
FindServiceOfferingByLabelAndProviderName string
FindServiceOfferingByLabelAndProviderProvider string
FindServiceOfferingByLabelAndProviderServiceOffering models.ServiceOffering
FindServiceOfferingByLabelAndProviderApiResponse error
FindServiceOfferingByLabelAndProviderCalled bool
FindServiceOfferingsByLabelName string
FindServiceOfferingsByLabelServiceOfferings models.ServiceOfferings
FindServiceOfferingsByLabelApiResponse error
FindServiceOfferingsByLabelCalled bool
ListServicesFromManyBrokersReturns map[string][]models.ServiceOffering
ListServicesFromManyBrokersErr error
ListServicesFromBrokerReturns map[string][]models.ServiceOffering
ListServicesFromBrokerErr error
V1ServicePlanDescription resources.ServicePlanDescription
V2ServicePlanDescription resources.ServicePlanDescription
FindServicePlanByDescriptionArguments []resources.ServicePlanDescription
FindServicePlanByDescriptionResultGuids []string
FindServicePlanByDescriptionResponses []error
findServicePlanByDescriptionCallCount int
ServiceInstanceCountForServicePlan int
ServiceInstanceCountApiResponse error
V1GuidToMigrate string
V2GuidToMigrate string
MigrateServicePlanFromV1ToV2Called bool
MigrateServicePlanFromV1ToV2ReturnedCount int
MigrateServicePlanFromV1ToV2Response error
}
func (repo *FakeServiceRepo) GetServiceOfferingByGuid(guid string) (models.ServiceOffering, error) {
return repo.GetServiceOfferingByGuidReturns.ServiceOffering, repo.GetServiceOfferingByGuidReturns.Error
}
func (repo *FakeServiceRepo) GetAllServiceOfferings() (models.ServiceOfferings, error) {
return repo.GetAllServiceOfferingsReturns.ServiceOfferings, repo.GetAllServiceOfferingsReturns.Error
}
func (repo *FakeServiceRepo) GetServiceOfferingsForSpace(spaceGuid string) (models.ServiceOfferings, error) {
repo.GetServiceOfferingsForSpaceArgs.SpaceGuid = spaceGuid
return repo.GetServiceOfferingsForSpaceReturns.ServiceOfferings, repo.GetServiceOfferingsForSpaceReturns.Error
}
func (repo *FakeServiceRepo) FindServiceOfferingsForSpaceByLabel(spaceGuid, name string) (models.ServiceOfferings, error) {
repo.FindServiceOfferingsForSpaceByLabelArgs.Name = name
repo.FindServiceOfferingsForSpaceByLabelArgs.SpaceGuid = spaceGuid
return repo.FindServiceOfferingsForSpaceByLabelReturns.ServiceOfferings, repo.FindServiceOfferingsForSpaceByLabelReturns.Error
}
func (repo *FakeServiceRepo) PurgeServiceOffering(offering models.ServiceOffering) (apiErr error) {
repo.PurgedServiceOffering = offering
repo.PurgeServiceOfferingCalled = true
return repo.PurgeServiceOfferingApiResponse
}
func (repo *FakeServiceRepo) FindServiceOfferingByLabelAndProvider(name, provider string) (offering models.ServiceOffering, apiErr error) {
repo.FindServiceOfferingByLabelAndProviderCalled = true
repo.FindServiceOfferingByLabelAndProviderName = name
repo.FindServiceOfferingByLabelAndProviderProvider = provider
apiErr = repo.FindServiceOfferingByLabelAndProviderApiResponse
offering = repo.FindServiceOfferingByLabelAndProviderServiceOffering
return
}
func (repo *FakeServiceRepo) FindServiceOfferingsByLabel(name string) (offerings models.ServiceOfferings, apiErr error) {
repo.FindServiceOfferingsByLabelCalled = true
repo.FindServiceOfferingsByLabelName = name
apiErr = repo.FindServiceOfferingsByLabelApiResponse
offerings = repo.FindServiceOfferingsByLabelServiceOfferings
return
}
func (repo *FakeServiceRepo) CreateServiceInstance(name, planGuid string, params map[string]interface{}, tags []string) (apiErr error) {
repo.CreateServiceInstanceArgs.Name = name
repo.CreateServiceInstanceArgs.PlanGuid = planGuid
repo.CreateServiceInstanceArgs.Params = params
repo.CreateServiceInstanceArgs.Tags = tags
return repo.CreateServiceInstanceReturns.Error
}
func (repo *FakeServiceRepo) UpdateServiceInstance(instanceGuid, planGuid string, params map[string]interface{}, tags []string) (apiErr error) {
if repo.UpdateServiceInstanceReturnsErr {
apiErr = errors.New("Error updating service instance")
} else {
repo.UpdateServiceInstanceArgs.InstanceGuid = instanceGuid
repo.UpdateServiceInstanceArgs.PlanGuid = planGuid
repo.UpdateServiceInstanceArgs.Params = params
repo.UpdateServiceInstanceArgs.Tags = tags
}
return
}
func (repo *FakeServiceRepo) FindInstanceByName(name string) (instance models.ServiceInstance, apiErr error) {
repo.FindInstanceByNameName = name
if repo.FindInstanceByNameMap != nil && repo.FindInstanceByNameMap.Has(name) {
instance = repo.FindInstanceByNameMap.Get(name).(models.ServiceInstance)
} else {
instance = repo.FindInstanceByNameServiceInstance
}
if repo.FindInstanceByNameErr {
apiErr = errors.New("Error finding instance")
}
if repo.FindInstanceByNameNotFound {
apiErr = errors.NewModelNotFoundError("Service instance", name)
}
return
}
func (repo *FakeServiceRepo) DeleteService(instance models.ServiceInstance) (apiErr error) {
repo.DeleteServiceServiceInstance = instance
return
}
func (repo *FakeServiceRepo) RenameService(instance models.ServiceInstance, newName string) (apiErr error) {
repo.RenameServiceServiceInstance = instance
repo.RenameServiceNewName = newName
return
}
func (repo *FakeServiceRepo) FindServicePlanByDescription(planDescription resources.ServicePlanDescription) (planGuid string, apiErr error) {
repo.FindServicePlanByDescriptionArguments =
append(repo.FindServicePlanByDescriptionArguments, planDescription)
if len(repo.FindServicePlanByDescriptionResultGuids) > repo.findServicePlanByDescriptionCallCount {
planGuid = repo.FindServicePlanByDescriptionResultGuids[repo.findServicePlanByDescriptionCallCount]
}
if len(repo.FindServicePlanByDescriptionResponses) > repo.findServicePlanByDescriptionCallCount {
apiErr = repo.FindServicePlanByDescriptionResponses[repo.findServicePlanByDescriptionCallCount]
}
repo.findServicePlanByDescriptionCallCount += 1
return
}
func (repo *FakeServiceRepo) ListServicesFromManyBrokers(brokerGuids []string) ([]models.ServiceOffering, error) {
if repo.ListServicesFromManyBrokersErr != nil {
return nil, repo.ListServicesFromManyBrokersErr
}
key := strings.Join(brokerGuids, ",")
if repo.ListServicesFromManyBrokersReturns[key] != nil {
return repo.ListServicesFromManyBrokersReturns[key], nil
}
return []models.ServiceOffering{}, nil
}
func (repo *FakeServiceRepo) ListServicesFromBroker(brokerGuid string) ([]models.ServiceOffering, error) {
if repo.ListServicesFromBrokerErr != nil {
return nil, repo.ListServicesFromBrokerErr
}
if repo.ListServicesFromBrokerReturns[brokerGuid] != nil {
return repo.ListServicesFromBrokerReturns[brokerGuid], nil
}
return []models.ServiceOffering{}, nil
}
func (repo *FakeServiceRepo) GetServiceInstanceCountForServicePlan(v1PlanGuid string) (count int, apiErr error) {
count = repo.ServiceInstanceCountForServicePlan
apiErr = repo.ServiceInstanceCountApiResponse
return
}
func (repo *FakeServiceRepo) MigrateServicePlanFromV1ToV2(v1PlanGuid, v2PlanGuid string) (changedCount int, apiErr error) {
repo.MigrateServicePlanFromV1ToV2Called = true
repo.V1GuidToMigrate = v1PlanGuid
repo.V2GuidToMigrate = v2PlanGuid
changedCount = repo.MigrateServicePlanFromV1ToV2ReturnedCount
apiErr = repo.MigrateServicePlanFromV1ToV2Response
return
}