~abp998/gwacl/subscription

« back to all changes in this revision

Viewing changes to xmlobjects_test.go

  • Committer: Gavin Panella
  • Date: 2013-03-12 17:05:36 UTC
  • mto: (5.3.2 use-dedent)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: gavin@gromper.net-20130312170536-b7u1wbzy0tf0bbxa
Reformat with 4 spaces instead of tabs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package gwacl
5
5
 
6
6
import (
7
 
    "encoding/base64"
8
 
    "encoding/xml"
9
7
    "fmt"
10
8
    . "launchpad.net/gocheck"
11
 
    "launchpad.net/gwacl/dedent"
12
 
    "sort"
13
9
)
14
10
 
15
 
type xmlSuite struct{}
16
 
 
17
 
var _ = Suite(&xmlSuite{})
18
 
 
19
 
//
20
 
// Tests for Marshallers
21
 
//
22
 
 
23
 
func (suite *xmlSuite) TestConfigurationSet(c *C) {
24
 
    config := makeLinuxProvisioningConfiguration()
 
11
func (suite *GwaclSuite) TestLinuxProvisioningConfiguration(c *C) {
 
12
    config := makeLinuxProvisioningConfiguration(provconfParams{})
25
13
 
26
14
    xml, err := config.Serialize()
27
15
    c.Assert(err, IsNil)
28
 
    template := dedent.Dedent(`
29
 
        <ConfigurationSet>
30
 
          <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
31
 
          <HostName>%s</HostName>
32
 
          <UserName>%s</UserName>
33
 
          <UserPassword>%s</UserPassword>
34
 
          <UserData>%s</UserData>
35
 
          <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
36
 
        </ConfigurationSet>`)
37
 
    expected := fmt.Sprintf(template, config.Hostname, config.Username,
38
 
        config.Password, config.UserData,
39
 
        config.DisableSSHPasswordAuthentication)
40
 
    c.Check(xml, Equals, expected)
 
16
    c.Check(xml, Equals, fmt.Sprintf(`
 
17
<LinuxProvisioningConfiguration>
 
18
  <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
 
19
  <HostName>%s</HostName>
 
20
  <UserName>%s</UserName>
 
21
  <UserPassword>%s</UserPassword>
 
22
  <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
 
23
</LinuxProvisioningConfiguration>`, config.Hostname,
 
24
        config.Username, config.Password,
 
25
        config.DisableSshPasswordAuthentication))
41
26
}
42
27
 
43
 
func (suite *xmlSuite) TestInputEndpoint(c *C) {
 
28
func (suite *GwaclSuite) TestInputEndpoint(c *C) {
44
29
    endpoint := makeEndpoint(endpointParams{})
45
30
 
46
31
    xml, err := endpoint.Serialize()
47
32
    c.Assert(err, IsNil)
48
 
    template := dedent.Dedent(`
49
 
        <InputEndpoint>
50
 
          <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
51
 
          <LocalPort>%v</LocalPort>
52
 
          <Name>%s</Name>
53
 
          <Port>%v</Port>
54
 
          <Protocol>%s</Protocol>
55
 
        </InputEndpoint>`)
56
 
    expected := fmt.Sprintf(template, endpoint.LoadBalancedEndpointSetName,
57
 
        endpoint.LocalPort, endpoint.Name, endpoint.Port, endpoint.Protocol)
 
33
    expected := fmt.Sprintf(`
 
34
<InputEndpoint>
 
35
  <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
 
36
  <LocalPort>%v</LocalPort>
 
37
  <Name>%s</Name>
 
38
  <Port>%v</Port>
 
39
  <Protocol>%s</Protocol>
 
40
</InputEndpoint>`, endpoint.LoadBalancedEndpointSetName, endpoint.LocalPort,
 
41
        endpoint.Name, endpoint.Port, endpoint.Protocol)
58
42
    c.Check(xml, Equals, expected)
59
43
}
60
44
 
61
 
func (suite *xmlSuite) TestOSVirtualHardDisk(c *C) {
62
 
    disk := makeOSVirtualHardDisk()
 
45
func (suite *GwaclSuite) TestOSVirtualHardDisk(c *C) {
 
46
    disk := makeOSVirtualHardDisk(osVirtualHardDiskParams{})
63
47
 
64
48
    xml, err := disk.Serialize()
65
49
    c.Assert(err, IsNil)
66
 
    template := dedent.Dedent(`
67
 
        <OSVirtualHardDisk>
68
 
          <HostCaching>%s</HostCaching>
69
 
          <DiskLabel>%s</DiskLabel>
70
 
          <DiskName>%s</DiskName>
71
 
          <MediaLink>%s</MediaLink>
72
 
          <SourceImageName>%s</SourceImageName>
73
 
        </OSVirtualHardDisk>`)
74
 
    expected := fmt.Sprintf(template, disk.HostCaching, disk.DiskLabel,
75
 
        disk.DiskName, disk.MediaLink, disk.SourceImageName)
 
50
    expected := fmt.Sprintf(`
 
51
<OSVirtualHardDisk>
 
52
  <HostCaching>%s</HostCaching>
 
53
  <DiskLabel>%s</DiskLabel>
 
54
  <DiskName>%s</DiskName>
 
55
  <MediaLink>%s</MediaLink>
 
56
  <SourceImageName>%s</SourceImageName>
 
57
</OSVirtualHardDisk>`, disk.HostCaching, disk.DiskLabel, disk.DiskName,
 
58
        disk.MediaLink, disk.SourceImageName)
76
59
    c.Check(xml, Equals, expected)
77
60
}
78
61
 
79
 
func (suite *xmlSuite) TestConfigurationSetNetworkConfiguration(c *C) {
 
62
func (suite *GwaclSuite) TestNetworkConfiguration(c *C) {
80
63
    endpoint1 := makeEndpoint(endpointParams{})
81
64
    endpoint2 := makeEndpoint(endpointParams{})
82
65
    endpoints := []InputEndpoint{*endpoint1, *endpoint2}
83
 
    config := NewNetworkConfigurationSet(endpoints)
 
66
    config := &NetworkConfiguration{
 
67
        InputEndpoints: endpoints}
84
68
    xml, err := config.Serialize()
85
69
    c.Assert(err, IsNil)
86
 
    template := dedent.Dedent(`
87
 
        <ConfigurationSet>
88
 
          <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
89
 
          <InputEndpoints>
90
 
            <InputEndpoint>
91
 
              <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
92
 
              <LocalPort>%v</LocalPort>
93
 
              <Name>%s</Name>
94
 
              <Port>%v</Port>
95
 
              <Protocol>%s</Protocol>
96
 
            </InputEndpoint>
97
 
            <InputEndpoint>
98
 
              <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
99
 
              <LocalPort>%v</LocalPort>
100
 
              <Name>%s</Name>
101
 
              <Port>%v</Port>
102
 
              <Protocol>%s</Protocol>
103
 
            </InputEndpoint>
104
 
          </InputEndpoints>
105
 
        </ConfigurationSet>`)
106
 
    expected := fmt.Sprintf(template, endpoint1.LoadBalancedEndpointSetName,
107
 
        endpoint1.LocalPort, endpoint1.Name, endpoint1.Port,
108
 
        endpoint1.Protocol, endpoint2.LoadBalancedEndpointSetName,
109
 
        endpoint2.LocalPort, endpoint2.Name, endpoint2.Port,
110
 
        endpoint2.Protocol)
 
70
    expected := fmt.Sprintf(`
 
71
<NetworkConfiguration>
 
72
  <InputEndpoints>
 
73
    <InputEndpoint>
 
74
      <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
 
75
      <LocalPort>%v</LocalPort>
 
76
      <Name>%s</Name>
 
77
      <Port>%v</Port>
 
78
      <Protocol>%s</Protocol>
 
79
    </InputEndpoint>
 
80
    <InputEndpoint>
 
81
      <LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
 
82
      <LocalPort>%v</LocalPort>
 
83
      <Name>%s</Name>
 
84
      <Port>%v</Port>
 
85
      <Protocol>%s</Protocol>
 
86
    </InputEndpoint>
 
87
  </InputEndpoints>
 
88
</NetworkConfiguration>`,
 
89
        endpoint1.LoadBalancedEndpointSetName, endpoint1.LocalPort,
 
90
        endpoint1.Name, endpoint1.Port, endpoint1.Protocol,
 
91
        endpoint2.LoadBalancedEndpointSetName, endpoint2.LocalPort,
 
92
        endpoint2.Name, endpoint2.Port, endpoint2.Protocol)
111
93
    c.Check(xml, Equals, expected)
112
94
}
113
95
 
114
 
func (suite *xmlSuite) TestRole(c *C) {
115
 
    role := makeRole()
116
 
    config := role.ConfigurationSets[0]
 
96
func (suite *GwaclSuite) TestRole(c *C) {
 
97
    config := makeLinuxProvisioningConfiguration(provconfParams{})
 
98
    configset := []LinuxProvisioningConfiguration{*config}
 
99
    role := makeRole(roleParams{ConfigurationSet: configset})
117
100
 
118
101
    xml, err := role.Serialize()
119
102
    c.Assert(err, IsNil)
120
 
    template := dedent.Dedent(`
121
 
        <Role>
122
 
          <RoleName>%s</RoleName>
123
 
          <RoleType>PersistentVMRole</RoleType>
124
 
          <ConfigurationSets>
125
 
            <ConfigurationSet>
126
 
              <ConfigurationSetType>%s</ConfigurationSetType>
127
 
              <HostName>%s</HostName>
128
 
              <UserName>%s</UserName>
129
 
              <UserPassword>%s</UserPassword>
130
 
              <UserData>%s</UserData>
131
 
              <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
132
 
            </ConfigurationSet>
133
 
          </ConfigurationSets>
134
 
          <RoleSize>%s</RoleSize>
135
 
        </Role>`)
136
 
    expected := fmt.Sprintf(template, role.RoleName,
137
 
        config.ConfigurationSetType, config.Hostname, config.Username,
138
 
        config.Password, config.UserData,
139
 
        config.DisableSSHPasswordAuthentication, role.RoleSize)
 
103
    expected := fmt.Sprintf(`
 
104
<Role>
 
105
  <RoleSize>%s</RoleSize>
 
106
  <RoleName>%s</RoleName>
 
107
  <RoleType>PersistentVMRole</RoleType>
 
108
  <ConfigurationSets>
 
109
    <ConfigurationSet>
 
110
      <ConfigurationSetType>%s</ConfigurationSetType>
 
111
      <HostName>%s</HostName>
 
112
      <UserName>%s</UserName>
 
113
      <UserPassword>%s</UserPassword>
 
114
      <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
 
115
    </ConfigurationSet>
 
116
  </ConfigurationSets>
 
117
</Role>`, role.RoleSize, role.RoleName, config.ConfigurationSetType,
 
118
        config.Hostname, config.Username, config.Password,
 
119
        config.DisableSshPasswordAuthentication)
140
120
    c.Check(xml, Equals, expected)
141
121
}
142
122
 
143
 
func makeGetRoleResponse(rolename string) string {
144
 
    // This template is from
145
 
    // http://msdn.microsoft.com/en-us/library/windowsazure/jj157193.aspx
146
 
    template := fmt.Sprintf(`
147
 
        <PersistentVMRole xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
148
 
          <RoleName>%s</RoleName>
149
 
          <OsVersion>operating-system-version</OsVersion>
150
 
          <RoleType>PersistentVMRole</RoleType>
151
 
          <ConfigurationSets>
152
 
            <ConfigurationSet>
153
 
              <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
154
 
              <InputEndpoints>
155
 
                <InputEndpoint>
156
 
                  <LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
157
 
                  <LocalPort>1</LocalPort>
158
 
                  <Name>name-of-input-endpoint</Name>
159
 
                  <Port>1</Port>
160
 
                  <LoadBalancerProbe>
161
 
                    <Path>path-of-probe</Path>
162
 
                    <Port>port-assigned-to-probe</Port>
163
 
                    <Protocol>protocol-of-input-endpoint</Protocol>
164
 
                  </LoadBalancerProbe>
165
 
                  <Protocol>TCP|UDP</Protocol>
166
 
                  <Vip>virtual-ip-address-of-input-endpoint</Vip>
167
 
                </InputEndpoint>
168
 
                <InputEndpoint>
169
 
                  <LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
170
 
                  <LocalPort>2</LocalPort>
171
 
                  <Name>name-of-input-endpoint</Name>
172
 
                  <Port>2</Port>
173
 
                  <LoadBalancerProbe>
174
 
                    <Path>path-of-probe</Path>
175
 
                    <Port>port-assigned-to-probe</Port>
176
 
                    <Protocol>protocol-of-input-endpoint</Protocol>
177
 
                  </LoadBalancerProbe>
178
 
                  <Protocol>TCP|UDP</Protocol>
179
 
                  <Vip>virtual-ip-address-of-input-endpoint</Vip>
180
 
                </InputEndpoint>
181
 
              </InputEndpoints>
182
 
              <SubnetNames>
183
 
                <SubnetName>name-of-subnet</SubnetName>
184
 
              </SubnetNames>
185
 
            </ConfigurationSet>
186
 
          </ConfigurationSets>
187
 
          <AvailabilitySetName>name-of-availability-set</AvailabilitySetName>
188
 
          <DataVirtualHardDisks>
189
 
            <DataVirtualHardDisk>
190
 
              <HostCaching>host-caching-mode-of-data-disk</HostCaching>
191
 
              <DiskName>new-or-existing-disk-name</DiskName>
192
 
              <Lun>logical-unit-number-of-data-disk</Lun>
193
 
              <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>
194
 
              <MediaLink>path-to-vhd</MediaLink>
195
 
            </DataVirtualHardDisk>
196
 
          </DataVirtualHardDisks>
197
 
          <OSVirtualHardDisk>
198
 
            <HostCaching>host-caching-mode-of-os-disk</HostCaching>
199
 
            <DiskName>name-of-os-disk</DiskName>
200
 
            <MediaLink>path-to-vhd</MediaLink>
201
 
            <SourceImageName>image-used-to-create-os-disk</SourceImageName>
202
 
            <OS>operating-system-on-os-disk</OS>
203
 
          </OSVirtualHardDisk>
204
 
          <RoleSize>size-of-instance</RoleSize>
205
 
          <DefaultWinRmCertificateThumbprint>winrm-cert-thumbprint</DefaultWinRmCertificateThumbprint>
206
 
        </PersistentVMRole>
207
 
        `, rolename)
208
 
    return template
209
 
}
210
 
 
211
 
func (suite *xmlSuite) TestGetRole(c *C) {
212
 
    expected := &GetRole{
213
 
        XMLName: xml.Name{
214
 
            Space: "http://schemas.microsoft.com/windowsazure",
215
 
            Local: "PersistentVMRole"},
216
 
        XMLNS:     XMLNS,
217
 
        RoleName:  "name-of-the-vm",
218
 
        OsVersion: "operating-system-version",
219
 
        RoleType:  "PersistentVMRole",
220
 
        ConfigurationSets: []ConfigurationSet{
221
 
            {
222
 
                ConfigurationSetType: "NetworkConfiguration",
223
 
                InputEndpoints: &[]InputEndpoint{
224
 
                    {
225
 
                        LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
226
 
                        LocalPort:                   1,
227
 
                        Name:                        "name-of-input-endpoint",
228
 
                        Port:                        1,
229
 
                        Protocol:                    "TCP|UDP",
230
 
                    },
231
 
                    {
232
 
                        LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
233
 
                        LocalPort:                   2,
234
 
                        Name:                        "name-of-input-endpoint",
235
 
                        Port:                        2,
236
 
                        Protocol:                    "TCP|UDP",
237
 
                    },
238
 
                },
239
 
            },
240
 
        },
241
 
        AvailabilitySetName: "name-of-availability-set",
242
 
        OSVirtualHardDisk: OSVirtualHardDisk{
243
 
            HostCaching:     "host-caching-mode-of-os-disk",
244
 
            DiskName:        "name-of-os-disk",
245
 
            MediaLink:       "path-to-vhd",
246
 
            SourceImageName: "image-used-to-create-os-disk",
247
 
            OS:              "operating-system-on-os-disk",
248
 
        },
249
 
        RoleSize: "size-of-instance",
250
 
        DefaultWinRmCertificateThumbprint: "winrm-cert-thumbprint",
251
 
    }
252
 
 
253
 
    template := makeGetRoleResponse("name-of-the-vm")
254
 
 
255
 
    observed := &GetRole{}
256
 
    err := observed.Deserialize([]byte(template))
257
 
    c.Assert(err, IsNil)
258
 
    c.Assert(observed, DeepEquals, expected)
259
 
}
260
 
 
261
 
func (suite *xmlSuite) TestNetworkConfigurationSerialize(c *C) {
262
 
    // Template from
263
 
    // http://msdn.microsoft.com/en-us/library/windowsazure/jj157181.aspx
264
 
    expected := dedent.Dedent(`
265
 
        <NetworkConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
266
 
          <VirtualNetworkConfiguration>
267
 
            <Dns>
268
 
              <DnsServers>
269
 
                <DnsServer name="dns-server-name" IPAddress="IPV4-address-of-the-server"></DnsServer>
270
 
              </DnsServers>
271
 
            </Dns>
272
 
            <LocalNetworkSites>
273
 
              <LocalNetworkSite name="local-site-name">
274
 
                <AddressSpace>
275
 
                  <AddressPrefix>CIDR-identifier</AddressPrefix>
276
 
                </AddressSpace>
277
 
                <VPNGatewayAddress>IPV4-address-of-the-vpn-gateway</VPNGatewayAddress>
278
 
              </LocalNetworkSite>
279
 
            </LocalNetworkSites>
280
 
            <VirtualNetworkSites>
281
 
              <VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
282
 
                <AddressSpace>
283
 
                  <AddressPrefix>CIDR-identifier</AddressPrefix>
284
 
                </AddressSpace>
285
 
                <Subnets>
286
 
                  <Subnet name="subnet-name">
287
 
                    <AddressPrefix>CIDR-identifier</AddressPrefix>
288
 
                  </Subnet>
289
 
                </Subnets>
290
 
                <DnsServersRef>
291
 
                  <DnsServerRef name="primary-DNS-name"></DnsServerRef>
292
 
                </DnsServersRef>
293
 
                <Gateway profile="Small">
294
 
                  <VPNClientAddressPool>
295
 
                    <AddressPrefix>CIDR-identifier</AddressPrefix>
296
 
                  </VPNClientAddressPool>
297
 
                  <ConnectionsToLocalNetwork>
298
 
                    <LocalNetworkSiteRef name="local-site-name">
299
 
                      <Connection type="connection-type"></Connection>
300
 
                    </LocalNetworkSiteRef>
301
 
                  </ConnectionsToLocalNetwork>
302
 
                </Gateway>
303
 
              </VirtualNetworkSite>
304
 
            </VirtualNetworkSites>
305
 
          </VirtualNetworkConfiguration>
306
 
        </NetworkConfiguration>`)
307
 
 
308
 
    input := NetworkConfiguration{
309
 
        XMLNS: XMLNS_NC,
310
 
        DNS: &[]VirtualNetDnsServer{
311
 
            {
312
 
                Name:      "dns-server-name",
313
 
                IPAddress: "IPV4-address-of-the-server",
314
 
            },
315
 
        },
316
 
        LocalNetworkSites: &[]LocalNetworkSite{
317
 
            {
318
 
                Name: "local-site-name",
319
 
                AddressSpacePrefixes: []string{
320
 
                    "CIDR-identifier",
321
 
                },
322
 
                VPNGatewayAddress: "IPV4-address-of-the-vpn-gateway",
323
 
            },
324
 
        },
325
 
        VirtualNetworkSites: &[]VirtualNetworkSite{
326
 
            {
327
 
                Name:          "virtual-network-name",
328
 
                AffinityGroup: "affinity-group-name",
329
 
                AddressSpacePrefixes: []string{
330
 
                    "CIDR-identifier",
331
 
                },
332
 
                Subnets: &[]Subnet{
333
 
                    {
334
 
                        Name:          "subnet-name",
335
 
                        AddressPrefix: "CIDR-identifier",
336
 
                    },
337
 
                },
338
 
                DnsServersRef: &[]DnsServerRef{
339
 
                    {
340
 
                        Name: "primary-DNS-name",
341
 
                    },
342
 
                },
343
 
                Gateway: &Gateway{
344
 
                    Profile: "Small",
345
 
                    VPNClientAddressPoolPrefixes: []string{
346
 
                        "CIDR-identifier",
347
 
                    },
348
 
                    LocalNetworkSiteRef: LocalNetworkSiteRef{
349
 
                        Name: "local-site-name",
350
 
                        Connection: LocalNetworkSiteRefConnection{
351
 
                            Type: "connection-type",
352
 
                        },
353
 
                    },
354
 
                },
355
 
            },
356
 
        },
357
 
    }
358
 
 
359
 
    observed, err := input.Serialize()
360
 
    c.Assert(err, IsNil)
361
 
    c.Assert(observed, Equals, expected)
362
 
}
363
 
 
364
 
func (suite *xmlSuite) TestNetworkConfigurationSerializeMinimal(c *C) {
365
 
    expected := fmt.Sprintf(
366
 
        "\n<NetworkConfiguration xmlns=\"%s\"></NetworkConfiguration>",
367
 
        XMLNS_NC)
368
 
    input := NetworkConfiguration{XMLNS: XMLNS_NC}
369
 
    observed, err := input.Serialize()
370
 
    c.Assert(err, IsNil)
371
 
    c.Assert(observed, Equals, expected)
372
 
}
373
 
 
374
 
func (suite *xmlSuite) TestNetworkConfigurationSerializeSimpleVirtualNetworkSite(c *C) {
375
 
    expected := dedent.Dedent(`
376
 
        <NetworkConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
377
 
          <VirtualNetworkConfiguration>
378
 
            <VirtualNetworkSites>
379
 
              <VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
380
 
                <AddressSpace>
381
 
                  <AddressPrefix>CIDR-identifier</AddressPrefix>
382
 
                </AddressSpace>
383
 
              </VirtualNetworkSite>
384
 
            </VirtualNetworkSites>
385
 
          </VirtualNetworkConfiguration>
386
 
        </NetworkConfiguration>`)
387
 
    input := NetworkConfiguration{
388
 
        XMLNS: XMLNS_NC,
389
 
        VirtualNetworkSites: &[]VirtualNetworkSite{
390
 
            {
391
 
                Name:          "virtual-network-name",
392
 
                AffinityGroup: "affinity-group-name",
393
 
                AddressSpacePrefixes: []string{
394
 
                    "CIDR-identifier",
395
 
                },
396
 
            },
397
 
        },
398
 
    }
399
 
    observed, err := input.Serialize()
400
 
    c.Assert(err, IsNil)
401
 
    c.Assert(observed, Equals, expected)
402
 
}
403
 
 
404
 
func (suite *xmlSuite) TestCreateAffinityGroup(c *C) {
405
 
    expected := dedent.Dedent(`
406
 
        <CreateAffinityGroup xmlns="http://schemas.microsoft.com/windowsazure">
407
 
          <Name>affinity-group-name</Name>
408
 
          <Label>base64-encoded-affinity-group-label</Label>
409
 
          <Description>affinity-group-description</Description>
410
 
          <Location>location</Location>
411
 
        </CreateAffinityGroup>`)
412
 
 
413
 
    input := CreateAffinityGroup{
414
 
        XMLNS:       XMLNS,
415
 
        Name:        "affinity-group-name",
416
 
        Label:       "base64-encoded-affinity-group-label",
417
 
        Description: "affinity-group-description",
418
 
        Location:    "location"}
419
 
 
420
 
    observed, err := input.Serialize()
421
 
    c.Assert(err, IsNil)
422
 
    c.Assert(observed, Equals, expected)
423
 
}
424
 
 
425
 
func (suite *xmlSuite) TestNewCreateAffinityGroup(c *C) {
426
 
    name := "name"
427
 
    label := "label"
428
 
    description := "description"
429
 
    location := "location"
430
 
    ag := NewCreateAffinityGroup(name, label, description, location)
431
 
    base64label := base64.StdEncoding.EncodeToString([]byte(label))
432
 
    c.Check(ag.XMLNS, Equals, XMLNS)
433
 
    c.Check(ag.Name, Equals, name)
434
 
    c.Check(ag.Label, Equals, base64label)
435
 
    c.Check(ag.Description, Equals, description)
436
 
    c.Check(ag.Location, Equals, location)
437
 
}
438
 
 
439
 
func (suite *xmlSuite) TestUpdateAffinityGroup(c *C) {
440
 
    expected := dedent.Dedent(`
441
 
        <UpdateAffinityGroup xmlns="http://schemas.microsoft.com/windowsazure">
442
 
          <Label>base64-encoded-affinity-group-label</Label>
443
 
          <Description>affinity-group-description</Description>
444
 
        </UpdateAffinityGroup>`)
445
 
    input := UpdateAffinityGroup{
446
 
        XMLNS:       XMLNS,
447
 
        Label:       "base64-encoded-affinity-group-label",
448
 
        Description: "affinity-group-description"}
449
 
 
450
 
    observed, err := input.Serialize()
451
 
    c.Assert(err, IsNil)
452
 
    c.Assert(observed, Equals, expected)
453
 
}
454
 
 
455
 
func (suite *xmlSuite) TestNewUpdateAffinityGroup(c *C) {
456
 
    label := "label"
457
 
    description := "description"
458
 
    ag := NewUpdateAffinityGroup(label, description)
459
 
    base64label := base64.StdEncoding.EncodeToString([]byte(label))
460
 
    c.Check(ag.XMLNS, Equals, XMLNS)
461
 
    c.Check(ag.Label, Equals, base64label)
462
 
    c.Check(ag.Description, Equals, description)
463
 
}
464
 
 
465
 
func (suite *xmlSuite) TestNetworkConfigurationDeserialize(c *C) {
466
 
    // Template from
467
 
    // http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx
468
 
    input := `
469
 
        <NetworkConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
470
 
          <VirtualNetworkConfiguration>
471
 
            <Dns>
472
 
              <DnsServers>
473
 
                <DnsServer name="dns-server-name" IPAddress="IPV4-address-of-the-server"></DnsServer>
474
 
              </DnsServers>
475
 
            </Dns>
476
 
            <LocalNetworkSites>
477
 
              <LocalNetworkSite name="local-site-name">
478
 
                <AddressSpace>
479
 
                  <AddressPrefix>CIDR-identifier</AddressPrefix>
480
 
                </AddressSpace>
481
 
                <VPNGatewayAddress>IPV4-address-of-the-vpn-gateway</VPNGatewayAddress>
482
 
              </LocalNetworkSite>
483
 
            </LocalNetworkSites>
484
 
            <VirtualNetworkSites>
485
 
              <VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
486
 
                <Label>label-for-the-site</Label>
487
 
                <AddressSpace>
488
 
                  <AddressPrefix>CIDR-identifier</AddressPrefix>
489
 
                </AddressSpace>
490
 
                <Subnets>
491
 
                  <Subnet name="subnet-name">
492
 
                    <AddressPrefix>CIDR-identifier</AddressPrefix>
493
 
                  </Subnet>
494
 
                </Subnets>
495
 
                <DnsServersRef>
496
 
                  <DnsServerRef name="primary-DNS-name"></DnsServerRef>
497
 
                </DnsServersRef>
498
 
                <Gateway profile="Small">
499
 
                  <VPNClientAddressPool>
500
 
                    <AddressPrefix>CIDR-identifier</AddressPrefix>
501
 
                  </VPNClientAddressPool>
502
 
                  <ConnectionsToLocalNetwork>
503
 
                    <LocalNetworkSiteRef name="local-site-name">
504
 
                      <Connection type="connection-type"></Connection>
505
 
                    </LocalNetworkSiteRef>
506
 
                  </ConnectionsToLocalNetwork>
507
 
                </Gateway>
508
 
              </VirtualNetworkSite>
509
 
            </VirtualNetworkSites>
510
 
          </VirtualNetworkConfiguration>
511
 
        </NetworkConfiguration>`
512
 
    expected := &NetworkConfiguration{
513
 
        XMLNS: XMLNS_NC,
514
 
        DNS: &[]VirtualNetDnsServer{
515
 
            {
516
 
                Name:      "dns-server-name",
517
 
                IPAddress: "IPV4-address-of-the-server",
518
 
            },
519
 
        },
520
 
        LocalNetworkSites: &[]LocalNetworkSite{
521
 
            {
522
 
                Name: "local-site-name",
523
 
                AddressSpacePrefixes: []string{
524
 
                    "CIDR-identifier",
525
 
                },
526
 
                VPNGatewayAddress: "IPV4-address-of-the-vpn-gateway",
527
 
            },
528
 
        },
529
 
        VirtualNetworkSites: &[]VirtualNetworkSite{
530
 
            {
531
 
                Name:          "virtual-network-name",
532
 
                AffinityGroup: "affinity-group-name",
533
 
                AddressSpacePrefixes: []string{
534
 
                    "CIDR-identifier",
535
 
                },
536
 
                Subnets: &[]Subnet{
537
 
                    {
538
 
                        Name:          "subnet-name",
539
 
                        AddressPrefix: "CIDR-identifier",
540
 
                    },
541
 
                },
542
 
                DnsServersRef: &[]DnsServerRef{
543
 
                    {
544
 
                        Name: "primary-DNS-name",
545
 
                    },
546
 
                },
547
 
                Gateway: &Gateway{
548
 
                    Profile: "Small",
549
 
                    VPNClientAddressPoolPrefixes: []string{
550
 
                        "CIDR-identifier",
551
 
                    },
552
 
                    LocalNetworkSiteRef: LocalNetworkSiteRef{
553
 
                        Name: "local-site-name",
554
 
                        Connection: LocalNetworkSiteRefConnection{
555
 
                            Type: "connection-type",
556
 
                        },
557
 
                    },
558
 
                },
559
 
            },
560
 
        },
561
 
    }
562
 
    networkConfig := &NetworkConfiguration{}
563
 
    err := networkConfig.Deserialize([]byte(input))
564
 
    c.Assert(err, IsNil)
565
 
    // Check sub-components of the overall structure.
566
 
    c.Check(networkConfig.DNS, DeepEquals, expected.DNS)
567
 
    c.Check(networkConfig.LocalNetworkSites, DeepEquals, expected.LocalNetworkSites)
568
 
    c.Check(networkConfig.VirtualNetworkSites, DeepEquals, expected.VirtualNetworkSites)
569
 
    // Check the whole thing.
570
 
    c.Check(networkConfig, DeepEquals, expected)
571
 
}
572
 
 
573
 
func (suite *xmlSuite) TestDeployment(c *C) {
574
 
    deployment := makeDeployment()
575
 
    dns := deployment.DNS[0]
576
 
    role := deployment.RoleList[0]
577
 
    config := role.ConfigurationSets[0]
 
123
func (suite *GwaclSuite) TestDeployment(c *C) {
 
124
    config := makeLinuxProvisioningConfiguration(provconfParams{})
 
125
    configset := []LinuxProvisioningConfiguration{*config}
 
126
    role := makeRole(roleParams{ConfigurationSet: configset})
 
127
    rolelist := []Role{*role}
 
128
    dns := makeDnsServer(dnsParams{})
 
129
    dnsset := []DnsServer{*dns}
 
130
 
 
131
    deployment := makeDeployment(deploymentParams{
 
132
        RoleList: rolelist,
 
133
        Dns:      dnsset})
578
134
 
579
135
    xml, err := deployment.Serialize()
580
136
    c.Assert(err, IsNil)
581
 
    template := dedent.Dedent(`
582
 
        <Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
583
 
          <Name>%s</Name>
584
 
          <DeploymentSlot>%s</DeploymentSlot>
585
 
          <Label>%s</Label>
586
 
          <RoleInstanceList></RoleInstanceList>
587
 
          <RoleList>
588
 
            <Role>
589
 
              <RoleName>%s</RoleName>
590
 
              <RoleType>PersistentVMRole</RoleType>
591
 
              <ConfigurationSets>
592
 
                <ConfigurationSet>
593
 
                  <ConfigurationSetType>%s</ConfigurationSetType>
594
 
                  <HostName>%s</HostName>
595
 
                  <UserName>%s</UserName>
596
 
                  <UserPassword>%s</UserPassword>
597
 
                  <UserData>%s</UserData>
598
 
                  <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
599
 
                </ConfigurationSet>
600
 
              </ConfigurationSets>
601
 
              <RoleSize>%s</RoleSize>
602
 
            </Role>
603
 
          </RoleList>
604
 
          <VirtualNetworkName>%s</VirtualNetworkName>
605
 
          <Dns>
606
 
            <DnsServers>
607
 
              <DnsServer>
608
 
                <Name>%s</Name>
609
 
                <Address>%s</Address>
610
 
              </DnsServer>
611
 
            </DnsServers>
612
 
          </Dns>
613
 
          <ExtendedProperties></ExtendedProperties>
614
 
        </Deployment>`)
615
 
    expected := fmt.Sprintf(template, deployment.Name,
616
 
        deployment.DeploymentSlot, deployment.Label,
617
 
        role.RoleName, config.ConfigurationSetType, config.Hostname,
618
 
        config.Username, config.Password, config.UserData,
619
 
        config.DisableSSHPasswordAuthentication, role.RoleSize,
620
 
        deployment.VirtualNetworkName, dns.Name, dns.Address)
621
 
    c.Check(xml, Equals, expected)
622
 
}
623
 
 
624
 
// From http://msdn.microsoft.com/en-us/library/windowsazure/ee460804.aspx
625
 
var deploymentXML = `
626
 
<?xml version="1.0" encoding="utf-8"?>
627
 
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
628
 
  <Name>name-of-deployment</Name>
629
 
  <DeploymentSlot>current-deployment-environment</DeploymentSlot>
630
 
  <PrivateID>deployment-id</PrivateID>
631
 
  <Status>status-of-deployment</Status>
632
 
  <Label>base64-encoded-name-of-deployment</Label>
633
 
  <Url>http://name-of-deployment.cloudapp.net</Url>
634
 
  <Configuration>base-64-encoded-configuration-file</Configuration>
635
 
  <RoleInstanceList>
636
 
    <RoleInstance>
637
 
      <RoleName>name-of-role</RoleName>
638
 
      <InstanceName>name-of-role-instance</InstanceName>
639
 
      <InstanceStatus>status-of-role-instance</InstanceStatus>
640
 
      <InstanceUpgradeDomain>update-domain-of-role-instance</InstanceUpgradeDomain>
641
 
      <InstanceFaultDomain>fault-domain-of-role-instance</InstanceFaultDomain>
642
 
      <InstanceSize>size-of-role-instance</InstanceSize>
643
 
      <InstanceStateDetails>state-of-role-instance</InstanceStateDetails>
644
 
      <InstanceErrorCode>error-code-returned-for-role-instance</InstanceErrorCode>
645
 
      <IpAddress>ip-address-of-role-instance</IpAddress>
646
 
      <InstanceEndpoints>
647
 
        <InstanceEndpoint>
648
 
          <Name>name-of-endpoint</Name>
649
 
          <Vip>virtual-ip-address-of-instance-endpoint</Vip>
650
 
          <PublicPort>1234</PublicPort>
651
 
          <LocalPort>5678</LocalPort>
652
 
          <Protocol>protocol-of-instance-endpoint</Protocol>
653
 
        </InstanceEndpoint>
654
 
      </InstanceEndpoints>
655
 
      <PowerState>state-of-role-instance</PowerState>
656
 
      <HostName>dns-name-of-service</HostName>
657
 
      <RemoteAccessCertificateThumbprint>cert-thumbprint-for-remote-access</RemoteAccessCertificateThumbprint>
658
 
    </RoleInstance>
659
 
  </RoleInstanceList>
660
 
  <UpgradeStatus>
661
 
    <UpgradeType>auto|manual</UpgradeType>
662
 
    <CurrentUpgradeDomainState>before|during</CurrentUpgradeDomainState>
663
 
    <CurrentUpgradeDomain>n</CurrentUpgradeDomain>
664
 
  </UpgradeStatus>
665
 
  <UpgradeDomainCount>number-of-upgrade-domains-in-deployment</UpgradeDomainCount>
 
137
    expected := fmt.Sprintf(`
 
138
<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
 
139
  <Name>%s</Name>
 
140
  <DeploymentSlot>%s</DeploymentSlot>
 
141
  <Label>%s</Label>
666
142
  <RoleList>
667
143
    <Role>
668
 
      <RoleName>name-of-role</RoleName>
669
 
      <OsVersion>operating-system-version</OsVersion>
670
 
      <ConfigurationSets>
671
 
        <ConfigurationSet>
672
 
          <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
673
 
          <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
674
 
        </ConfigurationSet>
675
 
      </ConfigurationSets>
676
 
    </Role>
677
 
    <Role>
678
 
      <RoleName>name-of-role</RoleName>
679
 
      <OsVersion>operating-system-version</OsVersion>
 
144
      <RoleSize>%s</RoleSize>
 
145
      <RoleName>%s</RoleName>
680
146
      <RoleType>PersistentVMRole</RoleType>
681
147
      <ConfigurationSets>
682
 
        <ConfigurationSet>
683
 
          <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
684
 
            <InputEndpoints>
685
 
              <InputEndpoint>
686
 
                <Port>2222</Port>
687
 
                <LocalPort>111</LocalPort>
688
 
                <Protocol>TCP</Protocol>
689
 
                <Name>test-name</Name>
690
 
              </InputEndpoint>
691
 
            </InputEndpoints>
692
 
          <SubnetNames>
693
 
            <SubnetName>name-of-subnet</SubnetName>
694
 
          </SubnetNames>
695
 
        </ConfigurationSet>
 
148
        <ConfigurationSet>
 
149
          <ConfigurationSetType>%s</ConfigurationSetType>
 
150
          <HostName>%s</HostName>
 
151
          <UserName>%s</UserName>
 
152
          <UserPassword>%s</UserPassword>
 
153
          <DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
 
154
        </ConfigurationSet>
696
155
      </ConfigurationSets>
697
 
      <AvailabilitySetName>name-of-availability-set</AvailabilitySetName>
698
 
      <DataVirtualHardDisks>
699
 
        <DataVirtualHardDisk>
700
 
          <HostCaching>host-caching-mode-of-data-disk</HostCaching>
701
 
          <DiskName>name-of-data-disk</DiskName>
702
 
          <Lun>logical-unit-number-of-data-disk</Lun>
703
 
          <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>
704
 
          <MediaLink>path-to-vhd</MediaLink>
705
 
        </DataVirtualHardDisk>
706
 
      </DataVirtualHardDisks>
707
 
      <OSVirtualHardDisk>
708
 
        <HostCaching>host-caching-mode-of-os-disk</HostCaching>
709
 
        <DiskName>name-of-os-disk</DiskName>
710
 
        <MediaLink>path-to-vhd</MediaLink>
711
 
        <SourceImageName>image-used-to-create-os-disk</SourceImageName>
712
 
        <OS>operating-system-on-os-disk</OS>
713
 
      </OSVirtualHardDisk>
714
 
      <RoleSize>size-of-instance</RoleSize>
715
156
    </Role>
716
157
  </RoleList>
717
 
  <SdkVersion>sdk-version-used-to-create-package</SdkVersion>
718
 
  <Locked>status-of-deployment-write-allowed</Locked>
719
 
  <RollbackAllowed>rollback-operation-allowed</RollbackAllowed>
720
 
  <VirtualNetworkName>name-of-virtual-network</VirtualNetworkName>
 
158
  <VirtualNetworkName>%s</VirtualNetworkName>
721
159
  <Dns>
722
160
    <DnsServers>
723
161
      <DnsServer>
724
 
        <Name>name-of-dns-server</Name>
725
 
        <Address>address-of-dns-server</Address>
 
162
        <Name>%s</Name>
 
163
        <Address>%s</Address>
726
164
      </DnsServer>
727
165
    </DnsServers>
728
166
  </Dns>
729
 
  <ExtendedProperties>
730
 
    <ExtendedProperty>
731
 
      <Name>name-of-property</Name>
732
 
      <Value>value-of-property</Value>
733
 
    </ExtendedProperty>
734
 
  </ExtendedProperties>
735
 
  <PersistentVMDowntime>
736
 
    <StartTime>start-of-downtime</StartTime>
737
 
    <EndTime>end-of-downtime</EndTime>
738
 
    <Status>status-of-downtime</Status>
739
 
  </PersistentVMDowntime>
740
 
  <VirtualIPs>
741
 
    <VirtualIP>
742
 
      <Address>virtual-ip-address-of-deployment</Address>
743
 
    </VirtualIP>
744
 
  </VirtualIPs>
745
 
  <ExtensionConfiguration>
746
 
    <AllRoles>
747
 
      <Extension>
748
 
        <Id>identifier-of-extension</Id>
749
 
      </Extension>
750
 
      ...
751
 
    </AllRoles>
752
 
    <NamedRoles>
753
 
      <Role>
754
 
        <RoleName>role_name1</RoleName>
755
 
        <Extensions>
756
 
          <Extension>
757
 
            <Id>identifier-of-extension</Id>
758
 
          </Extension>
759
 
          ...
760
 
        </Extensions>
761
 
      </Role>
762
 
    </NamedRoles>
763
 
  </ExtensionConfiguration>
764
 
</Deployment>
765
 
`
766
 
 
767
 
func (suite *xmlSuite) TestDeploymentWRTGetDeployment(c *C) {
768
 
    expected := &Deployment{
769
 
        XMLNS:          "http://schemas.microsoft.com/windowsazure",
770
 
        Name:           "name-of-deployment",
771
 
        DeploymentSlot: "current-deployment-environment",
772
 
        PrivateID:      "deployment-id",
773
 
        Status:         "status-of-deployment",
774
 
        Label:          "base64-encoded-name-of-deployment",
775
 
        URL:            "http://name-of-deployment.cloudapp.net",
776
 
        Configuration:  "base-64-encoded-configuration-file",
777
 
        RoleInstanceList: []RoleInstance{
778
 
            {
779
 
                RoleName:              "name-of-role",
780
 
                InstanceName:          "name-of-role-instance",
781
 
                InstanceStatus:        "status-of-role-instance",
782
 
                InstanceUpgradeDomain: "update-domain-of-role-instance",
783
 
                InstanceFaultDomain:   "fault-domain-of-role-instance",
784
 
                InstanceSize:          "size-of-role-instance",
785
 
                InstanceStateDetails:  "state-of-role-instance",
786
 
                InstanceErrorCode:     "error-code-returned-for-role-instance",
787
 
                IPAddress:             "ip-address-of-role-instance",
788
 
                InstanceEndpoints: []InstanceEndpoint{
789
 
                    {
790
 
                        Name:       "name-of-endpoint",
791
 
                        VIP:        "virtual-ip-address-of-instance-endpoint",
792
 
                        PublicPort: 1234,
793
 
                        LocalPort:  5678,
794
 
                        Protocol:   "protocol-of-instance-endpoint",
795
 
                    },
796
 
                },
797
 
                PowerState: "state-of-role-instance",
798
 
                HostName:   "dns-name-of-service",
799
 
                RemoteAccessCertificateThumbprint: "cert-thumbprint-for-remote-access",
800
 
            },
801
 
        },
802
 
        UpgradeDomainCount: "number-of-upgrade-domains-in-deployment",
803
 
        RoleList: []Role{
804
 
            {
805
 
                RoleName: "name-of-role",
806
 
                ConfigurationSets: []ConfigurationSet{
807
 
                    {
808
 
                        ConfigurationSetType:             "LinuxProvisioningConfiguration",
809
 
                        DisableSSHPasswordAuthentication: "false",
810
 
                    },
811
 
                },
812
 
            },
813
 
            {
814
 
                RoleName: "name-of-role",
815
 
                RoleType: "PersistentVMRole",
816
 
                ConfigurationSets: []ConfigurationSet{
817
 
                    {
818
 
                        ConfigurationSetType: "NetworkConfiguration",
819
 
                        InputEndpoints: &[]InputEndpoint{
820
 
                            {
821
 
                                Name:      "test-name",
822
 
                                Port:      2222,
823
 
                                LocalPort: 111,
824
 
                                Protocol:  "TCP",
825
 
                            },
826
 
                        },
827
 
                    },
828
 
                },
829
 
                OSVirtualHardDisk: []OSVirtualHardDisk{
830
 
                    {
831
 
                        HostCaching:     "host-caching-mode-of-os-disk",
832
 
                        DiskName:        "name-of-os-disk",
833
 
                        MediaLink:       "path-to-vhd",
834
 
                        SourceImageName: "image-used-to-create-os-disk",
835
 
                        OS:              "operating-system-on-os-disk",
836
 
                    },
837
 
                },
838
 
                RoleSize: "size-of-instance",
839
 
            },
840
 
        },
841
 
        SDKVersion:         "sdk-version-used-to-create-package",
842
 
        Locked:             "status-of-deployment-write-allowed",
843
 
        RollbackAllowed:    "rollback-operation-allowed",
844
 
        VirtualNetworkName: "name-of-virtual-network",
845
 
        DNS: []DnsServer{
846
 
            {
847
 
                Name:    "name-of-dns-server",
848
 
                Address: "address-of-dns-server",
849
 
            },
850
 
        },
851
 
        ExtendedProperties: []ExtendedProperty{
852
 
            {
853
 
                Name:  "name-of-property",
854
 
                Value: "value-of-property",
855
 
            },
856
 
        },
857
 
    }
858
 
    observed := &Deployment{}
859
 
    err := observed.Deserialize([]byte(deploymentXML))
860
 
    c.Assert(err, IsNil)
861
 
    c.Assert(observed, DeepEquals, expected)
862
 
}
863
 
 
864
 
func (suite *xmlSuite) TestDeploymentGetFQDNExtractsFQDN(c *C) {
865
 
    deployment := &Deployment{}
866
 
    err := deployment.Deserialize([]byte(deploymentXML))
867
 
    c.Assert(err, IsNil)
868
 
    fqdn, err := deployment.GetFQDN()
869
 
    c.Assert(err, IsNil)
870
 
    c.Assert(fqdn, Equals, "name-of-deployment.cloudapp.net")
871
 
}
872
 
 
873
 
var deploymentXMLEmptyURL = `
874
 
<?xml version="1.0" encoding="utf-8"?>
875
 
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
876
 
  <Name>name-of-deployment</Name>
877
 
  <Label>base64-encoded-name-of-deployment</Label>
878
 
  <Url></Url>
879
 
</Deployment>
880
 
`
881
 
 
882
 
func (suite *xmlSuite) TestDeploymentGetFQDNErrorsIfURLIsEmpty(c *C) {
883
 
    deployment := &Deployment{}
884
 
    err := deployment.Deserialize([]byte(deploymentXMLEmptyURL))
885
 
    c.Assert(err, IsNil)
886
 
    _, err = deployment.GetFQDN()
887
 
    c.Check(err, ErrorMatches, ".*URL field is empty.*")
888
 
}
889
 
 
890
 
var deploymentXMLFaultyURL = `
891
 
<?xml version="1.0" encoding="utf-8"?>
892
 
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
893
 
  <Name>name-of-deployment</Name>
894
 
  <Label>base64-encoded-name-of-deployment</Label>
895
 
  <Url>%z</Url>
896
 
</Deployment>
897
 
`
898
 
 
899
 
func (suite *xmlSuite) TestDeploymentGetFQDNErrorsIfURLCannotBeParsed(c *C) {
900
 
    deployment := &Deployment{}
901
 
    err := deployment.Deserialize([]byte(deploymentXMLFaultyURL))
902
 
    c.Assert(err, IsNil)
903
 
    _, err = deployment.GetFQDN()
904
 
    c.Check(err, ErrorMatches, ".*invalid URL.*")
905
 
}
906
 
 
907
 
func (suite *xmlSuite) TestNewDeploymentForCreateVMDeployment(c *C) {
908
 
    name := "deploymentName"
909
 
    deploymentSlot := "staging"
910
 
    label := "deploymentLabel"
911
 
    vhd := NewOSVirtualHardDisk("hostCaching", "diskLabel", "diskName", "mediaLink", "sourceImageName", "os")
912
 
    roles := []Role{*NewRole("size", "name", []ConfigurationSet{}, []OSVirtualHardDisk{*vhd})}
913
 
    virtualNetworkName := "network"
914
 
 
915
 
    deployment := NewDeploymentForCreateVMDeployment(name, deploymentSlot, label, roles, virtualNetworkName)
916
 
 
917
 
    c.Check(deployment.XMLNS, Equals, XMLNS)
918
 
    c.Check(deployment.XMLNS_I, Equals, XMLNS_I)
919
 
    c.Check(deployment.Name, Equals, name)
920
 
    c.Check(deployment.DeploymentSlot, Equals, deploymentSlot)
921
 
    c.Check(deployment.RoleList, DeepEquals, roles)
922
 
    decodedLabel, err := base64.StdEncoding.DecodeString(deployment.Label)
923
 
    c.Assert(err, IsNil)
924
 
    c.Check(string(decodedLabel), Equals, label)
925
 
    c.Check(deployment.VirtualNetworkName, Equals, virtualNetworkName)
926
 
}
927
 
 
928
 
func (suite *xmlSuite) TestCreateVirtualHardDiskMediaLinkHappyPath(c *C) {
929
 
    mediaLink := CreateVirtualHardDiskMediaLink("storage-name", "storage/path")
930
 
    c.Check(mediaLink, Equals, "http://storage-name.blob.core.windows.net/storage/path")
931
 
}
932
 
 
933
 
func (suite *xmlSuite) TestCreateVirtualHardDiskMediaLinkChecksParams(c *C) {
934
 
    c.Check(
935
 
        func() { CreateVirtualHardDiskMediaLink("foo^bar", "valid") },
936
 
        PanicMatches, "'foo\\^bar' contains URI special characters")
937
 
    c.Check(
938
 
        func() { CreateVirtualHardDiskMediaLink("valid", "a/foo^bar/test") },
939
 
        PanicMatches, "'foo\\^bar' contains URI special characters")
940
 
}
941
 
 
942
 
func (suite *xmlSuite) TestCreateStorageServiceInput(c *C) {
943
 
    s := makeCreateStorageServiceInput()
944
 
    extProperty := s.ExtendedProperties[0]
945
 
    xml, err := s.Serialize()
946
 
    c.Assert(err, IsNil)
947
 
    template := dedent.Dedent(`
948
 
        <CreateStorageServiceInput xmlns="http://schemas.microsoft.com/windowsazure">
949
 
          <ServiceName>%s</ServiceName>
950
 
          <Label>%s</Label>
951
 
          <Description>%s</Description>
952
 
          <Location>%s</Location>
953
 
          <AffinityGroup>%s</AffinityGroup>
954
 
          <GeoReplicationEnabled>%s</GeoReplicationEnabled>
955
 
          <ExtendedProperties>
956
 
            <ExtendedProperty>
957
 
              <Name>%s</Name>
958
 
              <Value>%s</Value>
959
 
            </ExtendedProperty>
960
 
          </ExtendedProperties>
961
 
        </CreateStorageServiceInput>`)
962
 
    expected := fmt.Sprintf(template, s.ServiceName, s.Label, s.Description,
963
 
        s.Location, s.AffinityGroup, s.GeoReplicationEnabled, extProperty.Name,
964
 
        extProperty.Value)
965
 
    c.Assert(xml, Equals, expected)
966
 
}
967
 
 
968
 
//
969
 
// Tests for Unmarshallers
970
 
//
971
 
 
972
 
func (suite *xmlSuite) TestStorageServicesUnmarshal(c *C) {
973
 
    inputTemplate := `
974
 
        <?xml version="1.0" encoding="utf-8"?>
975
 
        <StorageServices xmlns="http://schemas.microsoft.com/windowsazure">
976
 
          <StorageService>
977
 
            <Url>%s</Url>
978
 
            <ServiceName>%s</ServiceName>
979
 
            <StorageServiceProperties>
980
 
              <Description>%s</Description>
981
 
              <AffinityGroup>%s</AffinityGroup>
982
 
              <Label>%s</Label>
983
 
              <Status>%s</Status>
984
 
              <Endpoints>
985
 
                <Endpoint>%s</Endpoint>
986
 
                <Endpoint>%s</Endpoint>
987
 
                <Endpoint>%s</Endpoint>
988
 
              </Endpoints>
989
 
              <GeoReplicationEnabled>%s</GeoReplicationEnabled>
990
 
              <GeoPrimaryRegion>%s</GeoPrimaryRegion>
991
 
              <StatusOfPrimary>%s</StatusOfPrimary>
992
 
              <LastGeoFailoverTime>%s</LastGeoFailoverTime>
993
 
              <GeoSecondaryRegion>%s</GeoSecondaryRegion>
994
 
              <StatusOfSecondary>%s</StatusOfSecondary>
995
 
              <ExtendedProperties>
996
 
                <ExtendedProperty>
997
 
                  <Name>%s</Name>
998
 
                  <Value>%s</Value>
999
 
                </ExtendedProperty>
1000
 
                <ExtendedProperty>
1001
 
                  <Name>%s</Name>
1002
 
                  <Value>%s</Value>
1003
 
                </ExtendedProperty>
1004
 
              </ExtendedProperties>
1005
 
            </StorageServiceProperties>
1006
 
          </StorageService>
1007
 
        </StorageServices>`
1008
 
    url := MakeRandomString(10)
1009
 
    servicename := MakeRandomString(10)
1010
 
    desc := MakeRandomString(10)
1011
 
    affinity := MakeRandomString(10)
1012
 
    label := MakeRandomString(10)
1013
 
    status := MakeRandomString(10)
1014
 
    blobEndpoint := MakeRandomString(10)
1015
 
    queueEndpoint := MakeRandomString(10)
1016
 
    tableEndpoint := MakeRandomString(10)
1017
 
    geoRepl := BoolToString(MakeRandomBool())
1018
 
    geoRegion := MakeRandomString(10)
1019
 
    statusPrimary := MakeRandomString(10)
1020
 
    failoverTime := MakeRandomString(10)
1021
 
    geoSecRegion := MakeRandomString(10)
1022
 
    statusSec := MakeRandomString(10)
1023
 
    p1Name := MakeRandomString(10)
1024
 
    p1Val := MakeRandomString(10)
1025
 
    p2Name := MakeRandomString(10)
1026
 
    p2Val := MakeRandomString(10)
1027
 
 
1028
 
    input := fmt.Sprintf(inputTemplate, url, servicename, desc, affinity,
1029
 
        label, status, blobEndpoint, queueEndpoint, tableEndpoint, geoRepl,
1030
 
        geoRegion, statusPrimary, failoverTime, geoSecRegion, statusSec,
1031
 
        p1Name, p1Val, p2Name, p2Val)
1032
 
    data := []byte(input)
1033
 
 
1034
 
    services := &StorageServices{}
1035
 
    err := services.Deserialize(data)
1036
 
    c.Assert(err, IsNil)
1037
 
 
1038
 
    c.Check(len(services.StorageServices), Equals, 1)
1039
 
    s := services.StorageServices[0]
1040
 
 
1041
 
    // Oh jeez, here we go....
1042
 
    c.Check(s.URL, Equals, url)
1043
 
    c.Check(s.ServiceName, Equals, servicename)
1044
 
    c.Check(s.Description, Equals, desc)
1045
 
    c.Check(s.AffinityGroup, Equals, affinity)
1046
 
    c.Check(s.Label, Equals, label)
1047
 
    c.Check(s.Status, Equals, status)
1048
 
    c.Check(s.GeoReplicationEnabled, Equals, geoRepl)
1049
 
    c.Check(s.GeoPrimaryRegion, Equals, geoRegion)
1050
 
    c.Check(s.StatusOfPrimary, Equals, statusPrimary)
1051
 
    c.Check(s.LastGeoFailoverTime, Equals, failoverTime)
1052
 
    c.Check(s.GeoSecondaryRegion, Equals, geoSecRegion)
1053
 
    c.Check(s.StatusOfSecondary, Equals, statusSec)
1054
 
 
1055
 
    endpoints := s.Endpoints
1056
 
    c.Check(len(endpoints), Equals, 3)
1057
 
    c.Check(endpoints[0], Equals, blobEndpoint)
1058
 
    c.Check(endpoints[1], Equals, queueEndpoint)
1059
 
    c.Check(endpoints[2], Equals, tableEndpoint)
1060
 
 
1061
 
    properties := s.ExtendedProperties
1062
 
    c.Check(properties[0].Name, Equals, p1Name)
1063
 
    c.Check(properties[0].Value, Equals, p1Val)
1064
 
    c.Check(properties[1].Name, Equals, p2Name)
1065
 
    c.Check(properties[1].Value, Equals, p2Val)
1066
 
}
1067
 
 
1068
 
func (suite *xmlSuite) TestBlobEnumerationResuts(c *C) {
1069
 
    input := `
1070
 
        <?xml version="1.0" encoding="utf-8"?>
1071
 
        <EnumerationResults ContainerName="http://myaccount.blob.core.windows.net/mycontainer">
1072
 
          <Prefix>prefix</Prefix>
1073
 
          <Marker>marker</Marker>
1074
 
          <MaxResults>maxresults</MaxResults>
1075
 
          <Delimiter>delimiter</Delimiter>
1076
 
          <Blobs>
1077
 
            <Blob>
1078
 
              <Name>blob-name</Name>
1079
 
              <Snapshot>snapshot-date-time</Snapshot>
1080
 
              <Url>blob-address</Url>
1081
 
              <Properties>
1082
 
                <Last-Modified>last-modified</Last-Modified>
1083
 
                <Etag>etag</Etag>
1084
 
                <Content-Length>size-in-bytes</Content-Length>
1085
 
                <Content-Type>blob-content-type</Content-Type>
1086
 
                <Content-Encoding />
1087
 
                <Content-Language />
1088
 
                <Content-MD5 />
1089
 
                <Cache-Control />
1090
 
                <x-ms-blob-sequence-number>sequence-number</x-ms-blob-sequence-number>
1091
 
                <BlobType>blobtype</BlobType>
1092
 
                <LeaseStatus>leasestatus</LeaseStatus>
1093
 
                <LeaseState>leasestate</LeaseState>
1094
 
                <LeaseDuration>leasesduration</LeaseDuration>
1095
 
                <CopyId>id</CopyId>
1096
 
                <CopyStatus>copystatus</CopyStatus>
1097
 
                <CopySource>copysource</CopySource>
1098
 
                <CopyProgress>copyprogress</CopyProgress>
1099
 
                <CopyCompletionTime>copycompletiontime</CopyCompletionTime>
1100
 
                <CopyStatusDescription>copydesc</CopyStatusDescription>
1101
 
              </Properties>
1102
 
              <Metadata>
1103
 
                <MetaName1>metadataname1</MetaName1>
1104
 
                <MetaName2>metadataname2</MetaName2>
1105
 
              </Metadata>
1106
 
            </Blob>
1107
 
            <BlobPrefix>
1108
 
              <Name>blob-prefix</Name>
1109
 
            </BlobPrefix>
1110
 
          </Blobs>
1111
 
          <NextMarker />
1112
 
        </EnumerationResults>`
1113
 
    data := []byte(input)
1114
 
    r := &BlobEnumerationResults{}
1115
 
    err := r.Deserialize(data)
1116
 
    c.Assert(err, IsNil)
1117
 
    c.Check(r.ContainerName, Equals, "http://myaccount.blob.core.windows.net/mycontainer")
1118
 
    c.Check(r.Prefix, Equals, "prefix")
1119
 
    c.Check(r.Marker, Equals, "marker")
1120
 
    c.Check(r.MaxResults, Equals, "maxresults")
1121
 
    c.Check(r.Delimiter, Equals, "delimiter")
1122
 
    c.Check(r.NextMarker, Equals, "")
1123
 
    b := r.Blobs[0]
1124
 
    c.Check(b.Name, Equals, "blob-name")
1125
 
    c.Check(b.Snapshot, Equals, "snapshot-date-time")
1126
 
    c.Check(b.URL, Equals, "blob-address")
1127
 
    c.Check(b.LastModified, Equals, "last-modified")
1128
 
    c.Check(b.ETag, Equals, "etag")
1129
 
    c.Check(b.ContentLength, Equals, "size-in-bytes")
1130
 
    c.Check(b.ContentType, Equals, "blob-content-type")
1131
 
    c.Check(b.BlobSequenceNumber, Equals, "sequence-number")
1132
 
    c.Check(b.BlobType, Equals, "blobtype")
1133
 
    c.Check(b.LeaseStatus, Equals, "leasestatus")
1134
 
    c.Check(b.LeaseState, Equals, "leasestate")
1135
 
    c.Check(b.LeaseDuration, Equals, "leasesduration")
1136
 
    c.Check(b.CopyID, Equals, "id")
1137
 
    c.Check(b.CopyStatus, Equals, "copystatus")
1138
 
    c.Check(b.CopySource, Equals, "copysource")
1139
 
    c.Check(b.CopyProgress, Equals, "copyprogress")
1140
 
    c.Check(b.CopyCompletionTime, Equals, "copycompletiontime")
1141
 
    c.Check(b.CopyStatusDescription, Equals, "copydesc")
1142
 
    m1 := b.Metadata.Items[0]
1143
 
    m2 := b.Metadata.Items[1]
1144
 
    c.Check(m1.Name(), Equals, "MetaName1")
1145
 
    c.Check(m1.Value, Equals, "metadataname1")
1146
 
    c.Check(m2.Name(), Equals, "MetaName2")
1147
 
    c.Check(m2.Value, Equals, "metadataname2")
1148
 
    prefix := r.BlobPrefixes[0]
1149
 
    c.Check(prefix, Equals, "blob-prefix")
1150
 
}
1151
 
 
1152
 
func (suite *xmlSuite) TestStorageAccountKeysUnmarshal(c *C) {
1153
 
    template := `
1154
 
        <?xml version="1.0" encoding="utf-8"?>
1155
 
          <StorageService xmlns="http://schemas.microsoft.com/windowsazure">
1156
 
            <Url>%s</Url>
1157
 
            <StorageServiceKeys>
1158
 
              <Primary>%s</Primary>
1159
 
              <Secondary>%s</Secondary>
1160
 
            </StorageServiceKeys>
1161
 
          </StorageService>`
1162
 
    url := MakeRandomString(10)
1163
 
    key1 := MakeRandomString(10)
1164
 
    key2 := MakeRandomString(10)
1165
 
    input := fmt.Sprintf(template, url, key1, key2)
1166
 
    data := []byte(input)
1167
 
 
1168
 
    keys := &StorageAccountKeys{}
1169
 
    err := keys.Deserialize(data)
1170
 
    c.Assert(err, IsNil)
1171
 
    c.Check(keys.URL, Equals, url)
1172
 
    c.Check(keys.Primary, Equals, key1)
1173
 
    c.Check(keys.Secondary, Equals, key2)
1174
 
}
 
167
</Deployment>`,
 
168
        deployment.Name, deployment.DeploymentSlot, deployment.Label,
 
169
        role.RoleSize, role.RoleName, config.ConfigurationSetType, config.Hostname,
 
170
        config.Username, config.Password, config.DisableSshPasswordAuthentication,
 
171
        deployment.VirtualNetworkName, dns.Name, dns.Address)
 
172
    c.Check(xml, Equals, expected)
 
173
}
 
174
 
1175
175
 
1176
176
// Tests for object factory functions.
1177
177
 
1178
 
func (suite *xmlSuite) TestNewRole(c *C) {
 
178
func (suite *GwaclSuite) TestNewRole(c *C) {
1179
179
    rolesize := MakeRandomString(10)
1180
180
    rolename := MakeRandomString(10)
1181
 
    config := makeLinuxProvisioningConfiguration()
1182
 
    configset := []ConfigurationSet{*config}
1183
 
    vhd := NewOSVirtualHardDisk("hostCaching", "diskLabel", "diskName", "mediaLink", "sourceImageName", "os")
 
181
    config := makeLinuxProvisioningConfiguration(provconfParams{})
 
182
    configset := []LinuxProvisioningConfiguration{*config}
1184
183
 
1185
 
    role := NewRole(rolesize, rolename, configset, []OSVirtualHardDisk{*vhd})
 
184
    role := NewRole(rolesize, rolename, configset)
1186
185
    c.Check(role.RoleSize, Equals, rolesize)
1187
186
    c.Check(role.RoleName, Equals, rolename)
1188
 
    c.Check(role.ConfigurationSets, DeepEquals, configset)
 
187
    c.Check(role.ConfigurationSet, DeepEquals, configset)
1189
188
    c.Check(role.RoleType, Equals, "PersistentVMRole")
1190
189
}
1191
190
 
1192
 
func (suite *xmlSuite) TestNewLinuxProvisioningConfiguration(c *C) {
 
191
func (suite *GwaclSuite) TestNewLinuxProvisioningConfiguration(c *C) {
1193
192
    hostname := MakeRandomString(10)
1194
193
    username := MakeRandomString(10)
1195
194
    password := MakeRandomString(10)
1196
 
    disablessh := BoolToString(MakeRandomBool())
1197
 
    userdata := MakeRandomString(10)
 
195
    disablessh := MakeRandomBool()
1198
196
 
1199
 
    config := NewLinuxProvisioningConfigurationSet(
1200
 
        hostname, username, password, userdata, disablessh)
 
197
    config := NewLinuxProvisioningConfiguration(
 
198
        hostname, username, password, disablessh)
1201
199
    c.Check(config.Hostname, Equals, hostname)
1202
200
    c.Check(config.Username, Equals, username)
1203
201
    c.Check(config.Password, Equals, password)
1204
 
    c.Check(config.UserData, Equals, userdata)
1205
 
    c.Check(config.DisableSSHPasswordAuthentication, Equals, disablessh)
 
202
    c.Check(config.DisableSshPasswordAuthentication, Equals, disablessh)
1206
203
    c.Check(config.ConfigurationSetType, Equals, "LinuxProvisioningConfiguration")
1207
204
}
1208
205
 
1209
 
func (suite *xmlSuite) TestNewNetworkConfiguration(c *C) {
1210
 
    name := "name1"
1211
 
    port := 242
1212
 
    localPort := 922
1213
 
    protocol := "TCP"
1214
 
    bName := "bname1"
1215
 
    inputendpoint := InputEndpoint{
1216
 
        LoadBalancedEndpointSetName: bName, LocalPort: localPort, Name: name, Port: port, Protocol: protocol}
1217
 
 
1218
 
    config := NewNetworkConfigurationSet([]InputEndpoint{inputendpoint})
1219
 
    inputEndpoints := *config.InputEndpoints
1220
 
    c.Check(len(inputEndpoints), Equals, 1)
1221
 
    inputEndpoint := inputEndpoints[0]
1222
 
    c.Check(inputEndpoint.Name, Equals, name)
1223
 
    c.Check(inputEndpoint.Port, Equals, port)
1224
 
    c.Check(inputEndpoint.Protocol, Equals, protocol)
1225
 
    c.Check(inputEndpoint.LoadBalancedEndpointSetName, Equals, bName)
1226
 
    c.Check(inputEndpoint.LocalPort, Equals, localPort)
1227
 
    c.Check(config.ConfigurationSetType, Equals, "NetworkConfiguration")
1228
 
}
1229
 
 
1230
 
func (suite *xmlSuite) TestNewOSVirtualHardDisk(c *C) {
 
206
func (suite *GwaclSuite) TestNewOSVirtualHardDisk(c *C) {
1231
207
    var hostcaching HostCachingType = "ReadWrite"
1232
208
    disklabel := MakeRandomString(10)
1233
209
    diskname := MakeRandomString(10)
1234
210
    MediaLink := MakeRandomString(10)
1235
211
    SourceImageName := MakeRandomString(10)
1236
 
    OS := MakeRandomString(10)
1237
212
 
1238
213
    disk := NewOSVirtualHardDisk(
1239
 
        hostcaching, disklabel, diskname, MediaLink, SourceImageName, OS)
 
214
        hostcaching, disklabel, diskname, MediaLink, SourceImageName)
1240
215
    c.Check(disk.HostCaching, Equals, string(hostcaching))
1241
216
    c.Check(disk.DiskLabel, Equals, disklabel)
1242
217
    c.Check(disk.DiskName, Equals, diskname)
1243
218
    c.Check(disk.MediaLink, Equals, MediaLink)
1244
219
    c.Check(disk.SourceImageName, Equals, SourceImageName)
1245
 
    c.Check(disk.OS, Equals, OS)
1246
 
}
1247
 
 
1248
 
// Properties XML subtree for ListContainers Storage API call.
1249
 
func (suite *xmlSuite) TestProperties(c *C) {
1250
 
    input := `
1251
 
        <?xml version="1.0" encoding="utf-8"?>
1252
 
        <Properties>
1253
 
          <Last-Modified>date/time-value</Last-Modified>
1254
 
          <Etag>etag-value</Etag>
1255
 
          <LeaseStatus>lease-status-value</LeaseStatus>
1256
 
          <LeaseState>lease-state-value</LeaseState>
1257
 
          <LeaseDuration>lease-duration-value</LeaseDuration>
1258
 
        </Properties>`
1259
 
    observed := &Properties{}
1260
 
    err := xml.Unmarshal([]byte(input), observed)
1261
 
    c.Assert(err, IsNil)
1262
 
 
1263
 
    expected := &Properties{
1264
 
        LastModified:  "date/time-value",
1265
 
        ETag:          "etag-value",
1266
 
        LeaseStatus:   "lease-status-value",
1267
 
        LeaseState:    "lease-state-value",
1268
 
        LeaseDuration: "lease-duration-value",
1269
 
    }
1270
 
 
1271
 
    c.Assert(observed, DeepEquals, expected)
1272
 
}
1273
 
 
1274
 
// Metadata XML subtree for ListContainers Storage API call.
1275
 
func (suite *xmlSuite) TestMetadata(c *C) {
1276
 
    input := `
1277
 
        <?xml version="1.0" encoding="utf-8"?>
1278
 
        <Metadata>
1279
 
          <metadata-name>metadata-value</metadata-name>
1280
 
        </Metadata>`
1281
 
    observed := &Metadata{}
1282
 
    err := xml.Unmarshal([]byte(input), observed)
1283
 
    c.Assert(err, IsNil)
1284
 
 
1285
 
    expected := &Metadata{
1286
 
        Items: []MetadataItem{
1287
 
            {
1288
 
                XMLName: xml.Name{Local: "metadata-name"},
1289
 
                Value:   "metadata-value",
1290
 
            },
1291
 
        },
1292
 
    }
1293
 
 
1294
 
    c.Assert(observed, DeepEquals, expected)
1295
 
}
1296
 
 
1297
 
// Container XML subtree for ListContainers Storage API call.
1298
 
func (suite *xmlSuite) TestContainer(c *C) {
1299
 
    input := `
1300
 
        <?xml version="1.0" encoding="utf-8"?>
1301
 
        <Container>
1302
 
          <Name>name-value</Name>
1303
 
          <URL>url-value</URL>
1304
 
          <Properties>
1305
 
            <Last-Modified>date/time-value</Last-Modified>
1306
 
            <Etag>etag-value</Etag>
1307
 
            <LeaseStatus>lease-status-value</LeaseStatus>
1308
 
            <LeaseState>lease-state-value</LeaseState>
1309
 
            <LeaseDuration>lease-duration-value</LeaseDuration>
1310
 
          </Properties>
1311
 
          <Metadata>
1312
 
            <metadata-name>metadata-value</metadata-name>
1313
 
          </Metadata>
1314
 
        </Container>`
1315
 
    observed := &Container{}
1316
 
    err := xml.Unmarshal([]byte(input), observed)
1317
 
    c.Assert(err, IsNil)
1318
 
 
1319
 
    expected := &Container{
1320
 
        XMLName: xml.Name{Local: "Container"},
1321
 
        Name:    "name-value",
1322
 
        URL:     "url-value",
1323
 
        Properties: Properties{
1324
 
            LastModified:  "date/time-value",
1325
 
            ETag:          "etag-value",
1326
 
            LeaseStatus:   "lease-status-value",
1327
 
            LeaseState:    "lease-state-value",
1328
 
            LeaseDuration: "lease-duration-value",
1329
 
        },
1330
 
        Metadata: Metadata{
1331
 
            Items: []MetadataItem{
1332
 
                {
1333
 
                    XMLName: xml.Name{Local: "metadata-name"},
1334
 
                    Value:   "metadata-value",
1335
 
                },
1336
 
            },
1337
 
        },
1338
 
    }
1339
 
 
1340
 
    c.Assert(observed, DeepEquals, expected)
1341
 
}
1342
 
 
1343
 
// EnumerationResults XML tree for ListContainers Storage API call.
1344
 
func (suite *xmlSuite) TestContainerEnumerationResults(c *C) {
1345
 
    input := `
1346
 
        <?xml version="1.0" encoding="utf-8"?>
1347
 
        <EnumerationResults AccountName="http://myaccount.blob.core.windows.net">
1348
 
          <Prefix>prefix-value</Prefix>
1349
 
          <Marker>marker-value</Marker>
1350
 
          <MaxResults>max-results-value</MaxResults>
1351
 
          <Containers>
1352
 
            <Container>
1353
 
              <Name>name-value</Name>
1354
 
              <URL>url-value</URL>
1355
 
              <Properties>
1356
 
                <Last-Modified>date/time-value</Last-Modified>
1357
 
                <Etag>etag-value</Etag>
1358
 
                <LeaseStatus>lease-status-value</LeaseStatus>
1359
 
                <LeaseState>lease-state-value</LeaseState>
1360
 
                <LeaseDuration>lease-duration-value</LeaseDuration>
1361
 
              </Properties>
1362
 
              <Metadata>
1363
 
                <metadata-name>metadata-value</metadata-name>
1364
 
              </Metadata>
1365
 
            </Container>
1366
 
          </Containers>
1367
 
          <NextMarker>next-marker-value</NextMarker>
1368
 
        </EnumerationResults>`
1369
 
    observed := &ContainerEnumerationResults{}
1370
 
    err := observed.Deserialize([]byte(input))
1371
 
    c.Assert(err, IsNil)
1372
 
 
1373
 
    expected := &ContainerEnumerationResults{
1374
 
        XMLName:    xml.Name{Local: "EnumerationResults"},
1375
 
        Prefix:     "prefix-value",
1376
 
        Marker:     "marker-value",
1377
 
        MaxResults: "max-results-value",
1378
 
        Containers: []Container{
1379
 
            {
1380
 
                XMLName: xml.Name{Local: "Container"},
1381
 
                Name:    "name-value",
1382
 
                URL:     "url-value",
1383
 
                Properties: Properties{
1384
 
                    LastModified:  "date/time-value",
1385
 
                    ETag:          "etag-value",
1386
 
                    LeaseStatus:   "lease-status-value",
1387
 
                    LeaseState:    "lease-state-value",
1388
 
                    LeaseDuration: "lease-duration-value",
1389
 
                },
1390
 
                Metadata: Metadata{
1391
 
                    Items: []MetadataItem{
1392
 
                        {
1393
 
                            XMLName: xml.Name{Local: "metadata-name"},
1394
 
                            Value:   "metadata-value",
1395
 
                        },
1396
 
                    },
1397
 
                },
1398
 
            },
1399
 
        },
1400
 
        NextMarker: "next-marker-value",
1401
 
    }
1402
 
 
1403
 
    c.Assert(observed, DeepEquals, expected)
1404
 
    c.Assert(observed.Containers[0].Metadata.Items[0].Name(), Equals, "metadata-name")
1405
 
}
1406
 
 
1407
 
func (suite *xmlSuite) TestHostedService(c *C) {
1408
 
    input := `
1409
 
        <?xml version="1.0" encoding="utf-8"?>
1410
 
        <HostedService xmlns="http://schemas.microsoft.com/windowsazure">
1411
 
          <Url>hosted-service-url</Url>
1412
 
          <ServiceName>hosted-service-name</ServiceName>
1413
 
          <HostedServiceProperties>
1414
 
            <Description>description</Description>
1415
 
            <AffinityGroup>name-of-affinity-group</AffinityGroup>
1416
 
            <Location>location-of-service</Location >
1417
 
            <Label>base-64-encoded-name-of-service</Label>
1418
 
            <Status>current-status-of-service</Status>
1419
 
            <DateCreated>creation-date-of-service</DateCreated>
1420
 
            <DateLastModified>last-modification-date-of-service</DateLastModified>
1421
 
            <ExtendedProperties>
1422
 
              <ExtendedProperty>
1423
 
                <Name>name-of-property</Name>
1424
 
                <Value>value-of-property</Value>
1425
 
              </ExtendedProperty>
1426
 
            </ExtendedProperties>
1427
 
          </HostedServiceProperties>
1428
 
          <Deployments>
1429
 
            <Deployment xmlns="http://schemas.microsoft.com/windowsazure">
1430
 
              <Name>name-of-deployment</Name>
1431
 
            </Deployment>
1432
 
          </Deployments>
1433
 
        </HostedService>
1434
 
    `
1435
 
    expected := &HostedService{
1436
 
        XMLNS: "http://schemas.microsoft.com/windowsazure",
1437
 
        HostedServiceDescriptor: HostedServiceDescriptor{
1438
 
            URL:              "hosted-service-url",
1439
 
            ServiceName:      "hosted-service-name",
1440
 
            Description:      "description",
1441
 
            AffinityGroup:    "name-of-affinity-group",
1442
 
            Location:         "location-of-service",
1443
 
            Label:            "base-64-encoded-name-of-service",
1444
 
            Status:           "current-status-of-service",
1445
 
            DateCreated:      "creation-date-of-service",
1446
 
            DateLastModified: "last-modification-date-of-service",
1447
 
            ExtendedProperties: []ExtendedProperty{
1448
 
                {
1449
 
                    Name:  "name-of-property",
1450
 
                    Value: "value-of-property",
1451
 
                },
1452
 
            }},
1453
 
        Deployments: []Deployment{{
1454
 
            XMLNS: "http://schemas.microsoft.com/windowsazure",
1455
 
            Name:  "name-of-deployment",
1456
 
        }},
1457
 
    }
1458
 
 
1459
 
    observed := &HostedService{}
1460
 
    err := observed.Deserialize([]byte(input))
1461
 
    c.Assert(err, IsNil)
1462
 
    c.Assert(observed, DeepEquals, expected)
1463
 
}
1464
 
 
1465
 
func makeHostedServiceDescriptorList(url string) string {
1466
 
    input := `
1467
 
        <?xml version="1.0" encoding="utf-8"?>
1468
 
          <HostedServices xmlns="http://schemas.microsoft.com/windowsazure">
1469
 
            <HostedService>
1470
 
              <Url>%s</Url>
1471
 
              <ServiceName>hosted-service-name</ServiceName>
1472
 
              <HostedServiceProperties>
1473
 
                <Description>description</Description>
1474
 
                <AffinityGroup>affinity-group</AffinityGroup>
1475
 
                <Location>service-location</Location>
1476
 
                <Label>label</Label>
1477
 
                <Status>status</Status>
1478
 
                <DateCreated>date-created</DateCreated>
1479
 
                <DateLastModified>date-modified</DateLastModified>
1480
 
                <ExtendedProperties>
1481
 
                  <ExtendedProperty>
1482
 
                    <Name>property-name</Name>
1483
 
                    <Value>property-value</Value>
1484
 
                  </ExtendedProperty>
1485
 
                </ExtendedProperties>
1486
 
              </HostedServiceProperties>
1487
 
            </HostedService>
1488
 
          </HostedServices>
1489
 
    `
1490
 
    return fmt.Sprintf(input, url)
1491
 
}
1492
 
 
1493
 
func (suite *xmlSuite) TestHostedServiceDescriptorList(c *C) {
1494
 
    input := makeHostedServiceDescriptorList("hosted-service-address")
1495
 
    expected := &HostedServiceDescriptorList{
1496
 
        XMLName: xml.Name{
1497
 
            Space: "http://schemas.microsoft.com/windowsazure",
1498
 
            Local: "HostedServices"},
1499
 
        XMLNS: "http://schemas.microsoft.com/windowsazure",
1500
 
        HostedServices: []HostedServiceDescriptor{
1501
 
            {
1502
 
                URL:              "hosted-service-address",
1503
 
                ServiceName:      "hosted-service-name",
1504
 
                Description:      "description",
1505
 
                AffinityGroup:    "affinity-group",
1506
 
                Location:         "service-location",
1507
 
                Label:            "label",
1508
 
                Status:           "status",
1509
 
                DateCreated:      "date-created",
1510
 
                DateLastModified: "date-modified",
1511
 
                ExtendedProperties: []ExtendedProperty{
1512
 
                    {
1513
 
                        Name:  "property-name",
1514
 
                        Value: "property-value",
1515
 
                    },
1516
 
                },
1517
 
            },
1518
 
        },
1519
 
    }
1520
 
 
1521
 
    observed := &HostedServiceDescriptorList{}
1522
 
    err := observed.Deserialize([]byte(input))
1523
 
    c.Assert(err, IsNil)
1524
 
    c.Assert(observed, DeepEquals, expected)
1525
 
}
1526
 
 
1527
 
func (suite *xmlSuite) TestHostedServiceDescriptorGetLabel(c *C) {
1528
 
    serviceDesc := HostedServiceDescriptor{Label: ""}
1529
 
    label := MakeRandomString(10)
1530
 
    base64Label := base64.StdEncoding.EncodeToString([]byte(label))
1531
 
    serviceDesc.Label = base64Label
1532
 
    decodedLabel, err := serviceDesc.GetLabel()
1533
 
    c.Assert(err, IsNil)
1534
 
    c.Check(decodedLabel, DeepEquals, label)
1535
 
}
1536
 
 
1537
 
// TestCreateStorageService demonstrates that CreateHostedService is a
1538
 
// suitable container for the CreateHostedService XML tree that are required
1539
 
// for the Create Hosted Service API call.
1540
 
func (suite *xmlSuite) TestCreateHostedService(c *C) {
1541
 
    // From http://msdn.microsoft.com/en-us/library/windowsazure/gg441304.aspx
1542
 
    input := `
1543
 
        <?xml version="1.0" encoding="utf-8"?>
1544
 
        <CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure">
1545
 
          <ServiceName>service-name</ServiceName>
1546
 
          <Label>base64-encoded-service-label</Label>
1547
 
          <Description>description</Description>
1548
 
          <Location>location</Location>
1549
 
          <AffinityGroup>affinity-group</AffinityGroup>
1550
 
          <ExtendedProperties>
1551
 
            <ExtendedProperty>
1552
 
              <Name>property-name</Name>
1553
 
              <Value>property-value</Value>
1554
 
            </ExtendedProperty>
1555
 
          </ExtendedProperties>
1556
 
        </CreateHostedService>
1557
 
        `
1558
 
    expected := &CreateHostedService{
1559
 
        XMLNS:         XMLNS,
1560
 
        ServiceName:   "service-name",
1561
 
        Label:         "base64-encoded-service-label",
1562
 
        Description:   "description",
1563
 
        Location:      "location",
1564
 
        AffinityGroup: "affinity-group",
1565
 
        ExtendedProperties: []ExtendedProperty{
1566
 
            {
1567
 
                Name:  "property-name",
1568
 
                Value: "property-value",
1569
 
            },
1570
 
        },
1571
 
    }
1572
 
    observed := &CreateHostedService{}
1573
 
    err := observed.Deserialize([]byte(input))
1574
 
    c.Assert(err, IsNil)
1575
 
    c.Assert(observed, DeepEquals, expected)
1576
 
}
1577
 
 
1578
 
func (suite *xmlSuite) TestNewCreateHostedServiceWithLocation(c *C) {
1579
 
    serviceName := "serviceName"
1580
 
    label := "label"
1581
 
    location := "location"
1582
 
    createdHostedService := NewCreateHostedServiceWithLocation(serviceName, label, location)
1583
 
    base64label := base64.StdEncoding.EncodeToString([]byte(label))
1584
 
    c.Check(createdHostedService.ServiceName, DeepEquals, serviceName)
1585
 
    c.Check(createdHostedService.Label, DeepEquals, base64label)
1586
 
    c.Check(createdHostedService.Location, DeepEquals, location)
1587
 
}
1588
 
 
1589
 
func (suite *xmlSuite) TestNewCreateStorageServiceInputWithLocation(c *C) {
1590
 
    cssi := NewCreateStorageServiceInputWithLocation("name", "label", "location", "false")
1591
 
    c.Check(cssi.XMLNS, Equals, XMLNS)
1592
 
    c.Check(cssi.ServiceName, Equals, "name")
1593
 
    c.Check(cssi.Label, Equals, base64.StdEncoding.EncodeToString([]byte("label")))
1594
 
    c.Check(cssi.Location, Equals, "location")
1595
 
    c.Check(cssi.GeoReplicationEnabled, Equals, "false")
1596
 
}
1597
 
 
1598
 
func makeUpdateHostedService(label, description string, property ExtendedProperty) string {
1599
 
    template := dedent.Dedent(`
1600
 
        <UpdateHostedService xmlns="http://schemas.microsoft.com/windowsazure">
1601
 
          <Label>%s</Label>
1602
 
          <Description>%s</Description>
1603
 
          <ExtendedProperties>
1604
 
            <ExtendedProperty>
1605
 
              <Name>%s</Name>
1606
 
              <Value>%s</Value>
1607
 
            </ExtendedProperty>
1608
 
          </ExtendedProperties>
1609
 
        </UpdateHostedService>`)
1610
 
    return fmt.Sprintf(template, label, description, property.Name, property.Value)
1611
 
}
1612
 
 
1613
 
func (suite *xmlSuite) TestUpdateHostedService(c *C) {
1614
 
    label := MakeRandomString(10)
1615
 
    description := MakeRandomString(10)
1616
 
    property := ExtendedProperty{
1617
 
        Name:  "property-name",
1618
 
        Value: "property-value",
1619
 
    }
1620
 
    expected := makeUpdateHostedService(label, description, property)
1621
 
    input := UpdateHostedService{
1622
 
        XMLNS:       XMLNS,
1623
 
        Label:       label,
1624
 
        Description: description,
1625
 
        ExtendedProperties: []ExtendedProperty{
1626
 
            property,
1627
 
        },
1628
 
    }
1629
 
 
1630
 
    observed, err := input.Serialize()
1631
 
    c.Assert(err, IsNil)
1632
 
    c.Assert(observed, Equals, expected)
1633
 
}
1634
 
 
1635
 
func (suite *xmlSuite) TestNewUpdateHostedService(c *C) {
1636
 
    label := MakeRandomString(10)
1637
 
    description := MakeRandomString(10)
1638
 
    properties := []ExtendedProperty{
1639
 
        {
1640
 
            Name:  MakeRandomString(10),
1641
 
            Value: MakeRandomString(10),
1642
 
        },
1643
 
    }
1644
 
    updateHostedService := NewUpdateHostedService(
1645
 
        label, description, properties)
1646
 
    c.Check(
1647
 
        updateHostedService.Label, Equals,
1648
 
        base64.StdEncoding.EncodeToString([]byte(label)))
1649
 
    c.Check(updateHostedService.Description, Equals, description)
1650
 
    c.Check(updateHostedService.ExtendedProperties, DeepEquals, properties)
1651
 
}
1652
 
 
1653
 
func (suite *xmlSuite) TestBlockListSerialize(c *C) {
1654
 
    blockList := &BlockList{
1655
 
        XMLName: xml.Name{Local: "BlockList"},
1656
 
    }
1657
 
    blockList.Add(BlockListCommitted, "first-base64-encoded-block-id")
1658
 
    blockList.Add(BlockListUncommitted, "second-base64-encoded-block-id")
1659
 
    blockList.Add(BlockListLatest, "third-base64-encoded-block-id")
1660
 
    observed, err := blockList.Serialize()
1661
 
    c.Assert(err, IsNil)
1662
 
    expected := dedent.Dedent(`
1663
 
        <BlockList>
1664
 
          <Committed>Zmlyc3QtYmFzZTY0LWVuY29kZWQtYmxvY2staWQ=</Committed>
1665
 
          <Uncommitted>c2Vjb25kLWJhc2U2NC1lbmNvZGVkLWJsb2NrLWlk</Uncommitted>
1666
 
          <Latest>dGhpcmQtYmFzZTY0LWVuY29kZWQtYmxvY2staWQ=</Latest>
1667
 
        </BlockList>`)
1668
 
    c.Assert(string(observed), Equals, expected)
1669
 
}
1670
 
 
1671
 
func (suite *xmlSuite) TestGetBlockListDeserialize(c *C) {
1672
 
    input := `
1673
 
        <?xml version="1.0" encoding="utf-8"?>
1674
 
        <BlockList>
1675
 
          <CommittedBlocks>
1676
 
            <Block>
1677
 
              <Name>BlockId001</Name>
1678
 
              <Size>4194304</Size>
1679
 
            </Block>
1680
 
          </CommittedBlocks>
1681
 
          <UncommittedBlocks>
1682
 
            <Block>
1683
 
              <Name>BlockId002</Name>
1684
 
              <Size>1024</Size>
1685
 
            </Block>
1686
 
          </UncommittedBlocks>
1687
 
        </BlockList>`
1688
 
    observed := GetBlockList{}
1689
 
    err := observed.Deserialize([]byte(input))
1690
 
    c.Assert(err, IsNil)
1691
 
    expected := GetBlockList{
1692
 
        XMLName: xml.Name{Local: "BlockList"},
1693
 
        CommittedBlocks: []Block{
1694
 
            {
1695
 
                Name: "BlockId001",
1696
 
                Size: "4194304"},
1697
 
        },
1698
 
        UncommittedBlocks: []Block{
1699
 
            {
1700
 
                Name: "BlockId002",
1701
 
                Size: "1024"},
1702
 
        },
1703
 
    }
1704
 
    c.Check(observed, DeepEquals, expected)
1705
 
}
1706
 
 
1707
 
func makeOperationXML(operationType string) string {
1708
 
    XMLTemplate := dedent.Dedent(`
1709
 
        <%s xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1710
 
          <OperationType>%s</OperationType>
1711
 
        </%s>`)
1712
 
    return fmt.Sprintf(XMLTemplate, operationType, operationType, operationType)
1713
 
}
1714
 
 
1715
 
func (suite *managementAPISuite) TestStartRoleOperation(c *C) {
1716
 
    expectedXML := makeOperationXML("StartRoleOperation")
1717
 
    xml, err := marshalXML(startRoleOperation)
1718
 
    c.Assert(err, IsNil)
1719
 
    c.Check(string(xml), Equals, expectedXML)
1720
 
}
1721
 
 
1722
 
func (suite *managementAPISuite) TestRestartRoleOperation(c *C) {
1723
 
    expectedXML := makeOperationXML("RestartRoleOperation")
1724
 
    xml, err := marshalXML(restartRoleOperation)
1725
 
    c.Assert(err, IsNil)
1726
 
    c.Check(string(xml), Equals, expectedXML)
1727
 
}
1728
 
 
1729
 
func (suite *managementAPISuite) TestShutdownRoleOperation(c *C) {
1730
 
    expectedXML := makeOperationXML("ShutdownRoleOperation")
1731
 
    xml, err := marshalXML(shutdownRoleOperation)
1732
 
    c.Assert(err, IsNil)
1733
 
    c.Check(string(xml), Equals, expectedXML)
1734
 
}
1735
 
 
1736
 
// TestOSImageWRTAddOSImage demonstrates the OSImage is a suitable container
1737
 
// for the OSImage XML trees that are required for the Add OS Image API call.
1738
 
func (suite *xmlSuite) TestOSImageWRTAddOSImage(c *C) {
1739
 
    // From http://msdn.microsoft.com/en-us/library/windowsazure/jj157192.aspx
1740
 
    input := `
1741
 
        <OSImage xmlns="http://schemas.microsoft.com/windowsazure">
1742
 
           <Label>image-label</Label>
1743
 
           <MediaLink>uri-of-the-containing-blob</MediaLink>
1744
 
           <Name>image-name</Name>
1745
 
           <OS>Linux|Windows</OS>
1746
 
           <Eula>image-eula</Eula>
1747
 
           <Description>image-description</Description>
1748
 
           <ImageFamily>image-family</ImageFamily>
1749
 
           <PublishedDate>published-date</PublishedDate>
1750
 
           <IsPremium>true/false</IsPremium>
1751
 
           <ShowInGui>true/false</ShowInGui>
1752
 
           <PrivacyUri>http://www.example.com/privacypolicy.html</PrivacyUri>
1753
 
           <IconUri>http://www.example.com/favicon.png</IconUri>
1754
 
           <RecommendedVMSize>Small/Large/Medium/ExtraLarge</RecommendedVMSize>
1755
 
           <SmallIconUri>http://www.example.com/smallfavicon.png</SmallIconUri>
1756
 
           <Language>language-of-image</Language>
1757
 
        </OSImage>
1758
 
        `
1759
 
    expected := &OSImage{
1760
 
        Label:             "image-label",
1761
 
        MediaLink:         "uri-of-the-containing-blob",
1762
 
        Name:              "image-name",
1763
 
        OS:                "Linux|Windows",
1764
 
        EULA:              "image-eula",
1765
 
        Description:       "image-description",
1766
 
        ImageFamily:       "image-family",
1767
 
        PublishedDate:     "published-date",
1768
 
        IsPremium:         "true/false",
1769
 
        ShowInGUI:         "true/false",
1770
 
        PrivacyURI:        "http://www.example.com/privacypolicy.html",
1771
 
        IconURI:           "http://www.example.com/favicon.png",
1772
 
        RecommendedVMSize: "Small/Large/Medium/ExtraLarge",
1773
 
        SmallIconURI:      "http://www.example.com/smallfavicon.png",
1774
 
        Language:          "language-of-image",
1775
 
    }
1776
 
 
1777
 
    osimage := &OSImage{}
1778
 
    err := osimage.Deserialize([]byte(input))
1779
 
    c.Assert(err, IsNil)
1780
 
    c.Assert(osimage, DeepEquals, expected)
1781
 
}
1782
 
 
1783
 
// TestOSImageWRTListOSImages demonstrates that OSImage is a suitable
1784
 
// container for the OSImage XML subtrees that are returned from the List OS
1785
 
// Images API call.
1786
 
func (suite *xmlSuite) TestOSImageWRTListOSImages(c *C) {
1787
 
    // From http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx
1788
 
    input := `
1789
 
        <OSImage xmlns="http://schemas.microsoft.com/windowsazure">
1790
 
          <AffinityGroup>name-of-the-affinity-group</AffinityGroup>
1791
 
          <Category>category-of-the-image</Category>
1792
 
          <Label>image-description</Label>
1793
 
          <Location>geo-location-of-the-stored-image</Location>
1794
 
          <LogicalSizeInGB>123.456</LogicalSizeInGB>
1795
 
          <MediaLink>url-of-the-containing-blob</MediaLink>
1796
 
          <Name>image-name</Name>
1797
 
          <OS>operating-system-of-the-image</OS>
1798
 
          <Eula>image-eula</Eula>
1799
 
          <Description>image-description</Description>
1800
 
          <ImageFamily>image-family</ImageFamily>
1801
 
          <ShowInGui>true|false</ShowInGui>
1802
 
          <PublishedDate>published-date</PublishedDate>
1803
 
          <IsPremium>true|false</IsPremium>
1804
 
          <PrivacyUri>uri-of-privacy-policy</PrivacyUri>
1805
 
          <RecommendedVMSize>size-of-the-virtual-machine</RecommendedVMSize>
1806
 
          <PublisherName>publisher-identifier</PublisherName>
1807
 
          <PricingDetailLink>pricing-details</PricingDetailLink>
1808
 
          <SmallIconUri>uri-of-icon</SmallIconUri>
1809
 
          <Language>language-of-image</Language>
1810
 
        </OSImage>
1811
 
        `
1812
 
    expected := &OSImage{
1813
 
        AffinityGroup:     "name-of-the-affinity-group",
1814
 
        Category:          "category-of-the-image",
1815
 
        Label:             "image-description",
1816
 
        Location:          "geo-location-of-the-stored-image",
1817
 
        LogicalSizeInGB:   123.456,
1818
 
        MediaLink:         "url-of-the-containing-blob",
1819
 
        Name:              "image-name",
1820
 
        OS:                "operating-system-of-the-image",
1821
 
        EULA:              "image-eula",
1822
 
        Description:       "image-description",
1823
 
        ImageFamily:       "image-family",
1824
 
        ShowInGUI:         "true|false",
1825
 
        PublishedDate:     "published-date",
1826
 
        IsPremium:         "true|false",
1827
 
        PrivacyURI:        "uri-of-privacy-policy",
1828
 
        RecommendedVMSize: "size-of-the-virtual-machine",
1829
 
        PublisherName:     "publisher-identifier",
1830
 
        PricingDetailLink: "pricing-details",
1831
 
        SmallIconURI:      "uri-of-icon",
1832
 
        Language:          "language-of-image",
1833
 
    }
1834
 
 
1835
 
    osimage := &OSImage{}
1836
 
    err := osimage.Deserialize([]byte(input))
1837
 
    c.Assert(err, IsNil)
1838
 
    c.Assert(osimage, DeepEquals, expected)
1839
 
}
1840
 
 
1841
 
// TestOSImageWRTUpdateOSImage demonstrates the OSImage is a suitable
1842
 
// container for the OSImage XML trees that are required for the Update OS
1843
 
// Image API call.
1844
 
func (suite *xmlSuite) TestOSImageWRTUpdateOSImage(c *C) {
1845
 
    // From http://msdn.microsoft.com/en-us/library/windowsazure/jj157198.aspx
1846
 
    input := `
1847
 
        <OSImage xmlns="http://schemas.microsoft.com/windowsazure">
1848
 
          <Label>image-label</Label>
1849
 
          <Eula>image-eula</Eula>
1850
 
          <Description>Image-Description</Description>
1851
 
          <ImageFamily>Image-Family</ImageFamily>
1852
 
          <PublishedDate>published-date</PublishedDate>
1853
 
          <IsPremium>true/false</IsPremium>
1854
 
          <ShowInGui>true/false</ShowInGui>
1855
 
          <PrivacyUri>http://www.example.com/privacypolicy.html</PrivacyUri>
1856
 
          <IconUri>http://www.example.com/favicon.png</IconUri>
1857
 
          <RecommendedVMSize>Small/Large/Medium/ExtraLarge</RecommendedVMSize>
1858
 
          <SmallIconUri>http://www.example.com/smallfavicon.png</SmallIconUri>
1859
 
          <Language>language-of-image</Language>
1860
 
        </OSImage>
1861
 
        `
1862
 
    expected := &OSImage{
1863
 
        Label:             "image-label",
1864
 
        EULA:              "image-eula",
1865
 
        Description:       "Image-Description",
1866
 
        ImageFamily:       "Image-Family",
1867
 
        PublishedDate:     "published-date",
1868
 
        IsPremium:         "true/false",
1869
 
        ShowInGUI:         "true/false",
1870
 
        PrivacyURI:        "http://www.example.com/privacypolicy.html",
1871
 
        IconURI:           "http://www.example.com/favicon.png",
1872
 
        RecommendedVMSize: "Small/Large/Medium/ExtraLarge",
1873
 
        SmallIconURI:      "http://www.example.com/smallfavicon.png",
1874
 
        Language:          "language-of-image",
1875
 
    }
1876
 
 
1877
 
    osimage := &OSImage{}
1878
 
    err := osimage.Deserialize([]byte(input))
1879
 
    c.Assert(err, IsNil)
1880
 
    c.Assert(osimage, DeepEquals, expected)
1881
 
}
1882
 
 
1883
 
func (suite *xmlSuite) TestOSImageHasLocation(c *C) {
1884
 
    image := &OSImage{
1885
 
        Location: "East Asia;Southeast Asia;North Europe;West Europe;East US;West US",
1886
 
    }
1887
 
 
1888
 
    var testValues = []struct {
1889
 
        location       string
1890
 
        expectedResult bool
1891
 
    }{
1892
 
        {"East Asia", true},
1893
 
        {"West US", true},
1894
 
        {"Unknown location", false},
1895
 
    }
1896
 
    for _, test := range testValues {
1897
 
        c.Check(image.hasLocation(test.location), Equals, test.expectedResult)
1898
 
    }
1899
 
}
1900
 
 
1901
 
func (suite *xmlSuite) TestIsDailyBuild(c *C) {
1902
 
    c.Check((&OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}).isDailyBuild(), Equals, true)
1903
 
    c.Check((&OSImage{Label: "Ubuntu Server 12.04.2 LTS"}).isDailyBuild(), Equals, false)
1904
 
    c.Check((&OSImage{Label: "Ubuntu Server 13.04"}).isDailyBuild(), Equals, false)
1905
 
}
1906
 
 
1907
 
func (suite *xmlSuite) TestSortImages(c *C) {
1908
 
    input := `
1909
 
<?xml version="1.0"?>
1910
 
<Images xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1911
 
  <OSImage>
1912
 
    <Label>Label 1</Label>
1913
 
    <PublishedDate>2012-04-25T00:00:00Z</PublishedDate>
1914
 
  </OSImage>
1915
 
  <OSImage>
1916
 
    <Label>Label 2</Label>
1917
 
    <PublishedDate>2013-02-15T00:00:00Z</PublishedDate>
1918
 
  </OSImage>
1919
 
  <OSImage>
1920
 
    <Label>Label 3</Label>
1921
 
    <PublishedDate>2013-04-13T00:00:00Z</PublishedDate>
1922
 
  </OSImage>
1923
 
  <OSImage>
1924
 
    <Label>Label 4</Label>
1925
 
    <PublishedDate>2013-03-15T00:00:00Z</PublishedDate>
1926
 
  </OSImage>
1927
 
</Images>`
1928
 
 
1929
 
    images := &Images{}
1930
 
    err := images.Deserialize([]byte(input))
1931
 
    c.Assert(err, IsNil)
1932
 
 
1933
 
    sort.Sort(images)
1934
 
    labels := []string{
1935
 
        (*images).Images[0].Label,
1936
 
        (*images).Images[1].Label,
1937
 
        (*images).Images[2].Label,
1938
 
        (*images).Images[3].Label,
1939
 
    }
1940
 
    c.Check(labels, DeepEquals, []string{"Label 3", "Label 4", "Label 2", "Label 1"})
1941
 
}
1942
 
 
1943
 
func (suite *xmlSuite) TestGetLatestUbuntuImage(c *C) {
1944
 
    // This is real-world XML input.
1945
 
    input := `
1946
 
<?xml version="1.0"?>
1947
 
<Images xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1948
 
  <OSImage>
1949
 
    <Category>Canonical</Category>
1950
 
    <Label>Ubuntu Server 12.04.2 LTS</Label>
1951
 
    <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
1952
 
    <LogicalSizeInGB>30</LogicalSizeInGB>
1953
 
    <Name>b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_2-LTS-amd64-server-20130415-en-us-30GB</Name>
1954
 
    <OS>Linux</OS>
1955
 
    <ImageFamily>Ubuntu Server 12.04 LTS</ImageFamily>
1956
 
    <PublishedDate>2013-04-15T00:00:00Z</PublishedDate>
1957
 
    <IsPremium>false</IsPremium>
1958
 
    <PublisherName>Canonical</PublisherName>
1959
 
  </OSImage>
1960
 
  <OSImage>
1961
 
    <Category>Canonical</Category>
1962
 
    <Label>Ubuntu Server 12.10</Label>
1963
 
    <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
1964
 
    <LogicalSizeInGB>30</LogicalSizeInGB>
1965
 
    <Name>b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_10-amd64-server-20130414-en-us-30GB</Name>
1966
 
    <OS>Linux</OS>
1967
 
    <ImageFamily>Ubuntu 12.10</ImageFamily>
1968
 
    <PublishedDate>2013-04-15T00:00:00Z</PublishedDate>
1969
 
    <PublisherName>Canonical</PublisherName>
1970
 
  </OSImage>
1971
 
  <OSImage>
1972
 
    <Category>Canonical</Category>
1973
 
    <Label>Ubuntu Server 13.04 DAILY</Label>
1974
 
    <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
1975
 
    <LogicalSizeInGB>30</LogicalSizeInGB>
1976
 
    <Name>fake-name__Ubuntu-13_04-amd64-server-20130423-en-us-30GB</Name>
1977
 
    <OS>Linux</OS>
1978
 
    <ImageFamily>Ubuntu Server 13.04</ImageFamily>
1979
 
    <PublishedDate>2013-06-25T00:00:00Z</PublishedDate>
1980
 
    <PublisherName>Canonical</PublisherName>
1981
 
  </OSImage>
1982
 
  <OSImage>
1983
 
    <Category>Canonical</Category>
1984
 
    <Label>Ubuntu Server 13.04</Label>
1985
 
    <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
1986
 
    <LogicalSizeInGB>30</LogicalSizeInGB>
1987
 
    <Name>b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_04-amd64-server-20130423-en-us-30GB</Name>
1988
 
    <OS>Linux</OS>
1989
 
    <ImageFamily>Ubuntu Server 13.04</ImageFamily>
1990
 
    <PublishedDate>2013-04-25T00:00:00Z</PublishedDate>
1991
 
    <PublisherName>Canonical</PublisherName>
1992
 
  </OSImage>
1993
 
  <OSImage>
1994
 
    <Category>Canonical</Category>
1995
 
    <Label>Ubuntu Server 13.04 bogus publisher name</Label>
1996
 
    <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
1997
 
    <LogicalSizeInGB>30</LogicalSizeInGB>
1998
 
    <Name>b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_04-amd64-server-20130423-en-us-30GB</Name>
1999
 
    <OS>Linux</OS>
2000
 
    <PublishedDate>2013-05-25T00:00:00Z</PublishedDate>
2001
 
    <ImageFamily>Ubuntu Server 13.04</ImageFamily>
2002
 
    <PublisherName>Bogus publisher name</PublisherName>
2003
 
  </OSImage>
2004
 
</Images>`
2005
 
    images := &Images{}
2006
 
    err := images.Deserialize([]byte(input))
2007
 
    c.Assert(err, IsNil)
2008
 
 
2009
 
    var testValues = []struct {
2010
 
        releaseName   string
2011
 
        location      string
2012
 
        expectedError error
2013
 
        expectedLabel string
2014
 
    }{
2015
 
        {"13.04", "West US", nil, "Ubuntu Server 13.04"},
2016
 
        {"12.04", "West US", nil, "Ubuntu Server 12.04.2 LTS"},
2017
 
        {"bogus-name", "Unknown location", fmt.Errorf("No matching images found"), ""},
2018
 
    }
2019
 
    for _, test := range testValues {
2020
 
        image, err := images.GetLatestUbuntuImage(test.releaseName, test.location)
2021
 
        c.Check(err, DeepEquals, test.expectedError)
2022
 
        if image != nil {
2023
 
            c.Check(image.Label, Equals, test.expectedLabel)
2024
 
        }
2025
 
    }
2026
 
}
2027
 
 
2028
 
func (suite *xmlSuite) TestOperation(c *C) {
2029
 
    // From http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx
2030
 
    input := `
2031
 
        <?xml version="1.0" encoding="utf-8"?>
2032
 
          <Operation xmlns="http://schemas.microsoft.com/windowsazure">
2033
 
            <ID>request-id</ID>
2034
 
            <Status>InProgress|Succeeded|Failed</Status>
2035
 
            <!--Response includes HTTP status code only if the operation succeeded or failed -->
2036
 
            <HttpStatusCode>200</HttpStatusCode>
2037
 
            <!--Response includes additional error information only if the operation failed -->
2038
 
            <Error>
2039
 
              <Code>error-code</Code>
2040
 
              <Message>error-message</Message>
2041
 
            </Error>
2042
 
          </Operation>
2043
 
        `
2044
 
    expected := &Operation{
2045
 
        ID:             "request-id",
2046
 
        Status:         "InProgress|Succeeded|Failed",
2047
 
        HTTPStatusCode: 200,
2048
 
        ErrorCode:      "error-code",
2049
 
        ErrorMessage:   "error-message",
2050
 
    }
2051
 
    observed := &Operation{}
2052
 
    err := observed.Deserialize([]byte(input))
2053
 
    c.Assert(err, IsNil)
2054
 
    c.Assert(observed, DeepEquals, expected)
2055
220
}