...
1
2
3 package virtualmachine
4
5
6
7
8 import (
9 "encoding/xml"
10 "testing"
11 )
12
13 func TestDocumentedDeploymentRequest(t *testing.T) {
14
15
16 xmlString := `<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
17 <Name>name-of-deployment</Name>
18 <DeploymentSlot>deployment-environment</DeploymentSlot>
19 <Label>identifier-of-deployment</Label>
20 <RoleList>
21 <Role>
22 <RoleName>name-of-the-virtual-machine</RoleName>
23 <RoleType>PersistentVMRole</RoleType>
24 <ConfigurationSets>
25 <ConfigurationSet i:type="WindowsProvisioningConfigurationSet">
26 <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType>
27 <ComputerName>name-of-computer</ComputerName>
28 <AdminPassword>administrator-password</AdminPassword>
29 <EnableAutomaticUpdates>true</EnableAutomaticUpdates>
30 <TimeZone>time-zone</TimeZone>
31 <DomainJoin>
32 <Credentials>
33 <Domain>domain-to-join</Domain>
34 <Username>user-name-in-the-domain</Username>
35 <Password>password-for-the-user-name</Password>
36 </Credentials>
37 <JoinDomain>domain-to-join</JoinDomain>
38 <MachineObjectOU>distinguished-name-of-the-ou</MachineObjectOU>
39 </DomainJoin>
40 <StoredCertificateSettings>
41 <CertificateSetting>
42 <StoreLocation>LocalMachine</StoreLocation>
43 <StoreName>name-of-store-on-the-machine</StoreName>
44 <Thumbprint>certificate-thumbprint</Thumbprint>
45 </CertificateSetting>
46 </StoredCertificateSettings>
47 <WinRM>
48 <Listeners>
49 <Listener>
50 <Protocol>listener-protocol</Protocol>
51 </Listener>
52 <Listener>
53 <CertificateThumbprint>certificate-thumbprint</CertificateThumbprint>
54 <Protocol>listener-protocol</Protocol>
55 </Listener>
56 </Listeners>
57 </WinRM>
58 <AdminUsername>name-of-administrator-account</AdminUsername>
59 <CustomData>base-64-encoded-data</CustomData>
60 <AdditionalUnattendContent>
61 <Passes>
62 <UnattendPass>
63 <PassName>name-of-pass</PassName>
64 <Components>
65 <UnattendComponent>
66 <ComponentName>name-of-component</ComponentName>
67 <ComponentSettings>
68 <ComponentSetting>
69 <SettingName>name-of-setting</SettingName>
70 <Content>base-64-encoded-XML-content</Content>
71 </ComponentSetting>
72 </ComponentSettings>
73 </UnattendComponent>
74 </Components>
75 </UnattendPass>
76 </Passes>
77 </AdditionalUnattendContent>
78 </ConfigurationSet>
79 <ConfigurationSet i:type="LinuxProvisioningConfigurationSet">
80 <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
81 <HostName>host-name-for-the-virtual-machine</HostName>
82 <UserName>new-user-name</UserName>
83 <UserPassword>password-for-the-new-user</UserPassword>
84 <DisableSshPasswordAuthentication>true</DisableSshPasswordAuthentication>
85 <SSH>
86 <PublicKeys>
87 <PublicKey>
88 <FingerPrint>certificate-fingerprint</FingerPrint>
89 <Path>SSH-public-key-storage-location</Path>
90 </PublicKey>
91 </PublicKeys>
92 <KeyPairs>
93 <KeyPair>
94 <FingerPrint>certificate-fingerprint</FingerPrint>
95 <Path>SSH-public-key-storage-location</Path>
96 </KeyPair>
97 </KeyPairs>
98 </SSH>
99 <CustomData>base-64-encoded-data</CustomData>
100 </ConfigurationSet>
101 <ConfigurationSet>
102 <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
103 <InputEndpoints>
104 <InputEndpoint>
105 <LoadBalancedEndpointSetName>name-of-load-balanced-set</LoadBalancedEndpointSetName>
106 <LocalPort>22</LocalPort>
107 <Name>ZZH</Name>
108 <Port>33</Port>
109 <LoadBalancerProbe>
110 <Path>/probe/me</Path>
111 <Port>80</Port>
112 <Protocol>http</Protocol>
113 <IntervalInSeconds>30</IntervalInSeconds>
114 <TimeoutInSeconds>5</TimeoutInSeconds>
115 </LoadBalancerProbe>
116 <Protocol>endpoint-protocol</Protocol>
117 <EnableDirectServerReturn>enable-direct-server-return</EnableDirectServerReturn>
118 <EndpointACL>
119 <Rules>
120 <Rule>
121 <Order>priority-of-the-rule</Order>
122 <Action>permit-rule</Action>
123 <RemoteSubnet>subnet-of-the-rule</RemoteSubnet>
124 <Description>description-of-the-rule</Description>
125 </Rule>
126 </Rules>
127 </EndpointACL>
128 <LoadBalancerName>name-of-internal-loadbalancer</LoadBalancerName>
129 <IdleTimeoutInMinutes>9</IdleTimeoutInMinutes>
130 </InputEndpoint>
131 </InputEndpoints>
132 <SubnetNames>
133 <SubnetName>name-of-subnet</SubnetName>
134 </SubnetNames>
135 <StaticVirtualNetworkIPAddress>ip-address</StaticVirtualNetworkIPAddress>
136 <PublicIPs>
137 <PublicIP>
138 <Name>name-of-public-ip</Name>
139 <IdleTimeoutInMinutes>11</IdleTimeoutInMinutes>
140 </PublicIP>
141 </PublicIPs>
142 </ConfigurationSet>
143 </ConfigurationSets>
144 <ResourceExtensionReferences>
145 <ResourceExtensionReference>
146 <ReferenceName>name-of-reference</ReferenceName>
147 <Publisher>name-of-publisher</Publisher>
148 <Name>name-of-extension</Name>
149 <Version>version-of-extension</Version>
150 <ResourceExtensionParameterValues>
151 <ResourceExtensionParameterValue>
152 <Key>name-of-parameter-key</Key>
153 <Value>parameter-value</Value>
154 <Type>type-of-parameter</Type>
155 </ResourceExtensionParameterValue>
156 </ResourceExtensionParameterValues>
157 <State>state-of-resource</State>
158 <Certificates>
159 <Certificate>
160 <Thumbprint>certificate-thumbprint</Thumbprint>
161 <ThumbprintAlgorithm>certificate-algorithm</ThumbprintAlgorithm>
162 </Certificate>
163 </Certificates>
164 </ResourceExtensionReference>
165 </ResourceExtensionReferences>
166 <VMImageName>name-of-vm-image</VMImageName>
167 <MediaLocation>path-to-vhd</MediaLocation>
168 <AvailabilitySetName>name-of-availability-set</AvailabilitySetName>
169 <DataVirtualHardDisks>
170 <DataVirtualHardDisk>
171 <HostCaching>caching-mode</HostCaching>
172 <DiskLabel>label-of-data-disk</DiskLabel>
173 <DiskName>name-of-disk</DiskName>
174 <Lun>0</Lun>
175 <LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>
176 <MediaLink>path-to-vhd</MediaLink>
177 </DataVirtualHardDisk>
178 </DataVirtualHardDisks>
179 <OSVirtualHardDisk>
180 <HostCaching>caching-mode</HostCaching>
181 <DiskLabel>label-of-operating-system-disk</DiskLabel>
182 <DiskName>name-of-disk</DiskName>
183 <MediaLink>path-to-vhd</MediaLink>
184 <SourceImageName>name-of-source-image</SourceImageName>
185 <OS>operating-system-of-image</OS>
186 <RemoteSourceImageLink>path-to-source-image</RemoteSourceImageLink>
187 <ResizedSizeInGB>125</ResizedSizeInGB>
188 </OSVirtualHardDisk>
189 <RoleSize>size-of-virtual-machine</RoleSize>
190 <ProvisionGuestAgent>true</ProvisionGuestAgent>
191 <VMImageInput>
192 <OSDiskConfiguration>
193 <ResizedSizeInGB>126</ResizedSizeInGB>
194 </OSDiskConfiguration>
195 <DataDiskConfigurations>
196 <DataDiskConfiguration>
197 <Name>disk-name</Name>
198 <ResizedSizeInGB>127</ResizedSizeInGB>
199 </DataDiskConfiguration>
200 </DataDiskConfigurations>
201 </VMImageInput>
202 </Role>
203 </RoleList>
204 <VirtualNetworkName>name-of-virtual-network</VirtualNetworkName>
205 <Dns>
206 <DnsServers>
207 <DnsServer>
208 <Name>dns-name</Name>
209 <Address>dns-ip-address</Address>
210 </DnsServer>
211 </DnsServers>
212 </Dns>
213 <ReservedIPName>name-of-reserved-ip</ReservedIPName>
214 <LoadBalancers>
215 <LoadBalancer>
216 <Name>name-of-internal-load-balancer</Name>
217 <FrontendIpConfiguration>
218 <Type>Private</Type>
219 <SubnetName>name-of-subnet</SubnetName>
220 <StaticVirtualNetworkIPAddress>static-ip-address</StaticVirtualNetworkIPAddress>
221 </FrontendIpConfiguration>
222 </LoadBalancer>
223 </LoadBalancers>
224 </Deployment>`
225
226 deployment := DeploymentRequest{}
227 if err := xml.Unmarshal([]byte(xmlString), &deployment); err != nil {
228 t.Fatal(err)
229 }
230
231 if deployment.Name != "name-of-deployment" {
232 t.Fatalf("Expected deployment.Name=\"name-of-deployment\", but got \"%s\"",
233 deployment.Name)
234 }
235
236
237
238 t.Logf("deployment.RoleList[0]: %+v", deployment.RoleList[0])
239 if expected := "name-of-the-virtual-machine"; deployment.RoleList[0].RoleName != expected {
240 t.Fatalf("Expected deployment.RoleList[0].RoleName=%v, but got %v", expected, deployment.RoleList[0].RoleName)
241 }
242
243
244
245 t.Logf("deployment.DNSServers[0]: %+v", deployment.DNSServers[0])
246 if deployment.DNSServers[0].Name != "dns-name" {
247 t.Fatalf("Expected deployment.DNSServers[0].Name=\"dns-name\", but got \"%s\"",
248 deployment.DNSServers[0].Name)
249 }
250
251
252
253 t.Logf("deployment.LoadBalancers[0]: %+v", deployment.LoadBalancers[0])
254 if deployment.LoadBalancers[0].Name != "name-of-internal-load-balancer" {
255 t.Fatalf("Expected deployment.LoadBalancers[0].Name=\"name-of-internal-load-balancer\", but got \"%s\"",
256 deployment.LoadBalancers[0].Name)
257 }
258
259 if deployment.LoadBalancers[0].Type != IPAddressTypePrivate {
260 t.Fatalf("Expected deployment.LoadBalancers[0].Type=IPAddressTypePrivate, but got \"%s\"",
261 deployment.LoadBalancers[0].Type)
262 }
263
264 if deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress != "static-ip-address" {
265 t.Fatalf("Expected deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress=\"static-ip-address\", but got \"%s\"",
266 deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress)
267 }
268
269
270
271 extensionReferences := (*deployment.RoleList[0].ResourceExtensionReferences)
272 t.Logf("(*deployment.RoleList[0].ResourceExtensionReferences)[0]: %+v", extensionReferences[0])
273 if extensionReferences[0].Name != "name-of-extension" {
274 t.Fatalf("Expected (*deployment.RoleList[0].ResourceExtensionReferences)[0].Name=\"name-of-extension\", but got \"%s\"",
275 extensionReferences[0].Name)
276 }
277
278 if extensionReferences[0].ParameterValues[0].Key != "name-of-parameter-key" {
279 t.Fatalf("Expected (*deployment.RoleList[0].ResourceExtensionReferences)[0].ParameterValues[0].Key=\"name-of-parameter-key\", but got %v",
280 extensionReferences[0].ParameterValues[0].Key)
281 }
282
283
284
285 if deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB != 127 {
286 t.Fatalf("Expected deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB=127, but got %v",
287 deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB)
288 }
289
290
291
292 winRMlisteners := *deployment.RoleList[0].ConfigurationSets[0].WinRMListeners
293 if string(winRMlisteners[0].Protocol) != "listener-protocol" {
294 t.Fatalf("Expected winRMlisteners[0].Protocol to be listener-protocol, but got %s",
295 string(winRMlisteners[0].Protocol))
296 }
297
298 winRMlisteners2 := *deployment.RoleList[0].ConfigurationSets[0].WinRMListeners
299 if winRMlisteners2[1].CertificateThumbprint != "certificate-thumbprint" {
300 t.Fatalf("Expected winRMlisteners2[1].CertificateThumbprint to be certificate-thumbprint, but got %s",
301 winRMlisteners2[1].CertificateThumbprint)
302 }
303
304 }
305
View as plain text