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

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
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 Approve
Review via email: mp+172989@code.launchpad.net

Commit message

Add ListSpecificHostedServices.

To post a comment you must log in.
Revision history for this message
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
164. By Raphaël Badin

Review fixes.

Revision history for this message
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
=== modified file 'management.go'
--- management.go 2013-07-03 09:36:36 +0000
+++ management.go 2013-07-04 10:56:30 +0000
@@ -71,6 +71,31 @@
71 return deployments, nil71 return deployments, nil
72}72}
7373
74type ListSpecificHostedServicesRequest struct {
75 ServiceNames []string
76}
77
78// ListSpecificHostedServices returns a slice containing specific
79// HostedServiceDescriptor objects, insofar as they match the request.
80func (api *ManagementAPI) ListSpecificHostedServices(request *ListSpecificHostedServicesRequest) ([]HostedServiceDescriptor, error) {
81 allServices, err := api.ListHostedServices()
82 if err != nil {
83 return nil, err
84 }
85 // Filter the service list according to the given names.
86 filter := make(map[string]bool)
87 for _, name := range request.ServiceNames {
88 filter[name] = true
89 }
90 services := []HostedServiceDescriptor{}
91 for _, service := range allServices {
92 if _, ok := filter[service.ServiceName]; ok {
93 services = append(services, service)
94 }
95 }
96 return services, nil
97}
98
74type DestroyDeploymentRequest struct {99type DestroyDeploymentRequest struct {
75 ServiceName string100 ServiceName string
76 DeploymentName string101 DeploymentName string
77102
=== modified file 'management_test.go'
--- management_test.go 2013-07-03 09:36:36 +0000
+++ management_test.go 2013-07-04 10:56:30 +0000
@@ -83,7 +83,7 @@
83 })83 })
8484
85 // The only request is for the service's properties85 // The only request is for the service's properties
86 c.Assert(len(record), Not(Equals), 0)86 c.Assert(record, Not(HasLen), 0)
87 expectedURL := fmt.Sprintf(87 expectedURL := fmt.Sprintf(
88 "%ssubscriptionId/services/hostedservices/%s?embed-detail=true",88 "%ssubscriptionId/services/hostedservices/%s?embed-detail=true",
89 AZURE_URL, service.ServiceName)89 AZURE_URL, service.ServiceName)
@@ -122,7 +122,7 @@
122 c.Check(deployments, DeepEquals, service.Deployments)122 c.Check(deployments, DeepEquals, service.Deployments)
123123
124 // Only one request to the API is made.124 // Only one request to the API is made.
125 c.Assert(len(record), Equals, 1)125 c.Assert(record, HasLen, 1)
126}126}
127127
128// TestListDeployments tests ListDeployments, including filtering by name.128// TestListDeployments tests ListDeployments, including filtering by name.
@@ -143,7 +143,7 @@
143 // Only the first deployment - named "Arthur" - is returned.143 // Only the first deployment - named "Arthur" - is returned.
144 c.Check(deployments, DeepEquals, []Deployment{service.Deployments[0]})144 c.Check(deployments, DeepEquals, []Deployment{service.Deployments[0]})
145 // Only one request to the API is made.145 // Only one request to the API is made.
146 c.Assert(len(record), Equals, 1)146 c.Assert(record, HasLen, 1)
147}147}
148148
149func (suite *managementAPISuite) TestListDeploymentsWithoutNamesReturnsNothing(c *C) {149func (suite *managementAPISuite) TestListDeploymentsWithoutNamesReturnsNothing(c *C) {
@@ -160,7 +160,64 @@
160 c.Assert(err, IsNil)160 c.Assert(err, IsNil)
161161
162 // No deployments are returned.162 // No deployments are returned.
163 c.Check(len(deployments), Equals, 0)163 c.Check(deployments, HasLen, 0)
164}
165
166func makeHostedServiceDescriptor() *HostedServiceDescriptor {
167 url := MakeRandomString(10)
168 serviceName := MakeRandomString(10)
169 return &HostedServiceDescriptor{ServiceName: serviceName, URL: url}
170}
171
172func (suite *managementAPISuite) TestListSpecificHostedServices(c *C) {
173 service1 := makeHostedServiceDescriptor()
174 service2 := makeHostedServiceDescriptor()
175 list := HostedServiceDescriptorList{HostedServices: []HostedServiceDescriptor{*service1, *service2}}
176 XML, err := list.Serialize()
177 c.Assert(err, IsNil)
178 fixedResponse := x509Response{
179 StatusCode: http.StatusOK,
180 Body: []byte(XML),
181 }
182 rigFixedResponseDispatcher(&fixedResponse)
183 recordedRequests := make([]*X509Request, 0)
184 rigRecordingDispatcher(&recordedRequests)
185
186 api := makeAPI(c)
187 request := &ListSpecificHostedServicesRequest{
188 ServiceNames: []string{service1.ServiceName},
189 }
190 descriptors, err := api.ListSpecificHostedServices(request)
191
192 // Only the first service is returned.
193 c.Check(descriptors, DeepEquals, []HostedServiceDescriptor{*service1})
194 // Only one request to the API is made.
195 c.Assert(recordedRequests, HasLen, 1)
196}
197
198func (suite *managementAPISuite) TestListSpecificHostedServicesWithoutNamesReturnsNothing(c *C) {
199 service1 := makeHostedServiceDescriptor()
200 service2 := makeHostedServiceDescriptor()
201 list := HostedServiceDescriptorList{HostedServices: []HostedServiceDescriptor{*service1, *service2}}
202 XML, err := list.Serialize()
203 c.Assert(err, IsNil)
204 fixedResponse := x509Response{
205 StatusCode: http.StatusOK,
206 Body: []byte(XML),
207 }
208 rigFixedResponseDispatcher(&fixedResponse)
209 recordedRequests := make([]*X509Request, 0)
210 rigRecordingDispatcher(&recordedRequests)
211
212 api := makeAPI(c)
213 request := &ListSpecificHostedServicesRequest{
214 ServiceNames: []string{},
215 }
216 descriptors, err := api.ListSpecificHostedServices(request)
217
218 c.Check(descriptors, DeepEquals, []HostedServiceDescriptor{})
219 // Only one request to the API is made.
220 c.Assert(recordedRequests, HasLen, 1)
164}221}
165222
166type suiteDestroyDeployment struct{}223type suiteDestroyDeployment struct{}

Subscribers

People subscribed via source and target branches

to all changes: