forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_service_broker_repo.go
95 lines (77 loc) · 2.29 KB
/
fake_service_broker_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
package api
import (
"cf"
"cf/net"
)
type FakeServiceBrokerRepo struct {
FindByNameName string
FindByNameServiceBroker cf.ServiceBroker
FindByNameNotFound bool
CreateName string
CreateUrl string
CreateUsername string
CreatePassword string
UpdatedServiceBroker cf.ServiceBroker
RenamedServiceBrokerGuid string
RenamedServiceBrokerName string
DeletedServiceBrokerGuid string
ServiceBrokers []cf.ServiceBroker
ListErr bool
}
func (repo *FakeServiceBrokerRepo) FindByName(name string) (serviceBroker cf.ServiceBroker, apiResponse net.ApiResponse) {
repo.FindByNameName = name
serviceBroker = repo.FindByNameServiceBroker
if repo.FindByNameNotFound {
apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Service Broker", name)
}
return
}
func (repo *FakeServiceBrokerRepo) ListServiceBrokers(stop chan bool) (serviceBrokersChan chan []cf.ServiceBroker, statusChan chan net.ApiResponse) {
serviceBrokersChan = make(chan []cf.ServiceBroker, 4)
statusChan = make(chan net.ApiResponse, 1)
if repo.ListErr {
statusChan <- net.NewApiResponseWithMessage("Error finding all routes")
close(serviceBrokersChan)
close(statusChan)
return
}
go func() {
serviceBrokersCount := len(repo.ServiceBrokers)
for i := 0; i < serviceBrokersCount; i += 2 {
select {
case <-stop:
break
default:
if serviceBrokersCount-i > 1 {
serviceBrokersChan <- repo.ServiceBrokers[i : i+2]
} else {
serviceBrokersChan <- repo.ServiceBrokers[i:]
}
}
}
close(serviceBrokersChan)
close(statusChan)
cf.WaitForClose(stop)
}()
return
}
func (repo *FakeServiceBrokerRepo) Create(name, url, username, password string) (apiResponse net.ApiResponse) {
repo.CreateName = name
repo.CreateUrl = url
repo.CreateUsername = username
repo.CreatePassword = password
return
}
func (repo *FakeServiceBrokerRepo) Update(serviceBroker cf.ServiceBroker) (apiResponse net.ApiResponse) {
repo.UpdatedServiceBroker = serviceBroker
return
}
func (repo *FakeServiceBrokerRepo) Rename(guid, name string) (apiResponse net.ApiResponse) {
repo.RenamedServiceBrokerGuid = guid
repo.RenamedServiceBrokerName = name
return
}
func (repo *FakeServiceBrokerRepo) Delete(guid string) (apiResponse net.ApiResponse) {
repo.DeletedServiceBrokerGuid = guid
return
}