-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
67 lines (61 loc) · 1.63 KB
/
helpers_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
58
59
60
61
62
63
64
65
66
67
package cloudfoundry
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
"fmt"
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
"net/http"
)
type HelpersTest struct {
session *managers.Session
}
func (h HelpersTest) ForceDeleteServiceBroker(serviceBrokerID string) (err error) {
services, _, err := h.session.ClientV2.GetServices(ccv2.Filter{
Values: []string{serviceBrokerID},
Operator: constant.EqualOperator,
Type: constant.ServiceBrokerGUIDFilter,
})
if err != nil {
return err
}
for _, s := range services {
plans, _, err := h.session.ClientV2.GetServicePlans(ccv2.Filter{
Values: []string{s.GUID},
Operator: constant.EqualOperator,
Type: constant.ServiceGUIDFilter,
})
if err != nil {
return err
}
for _, sp := range plans {
instances, _, err := h.session.ClientV2.GetServiceInstances(ccv2.Filter{
Values: []string{sp.GUID},
Operator: constant.EqualOperator,
Type: constant.ServicePlanGUIDFilter,
})
if err != nil {
return err
}
for _, i := range instances {
req, err := h.session.RawClient.NewRequest(
http.MethodDelete,
fmt.Sprintf("/v2/service_instances/%s?purge=true", i.GUID),
nil,
)
if err != nil {
panic(err)
}
resp, err := h.session.RawClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 || resp.StatusCode < 200 {
return fmt.Errorf(resp.Status)
}
}
}
}
_, err = h.session.ClientV2.DeleteServiceBroker(serviceBrokerID)
return err
}