Merge lp:~rvb/gwacl/listhostedservices-2 into lp:gwacl

Proposed by Raphaël Badin on 2013-07-04
Status: Merged
Approved by: Raphaël Badin on 2013-07-04
Approved revision: 164
Merged at revision: 162
Proposed branch: lp:~rvb/gwacl/listhostedservices-2
Merge into: lp:gwacl
Diff against target: 132 lines (+86/-4)
2 files modified
management.go (+25/-0)
management_test.go (+61/-4)
To merge this branch: bzr merge lp:~rvb/gwacl/listhostedservices-2
Reviewer Review Type Date Requested Status
Gavin Panella 2013-07-04 Approve on 2013-07-04
Review via email: mp+172989@code.launchpad.net

Commit message

Add ListSpecificHostedServices.

To post a comment you must log in.
Gavin Panella (allenap) wrote :

Looks good.

[1]

+    c.Assert(len(recordedRequests), Equals, 1)

There's a HasLen checker:

    c.Assert(recordedRequests, HasLen, 1)

Here and one other place.

review: Approve
lp:~rvb/gwacl/listhostedservices-2 updated on 2013-07-04
164. By Raphaël Badin on 2013-07-04

Review fixes.

Raphaël Badin (rvb) wrote :

> Looks good.
>
>
> [1]
>
> +    c.Assert(len(recordedRequests), Equals, 1)
>
> There's a HasLen checker:
>
>    c.Assert(recordedRequests, HasLen, 1)
>
> Here and one other place.

Fixed, thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'management.go'
2--- management.go 2013-07-03 09:36:36 +0000
3+++ management.go 2013-07-04 10:56:30 +0000
4@@ -71,6 +71,31 @@
5 return deployments, nil
6 }
7
8+type ListSpecificHostedServicesRequest struct {
9+ ServiceNames []string
10+}
11+
12+// ListSpecificHostedServices returns a slice containing specific
13+// HostedServiceDescriptor objects, insofar as they match the request.
14+func (api *ManagementAPI) ListSpecificHostedServices(request *ListSpecificHostedServicesRequest) ([]HostedServiceDescriptor, error) {
15+ allServices, err := api.ListHostedServices()
16+ if err != nil {
17+ return nil, err
18+ }
19+ // Filter the service list according to the given names.
20+ filter := make(map[string]bool)
21+ for _, name := range request.ServiceNames {
22+ filter[name] = true
23+ }
24+ services := []HostedServiceDescriptor{}
25+ for _, service := range allServices {
26+ if _, ok := filter[service.ServiceName]; ok {
27+ services = append(services, service)
28+ }
29+ }
30+ return services, nil
31+}
32+
33 type DestroyDeploymentRequest struct {
34 ServiceName string
35 DeploymentName string
36
37=== modified file 'management_test.go'
38--- management_test.go 2013-07-03 09:36:36 +0000
39+++ management_test.go 2013-07-04 10:56:30 +0000
40@@ -83,7 +83,7 @@
41 })
42
43 // The only request is for the service's properties
44- c.Assert(len(record), Not(Equals), 0)
45+ c.Assert(record, Not(HasLen), 0)
46 expectedURL := fmt.Sprintf(
47 "%ssubscriptionId/services/hostedservices/%s?embed-detail=true",
48 AZURE_URL, service.ServiceName)
49@@ -122,7 +122,7 @@
50 c.Check(deployments, DeepEquals, service.Deployments)
51
52 // Only one request to the API is made.
53- c.Assert(len(record), Equals, 1)
54+ c.Assert(record, HasLen, 1)
55 }
56
57 // TestListDeployments tests ListDeployments, including filtering by name.
58@@ -143,7 +143,7 @@
59 // Only the first deployment - named "Arthur" - is returned.
60 c.Check(deployments, DeepEquals, []Deployment{service.Deployments[0]})
61 // Only one request to the API is made.
62- c.Assert(len(record), Equals, 1)
63+ c.Assert(record, HasLen, 1)
64 }
65
66 func (suite *managementAPISuite) TestListDeploymentsWithoutNamesReturnsNothing(c *C) {
67@@ -160,7 +160,64 @@
68 c.Assert(err, IsNil)
69
70 // No deployments are returned.
71- c.Check(len(deployments), Equals, 0)
72+ c.Check(deployments, HasLen, 0)
73+}
74+
75+func makeHostedServiceDescriptor() *HostedServiceDescriptor {
76+ url := MakeRandomString(10)
77+ serviceName := MakeRandomString(10)
78+ return &HostedServiceDescriptor{ServiceName: serviceName, URL: url}
79+}
80+
81+func (suite *managementAPISuite) TestListSpecificHostedServices(c *C) {
82+ service1 := makeHostedServiceDescriptor()
83+ service2 := makeHostedServiceDescriptor()
84+ list := HostedServiceDescriptorList{HostedServices: []HostedServiceDescriptor{*service1, *service2}}
85+ XML, err := list.Serialize()
86+ c.Assert(err, IsNil)
87+ fixedResponse := x509Response{
88+ StatusCode: http.StatusOK,
89+ Body: []byte(XML),
90+ }
91+ rigFixedResponseDispatcher(&fixedResponse)
92+ recordedRequests := make([]*X509Request, 0)
93+ rigRecordingDispatcher(&recordedRequests)
94+
95+ api := makeAPI(c)
96+ request := &ListSpecificHostedServicesRequest{
97+ ServiceNames: []string{service1.ServiceName},
98+ }
99+ descriptors, err := api.ListSpecificHostedServices(request)
100+
101+ // Only the first service is returned.
102+ c.Check(descriptors, DeepEquals, []HostedServiceDescriptor{*service1})
103+ // Only one request to the API is made.
104+ c.Assert(recordedRequests, HasLen, 1)
105+}
106+
107+func (suite *managementAPISuite) TestListSpecificHostedServicesWithoutNamesReturnsNothing(c *C) {
108+ service1 := makeHostedServiceDescriptor()
109+ service2 := makeHostedServiceDescriptor()
110+ list := HostedServiceDescriptorList{HostedServices: []HostedServiceDescriptor{*service1, *service2}}
111+ XML, err := list.Serialize()
112+ c.Assert(err, IsNil)
113+ fixedResponse := x509Response{
114+ StatusCode: http.StatusOK,
115+ Body: []byte(XML),
116+ }
117+ rigFixedResponseDispatcher(&fixedResponse)
118+ recordedRequests := make([]*X509Request, 0)
119+ rigRecordingDispatcher(&recordedRequests)
120+
121+ api := makeAPI(c)
122+ request := &ListSpecificHostedServicesRequest{
123+ ServiceNames: []string{},
124+ }
125+ descriptors, err := api.ListSpecificHostedServices(request)
126+
127+ c.Check(descriptors, DeepEquals, []HostedServiceDescriptor{})
128+ // Only one request to the API is made.
129+ c.Assert(recordedRequests, HasLen, 1)
130 }
131
132 type suiteDestroyDeployment struct{}

Subscribers

People subscribed via source and target branches

to all changes: