Merge lp:~julian-edwards/gwacl/listhostedservices into lp:gwacl

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 163
Merged at revision: 159
Proposed branch: lp:~julian-edwards/gwacl/listhostedservices
Merge into: lp:gwacl
Diff against target: 147 lines (+84/-9)
3 files modified
management_base_test.go (+5/-5)
xmlobjects.go (+17/-4)
xmlobjects_test.go (+62/-0)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/listhostedservices
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+172948@code.launchpad.net

Commit message

Fix ListHostedServices and give it a test.

Description of the change

I sat down to write ListHostedServices and saw that it was already written. However, its implementation was broken and not surprisingly there were no tests for it. It's all fixed here, and I even improved the existing test TestListHostedServices so it rigs up a real response instead of an empty one.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good!

I ran the example file (which already called the old version of the method) and everything is okay.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'management_base_test.go'
2--- management_base_test.go 2013-07-03 10:01:33 +0000
3+++ management_base_test.go 2013-07-04 04:38:23 +0000
4@@ -352,23 +352,23 @@
5
6 func (suite *managementBaseAPISuite) TestListHostedServices(c *C) {
7 api := makeAPI(c)
8+ url := MakeRandomString(10)
9 fixedResponse := x509Response{
10 StatusCode: http.StatusOK,
11- Body: []byte("<HostedServices></HostedServices>"),
12+ Body: []byte(makeHostedServiceDescriptorList(url)),
13 }
14 rigFixedResponseDispatcher(&fixedResponse)
15 recordedRequests := make([]*X509Request, 0)
16 rigRecordingDispatcher(&recordedRequests)
17
18- _, err := api.ListHostedServices()
19+ descriptors, err := api.ListHostedServices()
20
21 c.Assert(err, IsNil)
22 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices"
23- checkOneRequest(c, &recordedRequests, expectedURL, []byte{}, "GET")
24+ checkOneRequest(c, &recordedRequests, expectedURL, nil, "GET")
25+ c.Assert(descriptors[0].URL, Equals, url)
26 }
27
28-// TODO test that ListHostedServices parses the structures correctly
29-
30 func (suite *managementBaseAPISuite) TestGetHostedServiceProperties_withoutDetails(c *C) {
31 api := makeAPI(c)
32 body := `
33
34=== modified file 'xmlobjects.go'
35--- xmlobjects.go 2013-07-02 15:39:49 +0000
36+++ xmlobjects.go 2013-07-04 04:38:23 +0000
37@@ -328,6 +328,8 @@
38 }
39
40 type HostedServiceDescriptorList struct {
41+ XMLName xml.Name `xml:"HostedServices"`
42+ XMLNS string `xml:"xmlns,attr"`
43 HostedServices []HostedServiceDescriptor `xml:"HostedService"`
44 }
45
46@@ -335,13 +337,24 @@
47 return toxml(c)
48 }
49
50+func (c *HostedServiceDescriptorList) Deserialize(data []byte) error {
51+ return xml.Unmarshal(data, c)
52+}
53+
54 // HostedServiceDescriptor contains a subset of the details in HostedService,
55 // and is used when describing a list of HostedServices.
56+// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460781.aspx
57 type HostedServiceDescriptor struct {
58- XMLNS string `xml:"xmlns,attr"`
59- URL string `xml:"Url"`
60- ServiceName string `xml:"ServiceName"`
61- Description string `xml:"Description"`
62+ URL string `xml:"Url"`
63+ ServiceName string `xml:"ServiceName"`
64+ Description string `xml:"HostedServiceProperties>Description"`
65+ AffinityGroup string `xml:"HostedServiceProperties>AffinityGroup"`
66+ Location string `xml:"HostedServiceProperties>Location"`
67+ Label string `xml:"HostedServiceProperties>Label"`
68+ Status string `xml:"HostedServiceProperties>Status"`
69+ DateCreated string `xml:"HostedServiceProperties>DateCreated"`
70+ DateLastModified string `xml:"HostedServiceProperties>DateLastModified"`
71+ ExtendedProperties []ExtendedProperty `xml:"HostedServiceProperties>ExtendedProperties>ExtendedProperty"`
72 }
73
74 type CreateHostedService struct {
75
76=== modified file 'xmlobjects_test.go'
77--- xmlobjects_test.go 2013-07-03 00:17:53 +0000
78+++ xmlobjects_test.go 2013-07-04 04:38:23 +0000
79@@ -1078,6 +1078,68 @@
80 c.Assert(observed.Containers[0].Metadata.Items[0].Name(), Equals, "metadata-name")
81 }
82
83+func makeHostedServiceDescriptorList(url string) string {
84+ input := `
85+ <?xml version="1.0" encoding="utf-8"?>
86+ <HostedServices xmlns="http://schemas.microsoft.com/windowsazure">
87+ <HostedService>
88+ <Url>%s</Url>
89+ <ServiceName>hosted-service-name</ServiceName>
90+ <HostedServiceProperties>
91+ <Description>description</Description>
92+ <AffinityGroup>affinity-group</AffinityGroup>
93+ <Location>service-location</Location>
94+ <Label>label</Label>
95+ <Status>status</Status>
96+ <DateCreated>date-created</DateCreated>
97+ <DateLastModified>date-modified</DateLastModified>
98+ <ExtendedProperties>
99+ <ExtendedProperty>
100+ <Name>property-name</Name>
101+ <Value>property-value</Value>
102+ </ExtendedProperty>
103+ </ExtendedProperties>
104+ </HostedServiceProperties>
105+ </HostedService>
106+ </HostedServices>
107+ `
108+ return fmt.Sprintf(input, url)
109+}
110+
111+func (suite *xmlSuite) TestHostedServiceDescriptorList(c *C) {
112+ input := makeHostedServiceDescriptorList("hosted-service-address")
113+ expected := &HostedServiceDescriptorList{
114+ XMLName: xml.Name{
115+ Space: "http://schemas.microsoft.com/windowsazure",
116+ Local: "HostedServices"},
117+ XMLNS: "http://schemas.microsoft.com/windowsazure",
118+ HostedServices: []HostedServiceDescriptor{
119+ {
120+ URL: "hosted-service-address",
121+ ServiceName: "hosted-service-name",
122+ Description: "description",
123+ AffinityGroup: "affinity-group",
124+ Location: "service-location",
125+ Label: "label",
126+ Status: "status",
127+ DateCreated: "date-created",
128+ DateLastModified: "date-modified",
129+ ExtendedProperties: []ExtendedProperty{
130+ {
131+ Name: "property-name",
132+ Value: "property-value",
133+ },
134+ },
135+ },
136+ },
137+ }
138+
139+ observed := &HostedServiceDescriptorList{}
140+ err := observed.Deserialize([]byte(input))
141+ c.Assert(err, IsNil)
142+ c.Assert(observed, DeepEquals, expected)
143+}
144+
145 // TestCreateStorageService demonstrates that CreateHostedService is a
146 // suitable container for the CreateHostedService XML tree that are required
147 // for the Create Hosted Service API call.

Subscribers

People subscribed via source and target branches

to all changes: