10
8
. "launchpad.net/gocheck"
11
"launchpad.net/gwacl/dedent"
15
type xmlSuite struct{}
17
var _ = Suite(&xmlSuite{})
20
// Tests for Marshallers
23
func (suite *xmlSuite) TestConfigurationSet(c *C) {
24
config := makeLinuxProvisioningConfiguration()
11
func (suite *GwaclSuite) TestLinuxProvisioningConfiguration(c *C) {
12
config := makeLinuxProvisioningConfiguration(provconfParams{})
26
14
xml, err := config.Serialize()
27
15
c.Assert(err, IsNil)
28
template := dedent.Dedent(`
30
<ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
31
<HostName>%s</HostName>
32
<UserName>%s</UserName>
33
<UserPassword>%s</UserPassword>
34
<UserData>%s</UserData>
35
<DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
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))
43
func (suite *xmlSuite) TestInputEndpoint(c *C) {
28
func (suite *GwaclSuite) TestInputEndpoint(c *C) {
44
29
endpoint := makeEndpoint(endpointParams{})
46
31
xml, err := endpoint.Serialize()
47
32
c.Assert(err, IsNil)
48
template := dedent.Dedent(`
50
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
51
<LocalPort>%v</LocalPort>
54
<Protocol>%s</Protocol>
56
expected := fmt.Sprintf(template, endpoint.LoadBalancedEndpointSetName,
57
endpoint.LocalPort, endpoint.Name, endpoint.Port, endpoint.Protocol)
33
expected := fmt.Sprintf(`
35
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
36
<LocalPort>%v</LocalPort>
39
<Protocol>%s</Protocol>
40
</InputEndpoint>`, endpoint.LoadBalancedEndpointSetName, endpoint.LocalPort,
41
endpoint.Name, endpoint.Port, endpoint.Protocol)
58
42
c.Check(xml, Equals, expected)
61
func (suite *xmlSuite) TestOSVirtualHardDisk(c *C) {
62
disk := makeOSVirtualHardDisk()
45
func (suite *GwaclSuite) TestOSVirtualHardDisk(c *C) {
46
disk := makeOSVirtualHardDisk(osVirtualHardDiskParams{})
64
48
xml, err := disk.Serialize()
65
49
c.Assert(err, IsNil)
66
template := dedent.Dedent(`
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(`
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)
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(`
88
<ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
91
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
92
<LocalPort>%v</LocalPort>
95
<Protocol>%s</Protocol>
98
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
99
<LocalPort>%v</LocalPort>
102
<Protocol>%s</Protocol>
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,
70
expected := fmt.Sprintf(`
71
<NetworkConfiguration>
74
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
75
<LocalPort>%v</LocalPort>
78
<Protocol>%s</Protocol>
81
<LoadBalancedEndpointSetName>%s</LoadBalancedEndpointSetName>
82
<LocalPort>%v</LocalPort>
85
<Protocol>%s</Protocol>
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)
114
func (suite *xmlSuite) TestRole(c *C) {
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})
118
101
xml, err := role.Serialize()
119
102
c.Assert(err, IsNil)
120
template := dedent.Dedent(`
122
<RoleName>%s</RoleName>
123
<RoleType>PersistentVMRole</RoleType>
126
<ConfigurationSetType>%s</ConfigurationSetType>
127
<HostName>%s</HostName>
128
<UserName>%s</UserName>
129
<UserPassword>%s</UserPassword>
130
<UserData>%s</UserData>
131
<DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
134
<RoleSize>%s</RoleSize>
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(`
105
<RoleSize>%s</RoleSize>
106
<RoleName>%s</RoleName>
107
<RoleType>PersistentVMRole</RoleType>
110
<ConfigurationSetType>%s</ConfigurationSetType>
111
<HostName>%s</HostName>
112
<UserName>%s</UserName>
113
<UserPassword>%s</UserPassword>
114
<DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
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)
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>
153
<ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
156
<LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
157
<LocalPort>1</LocalPort>
158
<Name>name-of-input-endpoint</Name>
161
<Path>path-of-probe</Path>
162
<Port>port-assigned-to-probe</Port>
163
<Protocol>protocol-of-input-endpoint</Protocol>
165
<Protocol>TCP|UDP</Protocol>
166
<Vip>virtual-ip-address-of-input-endpoint</Vip>
169
<LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
170
<LocalPort>2</LocalPort>
171
<Name>name-of-input-endpoint</Name>
174
<Path>path-of-probe</Path>
175
<Port>port-assigned-to-probe</Port>
176
<Protocol>protocol-of-input-endpoint</Protocol>
178
<Protocol>TCP|UDP</Protocol>
179
<Vip>virtual-ip-address-of-input-endpoint</Vip>
183
<SubnetName>name-of-subnet</SubnetName>
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>
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>
204
<RoleSize>size-of-instance</RoleSize>
205
<DefaultWinRmCertificateThumbprint>winrm-cert-thumbprint</DefaultWinRmCertificateThumbprint>
211
func (suite *xmlSuite) TestGetRole(c *C) {
212
expected := &GetRole{
214
Space: "http://schemas.microsoft.com/windowsazure",
215
Local: "PersistentVMRole"},
217
RoleName: "name-of-the-vm",
218
OsVersion: "operating-system-version",
219
RoleType: "PersistentVMRole",
220
ConfigurationSets: []ConfigurationSet{
222
ConfigurationSetType: "NetworkConfiguration",
223
InputEndpoints: &[]InputEndpoint{
225
LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
227
Name: "name-of-input-endpoint",
232
LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
234
Name: "name-of-input-endpoint",
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",
249
RoleSize: "size-of-instance",
250
DefaultWinRmCertificateThumbprint: "winrm-cert-thumbprint",
253
template := makeGetRoleResponse("name-of-the-vm")
255
observed := &GetRole{}
256
err := observed.Deserialize([]byte(template))
258
c.Assert(observed, DeepEquals, expected)
261
func (suite *xmlSuite) TestNetworkConfigurationSerialize(c *C) {
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>
269
<DnsServer name="dns-server-name" IPAddress="IPV4-address-of-the-server"></DnsServer>
273
<LocalNetworkSite name="local-site-name">
275
<AddressPrefix>CIDR-identifier</AddressPrefix>
277
<VPNGatewayAddress>IPV4-address-of-the-vpn-gateway</VPNGatewayAddress>
280
<VirtualNetworkSites>
281
<VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
283
<AddressPrefix>CIDR-identifier</AddressPrefix>
286
<Subnet name="subnet-name">
287
<AddressPrefix>CIDR-identifier</AddressPrefix>
291
<DnsServerRef name="primary-DNS-name"></DnsServerRef>
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>
303
</VirtualNetworkSite>
304
</VirtualNetworkSites>
305
</VirtualNetworkConfiguration>
306
</NetworkConfiguration>`)
308
input := NetworkConfiguration{
310
DNS: &[]VirtualNetDnsServer{
312
Name: "dns-server-name",
313
IPAddress: "IPV4-address-of-the-server",
316
LocalNetworkSites: &[]LocalNetworkSite{
318
Name: "local-site-name",
319
AddressSpacePrefixes: []string{
322
VPNGatewayAddress: "IPV4-address-of-the-vpn-gateway",
325
VirtualNetworkSites: &[]VirtualNetworkSite{
327
Name: "virtual-network-name",
328
AffinityGroup: "affinity-group-name",
329
AddressSpacePrefixes: []string{
335
AddressPrefix: "CIDR-identifier",
338
DnsServersRef: &[]DnsServerRef{
340
Name: "primary-DNS-name",
345
VPNClientAddressPoolPrefixes: []string{
348
LocalNetworkSiteRef: LocalNetworkSiteRef{
349
Name: "local-site-name",
350
Connection: LocalNetworkSiteRefConnection{
351
Type: "connection-type",
359
observed, err := input.Serialize()
361
c.Assert(observed, Equals, expected)
364
func (suite *xmlSuite) TestNetworkConfigurationSerializeMinimal(c *C) {
365
expected := fmt.Sprintf(
366
"\n<NetworkConfiguration xmlns=\"%s\"></NetworkConfiguration>",
368
input := NetworkConfiguration{XMLNS: XMLNS_NC}
369
observed, err := input.Serialize()
371
c.Assert(observed, Equals, expected)
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">
381
<AddressPrefix>CIDR-identifier</AddressPrefix>
383
</VirtualNetworkSite>
384
</VirtualNetworkSites>
385
</VirtualNetworkConfiguration>
386
</NetworkConfiguration>`)
387
input := NetworkConfiguration{
389
VirtualNetworkSites: &[]VirtualNetworkSite{
391
Name: "virtual-network-name",
392
AffinityGroup: "affinity-group-name",
393
AddressSpacePrefixes: []string{
399
observed, err := input.Serialize()
401
c.Assert(observed, Equals, expected)
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>`)
413
input := CreateAffinityGroup{
415
Name: "affinity-group-name",
416
Label: "base64-encoded-affinity-group-label",
417
Description: "affinity-group-description",
418
Location: "location"}
420
observed, err := input.Serialize()
422
c.Assert(observed, Equals, expected)
425
func (suite *xmlSuite) TestNewCreateAffinityGroup(c *C) {
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)
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{
447
Label: "base64-encoded-affinity-group-label",
448
Description: "affinity-group-description"}
450
observed, err := input.Serialize()
452
c.Assert(observed, Equals, expected)
455
func (suite *xmlSuite) TestNewUpdateAffinityGroup(c *C) {
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)
465
func (suite *xmlSuite) TestNetworkConfigurationDeserialize(c *C) {
467
// http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx
469
<NetworkConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
470
<VirtualNetworkConfiguration>
473
<DnsServer name="dns-server-name" IPAddress="IPV4-address-of-the-server"></DnsServer>
477
<LocalNetworkSite name="local-site-name">
479
<AddressPrefix>CIDR-identifier</AddressPrefix>
481
<VPNGatewayAddress>IPV4-address-of-the-vpn-gateway</VPNGatewayAddress>
484
<VirtualNetworkSites>
485
<VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
486
<Label>label-for-the-site</Label>
488
<AddressPrefix>CIDR-identifier</AddressPrefix>
491
<Subnet name="subnet-name">
492
<AddressPrefix>CIDR-identifier</AddressPrefix>
496
<DnsServerRef name="primary-DNS-name"></DnsServerRef>
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>
508
</VirtualNetworkSite>
509
</VirtualNetworkSites>
510
</VirtualNetworkConfiguration>
511
</NetworkConfiguration>`
512
expected := &NetworkConfiguration{
514
DNS: &[]VirtualNetDnsServer{
516
Name: "dns-server-name",
517
IPAddress: "IPV4-address-of-the-server",
520
LocalNetworkSites: &[]LocalNetworkSite{
522
Name: "local-site-name",
523
AddressSpacePrefixes: []string{
526
VPNGatewayAddress: "IPV4-address-of-the-vpn-gateway",
529
VirtualNetworkSites: &[]VirtualNetworkSite{
531
Name: "virtual-network-name",
532
AffinityGroup: "affinity-group-name",
533
AddressSpacePrefixes: []string{
539
AddressPrefix: "CIDR-identifier",
542
DnsServersRef: &[]DnsServerRef{
544
Name: "primary-DNS-name",
549
VPNClientAddressPoolPrefixes: []string{
552
LocalNetworkSiteRef: LocalNetworkSiteRef{
553
Name: "local-site-name",
554
Connection: LocalNetworkSiteRefConnection{
555
Type: "connection-type",
562
networkConfig := &NetworkConfiguration{}
563
err := networkConfig.Deserialize([]byte(input))
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)
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}
131
deployment := makeDeployment(deploymentParams{
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">
584
<DeploymentSlot>%s</DeploymentSlot>
586
<RoleInstanceList></RoleInstanceList>
589
<RoleName>%s</RoleName>
590
<RoleType>PersistentVMRole</RoleType>
593
<ConfigurationSetType>%s</ConfigurationSetType>
594
<HostName>%s</HostName>
595
<UserName>%s</UserName>
596
<UserPassword>%s</UserPassword>
597
<UserData>%s</UserData>
598
<DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
601
<RoleSize>%s</RoleSize>
604
<VirtualNetworkName>%s</VirtualNetworkName>
609
<Address>%s</Address>
613
<ExtendedProperties></ExtendedProperties>
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)
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>
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>
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>
655
<PowerState>state-of-role-instance</PowerState>
656
<HostName>dns-name-of-service</HostName>
657
<RemoteAccessCertificateThumbprint>cert-thumbprint-for-remote-access</RemoteAccessCertificateThumbprint>
661
<UpgradeType>auto|manual</UpgradeType>
662
<CurrentUpgradeDomainState>before|during</CurrentUpgradeDomainState>
663
<CurrentUpgradeDomain>n</CurrentUpgradeDomain>
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">
140
<DeploymentSlot>%s</DeploymentSlot>
668
<RoleName>name-of-role</RoleName>
669
<OsVersion>operating-system-version</OsVersion>
672
<ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
673
<DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
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>
683
<ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
687
<LocalPort>111</LocalPort>
688
<Protocol>TCP</Protocol>
689
<Name>test-name</Name>
693
<SubnetName>name-of-subnet</SubnetName>
149
<ConfigurationSetType>%s</ConfigurationSetType>
150
<HostName>%s</HostName>
151
<UserName>%s</UserName>
152
<UserPassword>%s</UserPassword>
153
<DisableSshPasswordAuthentication>%v</DisableSshPasswordAuthentication>
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>
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>
714
<RoleSize>size-of-instance</RoleSize>
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>
724
<Name>name-of-dns-server</Name>
725
<Address>address-of-dns-server</Address>
163
<Address>%s</Address>
731
<Name>name-of-property</Name>
732
<Value>value-of-property</Value>
734
</ExtendedProperties>
735
<PersistentVMDowntime>
736
<StartTime>start-of-downtime</StartTime>
737
<EndTime>end-of-downtime</EndTime>
738
<Status>status-of-downtime</Status>
739
</PersistentVMDowntime>
742
<Address>virtual-ip-address-of-deployment</Address>
745
<ExtensionConfiguration>
748
<Id>identifier-of-extension</Id>
754
<RoleName>role_name1</RoleName>
757
<Id>identifier-of-extension</Id>
763
</ExtensionConfiguration>
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{
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{
790
Name: "name-of-endpoint",
791
VIP: "virtual-ip-address-of-instance-endpoint",
794
Protocol: "protocol-of-instance-endpoint",
797
PowerState: "state-of-role-instance",
798
HostName: "dns-name-of-service",
799
RemoteAccessCertificateThumbprint: "cert-thumbprint-for-remote-access",
802
UpgradeDomainCount: "number-of-upgrade-domains-in-deployment",
805
RoleName: "name-of-role",
806
ConfigurationSets: []ConfigurationSet{
808
ConfigurationSetType: "LinuxProvisioningConfiguration",
809
DisableSSHPasswordAuthentication: "false",
814
RoleName: "name-of-role",
815
RoleType: "PersistentVMRole",
816
ConfigurationSets: []ConfigurationSet{
818
ConfigurationSetType: "NetworkConfiguration",
819
InputEndpoints: &[]InputEndpoint{
829
OSVirtualHardDisk: []OSVirtualHardDisk{
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",
838
RoleSize: "size-of-instance",
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",
847
Name: "name-of-dns-server",
848
Address: "address-of-dns-server",
851
ExtendedProperties: []ExtendedProperty{
853
Name: "name-of-property",
854
Value: "value-of-property",
858
observed := &Deployment{}
859
err := observed.Deserialize([]byte(deploymentXML))
861
c.Assert(observed, DeepEquals, expected)
864
func (suite *xmlSuite) TestDeploymentGetFQDNExtractsFQDN(c *C) {
865
deployment := &Deployment{}
866
err := deployment.Deserialize([]byte(deploymentXML))
868
fqdn, err := deployment.GetFQDN()
870
c.Assert(fqdn, Equals, "name-of-deployment.cloudapp.net")
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>
882
func (suite *xmlSuite) TestDeploymentGetFQDNErrorsIfURLIsEmpty(c *C) {
883
deployment := &Deployment{}
884
err := deployment.Deserialize([]byte(deploymentXMLEmptyURL))
886
_, err = deployment.GetFQDN()
887
c.Check(err, ErrorMatches, ".*URL field is empty.*")
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>
899
func (suite *xmlSuite) TestDeploymentGetFQDNErrorsIfURLCannotBeParsed(c *C) {
900
deployment := &Deployment{}
901
err := deployment.Deserialize([]byte(deploymentXMLFaultyURL))
903
_, err = deployment.GetFQDN()
904
c.Check(err, ErrorMatches, ".*invalid URL.*")
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"
915
deployment := NewDeploymentForCreateVMDeployment(name, deploymentSlot, label, roles, virtualNetworkName)
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)
924
c.Check(string(decodedLabel), Equals, label)
925
c.Check(deployment.VirtualNetworkName, Equals, virtualNetworkName)
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")
933
func (suite *xmlSuite) TestCreateVirtualHardDiskMediaLinkChecksParams(c *C) {
935
func() { CreateVirtualHardDiskMediaLink("foo^bar", "valid") },
936
PanicMatches, "'foo\\^bar' contains URI special characters")
938
func() { CreateVirtualHardDiskMediaLink("valid", "a/foo^bar/test") },
939
PanicMatches, "'foo\\^bar' contains URI special characters")
942
func (suite *xmlSuite) TestCreateStorageServiceInput(c *C) {
943
s := makeCreateStorageServiceInput()
944
extProperty := s.ExtendedProperties[0]
945
xml, err := s.Serialize()
947
template := dedent.Dedent(`
948
<CreateStorageServiceInput xmlns="http://schemas.microsoft.com/windowsazure">
949
<ServiceName>%s</ServiceName>
951
<Description>%s</Description>
952
<Location>%s</Location>
953
<AffinityGroup>%s</AffinityGroup>
954
<GeoReplicationEnabled>%s</GeoReplicationEnabled>
960
</ExtendedProperties>
961
</CreateStorageServiceInput>`)
962
expected := fmt.Sprintf(template, s.ServiceName, s.Label, s.Description,
963
s.Location, s.AffinityGroup, s.GeoReplicationEnabled, extProperty.Name,
965
c.Assert(xml, Equals, expected)
969
// Tests for Unmarshallers
972
func (suite *xmlSuite) TestStorageServicesUnmarshal(c *C) {
974
<?xml version="1.0" encoding="utf-8"?>
975
<StorageServices xmlns="http://schemas.microsoft.com/windowsazure">
978
<ServiceName>%s</ServiceName>
979
<StorageServiceProperties>
980
<Description>%s</Description>
981
<AffinityGroup>%s</AffinityGroup>
985
<Endpoint>%s</Endpoint>
986
<Endpoint>%s</Endpoint>
987
<Endpoint>%s</Endpoint>
989
<GeoReplicationEnabled>%s</GeoReplicationEnabled>
990
<GeoPrimaryRegion>%s</GeoPrimaryRegion>
991
<StatusOfPrimary>%s</StatusOfPrimary>
992
<LastGeoFailoverTime>%s</LastGeoFailoverTime>
993
<GeoSecondaryRegion>%s</GeoSecondaryRegion>
994
<StatusOfSecondary>%s</StatusOfSecondary>
1004
</ExtendedProperties>
1005
</StorageServiceProperties>
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)
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)
1034
services := &StorageServices{}
1035
err := services.Deserialize(data)
1036
c.Assert(err, IsNil)
1038
c.Check(len(services.StorageServices), Equals, 1)
1039
s := services.StorageServices[0]
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)
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)
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)
1068
func (suite *xmlSuite) TestBlobEnumerationResuts(c *C) {
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>
1078
<Name>blob-name</Name>
1079
<Snapshot>snapshot-date-time</Snapshot>
1080
<Url>blob-address</Url>
1082
<Last-Modified>last-modified</Last-Modified>
1084
<Content-Length>size-in-bytes</Content-Length>
1085
<Content-Type>blob-content-type</Content-Type>
1086
<Content-Encoding />
1087
<Content-Language />
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>
1096
<CopyStatus>copystatus</CopyStatus>
1097
<CopySource>copysource</CopySource>
1098
<CopyProgress>copyprogress</CopyProgress>
1099
<CopyCompletionTime>copycompletiontime</CopyCompletionTime>
1100
<CopyStatusDescription>copydesc</CopyStatusDescription>
1103
<MetaName1>metadataname1</MetaName1>
1104
<MetaName2>metadataname2</MetaName2>
1108
<Name>blob-prefix</Name>
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, "")
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")
1152
func (suite *xmlSuite) TestStorageAccountKeysUnmarshal(c *C) {
1154
<?xml version="1.0" encoding="utf-8"?>
1155
<StorageService xmlns="http://schemas.microsoft.com/windowsazure">
1157
<StorageServiceKeys>
1158
<Primary>%s</Primary>
1159
<Secondary>%s</Secondary>
1160
</StorageServiceKeys>
1162
url := MakeRandomString(10)
1163
key1 := MakeRandomString(10)
1164
key2 := MakeRandomString(10)
1165
input := fmt.Sprintf(template, url, key1, key2)
1166
data := []byte(input)
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)
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)
1176
176
// Tests for object factory functions.
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}
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")
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()
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")
1209
func (suite *xmlSuite) TestNewNetworkConfiguration(c *C) {
1215
inputendpoint := InputEndpoint{
1216
LoadBalancedEndpointSetName: bName, LocalPort: localPort, Name: name, Port: port, Protocol: protocol}
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")
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)
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)
1248
// Properties XML subtree for ListContainers Storage API call.
1249
func (suite *xmlSuite) TestProperties(c *C) {
1251
<?xml version="1.0" encoding="utf-8"?>
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>
1259
observed := &Properties{}
1260
err := xml.Unmarshal([]byte(input), observed)
1261
c.Assert(err, IsNil)
1263
expected := &Properties{
1264
LastModified: "date/time-value",
1266
LeaseStatus: "lease-status-value",
1267
LeaseState: "lease-state-value",
1268
LeaseDuration: "lease-duration-value",
1271
c.Assert(observed, DeepEquals, expected)
1274
// Metadata XML subtree for ListContainers Storage API call.
1275
func (suite *xmlSuite) TestMetadata(c *C) {
1277
<?xml version="1.0" encoding="utf-8"?>
1279
<metadata-name>metadata-value</metadata-name>
1281
observed := &Metadata{}
1282
err := xml.Unmarshal([]byte(input), observed)
1283
c.Assert(err, IsNil)
1285
expected := &Metadata{
1286
Items: []MetadataItem{
1288
XMLName: xml.Name{Local: "metadata-name"},
1289
Value: "metadata-value",
1294
c.Assert(observed, DeepEquals, expected)
1297
// Container XML subtree for ListContainers Storage API call.
1298
func (suite *xmlSuite) TestContainer(c *C) {
1300
<?xml version="1.0" encoding="utf-8"?>
1302
<Name>name-value</Name>
1303
<URL>url-value</URL>
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>
1312
<metadata-name>metadata-value</metadata-name>
1315
observed := &Container{}
1316
err := xml.Unmarshal([]byte(input), observed)
1317
c.Assert(err, IsNil)
1319
expected := &Container{
1320
XMLName: xml.Name{Local: "Container"},
1323
Properties: Properties{
1324
LastModified: "date/time-value",
1326
LeaseStatus: "lease-status-value",
1327
LeaseState: "lease-state-value",
1328
LeaseDuration: "lease-duration-value",
1331
Items: []MetadataItem{
1333
XMLName: xml.Name{Local: "metadata-name"},
1334
Value: "metadata-value",
1340
c.Assert(observed, DeepEquals, expected)
1343
// EnumerationResults XML tree for ListContainers Storage API call.
1344
func (suite *xmlSuite) TestContainerEnumerationResults(c *C) {
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>
1353
<Name>name-value</Name>
1354
<URL>url-value</URL>
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>
1363
<metadata-name>metadata-value</metadata-name>
1367
<NextMarker>next-marker-value</NextMarker>
1368
</EnumerationResults>`
1369
observed := &ContainerEnumerationResults{}
1370
err := observed.Deserialize([]byte(input))
1371
c.Assert(err, IsNil)
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{
1380
XMLName: xml.Name{Local: "Container"},
1383
Properties: Properties{
1384
LastModified: "date/time-value",
1386
LeaseStatus: "lease-status-value",
1387
LeaseState: "lease-state-value",
1388
LeaseDuration: "lease-duration-value",
1391
Items: []MetadataItem{
1393
XMLName: xml.Name{Local: "metadata-name"},
1394
Value: "metadata-value",
1400
NextMarker: "next-marker-value",
1403
c.Assert(observed, DeepEquals, expected)
1404
c.Assert(observed.Containers[0].Metadata.Items[0].Name(), Equals, "metadata-name")
1407
func (suite *xmlSuite) TestHostedService(c *C) {
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>
1423
<Name>name-of-property</Name>
1424
<Value>value-of-property</Value>
1426
</ExtendedProperties>
1427
</HostedServiceProperties>
1429
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
1430
<Name>name-of-deployment</Name>
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{
1449
Name: "name-of-property",
1450
Value: "value-of-property",
1453
Deployments: []Deployment{{
1454
XMLNS: "http://schemas.microsoft.com/windowsazure",
1455
Name: "name-of-deployment",
1459
observed := &HostedService{}
1460
err := observed.Deserialize([]byte(input))
1461
c.Assert(err, IsNil)
1462
c.Assert(observed, DeepEquals, expected)
1465
func makeHostedServiceDescriptorList(url string) string {
1467
<?xml version="1.0" encoding="utf-8"?>
1468
<HostedServices xmlns="http://schemas.microsoft.com/windowsazure">
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>
1482
<Name>property-name</Name>
1483
<Value>property-value</Value>
1485
</ExtendedProperties>
1486
</HostedServiceProperties>
1490
return fmt.Sprintf(input, url)
1493
func (suite *xmlSuite) TestHostedServiceDescriptorList(c *C) {
1494
input := makeHostedServiceDescriptorList("hosted-service-address")
1495
expected := &HostedServiceDescriptorList{
1497
Space: "http://schemas.microsoft.com/windowsazure",
1498
Local: "HostedServices"},
1499
XMLNS: "http://schemas.microsoft.com/windowsazure",
1500
HostedServices: []HostedServiceDescriptor{
1502
URL: "hosted-service-address",
1503
ServiceName: "hosted-service-name",
1504
Description: "description",
1505
AffinityGroup: "affinity-group",
1506
Location: "service-location",
1509
DateCreated: "date-created",
1510
DateLastModified: "date-modified",
1511
ExtendedProperties: []ExtendedProperty{
1513
Name: "property-name",
1514
Value: "property-value",
1521
observed := &HostedServiceDescriptorList{}
1522
err := observed.Deserialize([]byte(input))
1523
c.Assert(err, IsNil)
1524
c.Assert(observed, DeepEquals, expected)
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)
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
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>
1552
<Name>property-name</Name>
1553
<Value>property-value</Value>
1555
</ExtendedProperties>
1556
</CreateHostedService>
1558
expected := &CreateHostedService{
1560
ServiceName: "service-name",
1561
Label: "base64-encoded-service-label",
1562
Description: "description",
1563
Location: "location",
1564
AffinityGroup: "affinity-group",
1565
ExtendedProperties: []ExtendedProperty{
1567
Name: "property-name",
1568
Value: "property-value",
1572
observed := &CreateHostedService{}
1573
err := observed.Deserialize([]byte(input))
1574
c.Assert(err, IsNil)
1575
c.Assert(observed, DeepEquals, expected)
1578
func (suite *xmlSuite) TestNewCreateHostedServiceWithLocation(c *C) {
1579
serviceName := "serviceName"
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)
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")
1598
func makeUpdateHostedService(label, description string, property ExtendedProperty) string {
1599
template := dedent.Dedent(`
1600
<UpdateHostedService xmlns="http://schemas.microsoft.com/windowsazure">
1602
<Description>%s</Description>
1603
<ExtendedProperties>
1608
</ExtendedProperties>
1609
</UpdateHostedService>`)
1610
return fmt.Sprintf(template, label, description, property.Name, property.Value)
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",
1620
expected := makeUpdateHostedService(label, description, property)
1621
input := UpdateHostedService{
1624
Description: description,
1625
ExtendedProperties: []ExtendedProperty{
1630
observed, err := input.Serialize()
1631
c.Assert(err, IsNil)
1632
c.Assert(observed, Equals, expected)
1635
func (suite *xmlSuite) TestNewUpdateHostedService(c *C) {
1636
label := MakeRandomString(10)
1637
description := MakeRandomString(10)
1638
properties := []ExtendedProperty{
1640
Name: MakeRandomString(10),
1641
Value: MakeRandomString(10),
1644
updateHostedService := NewUpdateHostedService(
1645
label, description, properties)
1647
updateHostedService.Label, Equals,
1648
base64.StdEncoding.EncodeToString([]byte(label)))
1649
c.Check(updateHostedService.Description, Equals, description)
1650
c.Check(updateHostedService.ExtendedProperties, DeepEquals, properties)
1653
func (suite *xmlSuite) TestBlockListSerialize(c *C) {
1654
blockList := &BlockList{
1655
XMLName: xml.Name{Local: "BlockList"},
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(`
1664
<Committed>Zmlyc3QtYmFzZTY0LWVuY29kZWQtYmxvY2staWQ=</Committed>
1665
<Uncommitted>c2Vjb25kLWJhc2U2NC1lbmNvZGVkLWJsb2NrLWlk</Uncommitted>
1666
<Latest>dGhpcmQtYmFzZTY0LWVuY29kZWQtYmxvY2staWQ=</Latest>
1668
c.Assert(string(observed), Equals, expected)
1671
func (suite *xmlSuite) TestGetBlockListDeserialize(c *C) {
1673
<?xml version="1.0" encoding="utf-8"?>
1677
<Name>BlockId001</Name>
1678
<Size>4194304</Size>
1683
<Name>BlockId002</Name>
1686
</UncommittedBlocks>
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{
1698
UncommittedBlocks: []Block{
1704
c.Check(observed, DeepEquals, expected)
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>
1712
return fmt.Sprintf(XMLTemplate, operationType, operationType, operationType)
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)
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)
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)
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
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>
1759
expected := &OSImage{
1760
Label: "image-label",
1761
MediaLink: "uri-of-the-containing-blob",
1763
OS: "Linux|Windows",
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",
1777
osimage := &OSImage{}
1778
err := osimage.Deserialize([]byte(input))
1779
c.Assert(err, IsNil)
1780
c.Assert(osimage, DeepEquals, expected)
1783
// TestOSImageWRTListOSImages demonstrates that OSImage is a suitable
1784
// container for the OSImage XML subtrees that are returned from the List OS
1786
func (suite *xmlSuite) TestOSImageWRTListOSImages(c *C) {
1787
// From http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx
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>
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",
1820
OS: "operating-system-of-the-image",
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",
1835
osimage := &OSImage{}
1836
err := osimage.Deserialize([]byte(input))
1837
c.Assert(err, IsNil)
1838
c.Assert(osimage, DeepEquals, expected)
1841
// TestOSImageWRTUpdateOSImage demonstrates the OSImage is a suitable
1842
// container for the OSImage XML trees that are required for the Update OS
1844
func (suite *xmlSuite) TestOSImageWRTUpdateOSImage(c *C) {
1845
// From http://msdn.microsoft.com/en-us/library/windowsazure/jj157198.aspx
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>
1862
expected := &OSImage{
1863
Label: "image-label",
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",
1877
osimage := &OSImage{}
1878
err := osimage.Deserialize([]byte(input))
1879
c.Assert(err, IsNil)
1880
c.Assert(osimage, DeepEquals, expected)
1883
func (suite *xmlSuite) TestOSImageHasLocation(c *C) {
1885
Location: "East Asia;Southeast Asia;North Europe;West Europe;East US;West US",
1888
var testValues = []struct {
1892
{"East Asia", true},
1894
{"Unknown location", false},
1896
for _, test := range testValues {
1897
c.Check(image.hasLocation(test.location), Equals, test.expectedResult)
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)
1907
func (suite *xmlSuite) TestSortImages(c *C) {
1909
<?xml version="1.0"?>
1910
<Images xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1912
<Label>Label 1</Label>
1913
<PublishedDate>2012-04-25T00:00:00Z</PublishedDate>
1916
<Label>Label 2</Label>
1917
<PublishedDate>2013-02-15T00:00:00Z</PublishedDate>
1920
<Label>Label 3</Label>
1921
<PublishedDate>2013-04-13T00:00:00Z</PublishedDate>
1924
<Label>Label 4</Label>
1925
<PublishedDate>2013-03-15T00:00:00Z</PublishedDate>
1930
err := images.Deserialize([]byte(input))
1931
c.Assert(err, IsNil)
1935
(*images).Images[0].Label,
1936
(*images).Images[1].Label,
1937
(*images).Images[2].Label,
1938
(*images).Images[3].Label,
1940
c.Check(labels, DeepEquals, []string{"Label 3", "Label 4", "Label 2", "Label 1"})
1943
func (suite *xmlSuite) TestGetLatestUbuntuImage(c *C) {
1944
// This is real-world XML input.
1946
<?xml version="1.0"?>
1947
<Images xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
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>
1955
<ImageFamily>Ubuntu Server 12.04 LTS</ImageFamily>
1956
<PublishedDate>2013-04-15T00:00:00Z</PublishedDate>
1957
<IsPremium>false</IsPremium>
1958
<PublisherName>Canonical</PublisherName>
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>
1967
<ImageFamily>Ubuntu 12.10</ImageFamily>
1968
<PublishedDate>2013-04-15T00:00:00Z</PublishedDate>
1969
<PublisherName>Canonical</PublisherName>
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>
1978
<ImageFamily>Ubuntu Server 13.04</ImageFamily>
1979
<PublishedDate>2013-06-25T00:00:00Z</PublishedDate>
1980
<PublisherName>Canonical</PublisherName>
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>
1989
<ImageFamily>Ubuntu Server 13.04</ImageFamily>
1990
<PublishedDate>2013-04-25T00:00:00Z</PublishedDate>
1991
<PublisherName>Canonical</PublisherName>
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>
2000
<PublishedDate>2013-05-25T00:00:00Z</PublishedDate>
2001
<ImageFamily>Ubuntu Server 13.04</ImageFamily>
2002
<PublisherName>Bogus publisher name</PublisherName>
2006
err := images.Deserialize([]byte(input))
2007
c.Assert(err, IsNil)
2009
var testValues = []struct {
2013
expectedLabel string
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"), ""},
2019
for _, test := range testValues {
2020
image, err := images.GetLatestUbuntuImage(test.releaseName, test.location)
2021
c.Check(err, DeepEquals, test.expectedError)
2023
c.Check(image.Label, Equals, test.expectedLabel)
2028
func (suite *xmlSuite) TestOperation(c *C) {
2029
// From http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx
2031
<?xml version="1.0" encoding="utf-8"?>
2032
<Operation xmlns="http://schemas.microsoft.com/windowsazure">
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 -->
2039
<Code>error-code</Code>
2040
<Message>error-message</Message>
2044
expected := &Operation{
2046
Status: "InProgress|Succeeded|Failed",
2047
HTTPStatusCode: 200,
2048
ErrorCode: "error-code",
2049
ErrorMessage: "error-message",
2051
observed := &Operation{}
2052
err := observed.Deserialize([]byte(input))
2053
c.Assert(err, IsNil)
2054
c.Assert(observed, DeepEquals, expected)