forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_service_plan_repo.go
96 lines (81 loc) · 2.26 KB
/
fake_service_plan_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
package fakes
import (
"sort"
"strings"
"sync"
"github.com/cloudfoundry/cli/cf/models"
)
type FakeServicePlanRepo struct {
SearchReturns map[string][]models.ServicePlanFields
SearchErr error
UpdateStub func(models.ServicePlanFields, string, bool) error
updateMutex sync.RWMutex
updateArgsForCall []struct {
arg1 models.ServicePlanFields
arg2 string
arg3 bool
}
updateReturns struct {
result1 error
}
}
func (fake *FakeServicePlanRepo) Search(queryParams map[string]string) ([]models.ServicePlanFields, error) {
if fake.SearchErr != nil {
return nil, fake.SearchErr
}
if queryParams == nil {
//return everything
var returnPlans []models.ServicePlanFields
for _, value := range fake.SearchReturns {
returnPlans = append(returnPlans, value...)
}
return returnPlans, nil
}
searchKey := combineKeys(queryParams)
if fake.SearchReturns[searchKey] != nil {
return fake.SearchReturns[searchKey], nil
}
return []models.ServicePlanFields{}, nil
}
func combineKeys(mapToCombine map[string]string) string {
keys := []string{}
for key, _ := range mapToCombine {
keys = append(keys, key)
}
sort.Strings(keys)
values := []string{}
for _, key := range keys {
values = append(values, mapToCombine[key])
}
return strings.Join(values, ":")
}
func (fake *FakeServicePlanRepo) Update(arg1 models.ServicePlanFields, arg2 string, arg3 bool) error {
fake.updateMutex.Lock()
defer fake.updateMutex.Unlock()
fake.updateArgsForCall = append(fake.updateArgsForCall, struct {
arg1 models.ServicePlanFields
arg2 string
arg3 bool
}{arg1, arg2, arg3})
if fake.UpdateStub != nil {
return fake.UpdateStub(arg1, arg2, arg3)
} else {
return fake.updateReturns.result1
}
}
func (fake *FakeServicePlanRepo) UpdateCallCount() int {
fake.updateMutex.RLock()
defer fake.updateMutex.RUnlock()
return len(fake.updateArgsForCall)
}
func (fake *FakeServicePlanRepo) UpdateArgsForCall(i int) (models.ServicePlanFields, string, bool) {
fake.updateMutex.RLock()
defer fake.updateMutex.RUnlock()
return fake.updateArgsForCall[i].arg1, fake.updateArgsForCall[i].arg2, fake.updateArgsForCall[i].arg3
}
func (fake *FakeServicePlanRepo) UpdateReturns(result1 error) {
fake.UpdateStub = nil
fake.updateReturns = struct {
result1 error
}{result1}
}