// +build go1.7 package virtualmachine // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. import ( "encoding/xml" "testing" ) func TestDocumentedDeploymentRequest(t *testing.T) { // xml based on https://msdn.microsoft.com/en-us/library/azure/jj157194.aspx // fixed typos, replaced strongly typed fields with values of correct type xmlString := ` name-of-deployment deployment-environment name-of-the-virtual-machine PersistentVMRole WindowsProvisioningConfiguration name-of-computer administrator-password true time-zone domain-to-join user-name-in-the-domain password-for-the-user-name domain-to-join distinguished-name-of-the-ou LocalMachine name-of-store-on-the-machine certificate-thumbprint listener-protocol certificate-thumbprint listener-protocol name-of-administrator-account base-64-encoded-data name-of-pass name-of-component name-of-setting base-64-encoded-XML-content LinuxProvisioningConfiguration host-name-for-the-virtual-machine new-user-name password-for-the-new-user true certificate-fingerprint SSH-public-key-storage-location certificate-fingerprint SSH-public-key-storage-location base-64-encoded-data NetworkConfiguration name-of-load-balanced-set 22 ZZH 33 /probe/me 80 http 30 5 endpoint-protocol enable-direct-server-return priority-of-the-rule permit-rule subnet-of-the-rule description-of-the-rule name-of-internal-loadbalancer 9 name-of-subnet ip-address name-of-public-ip 11 name-of-reference name-of-publisher name-of-extension version-of-extension name-of-parameter-key parameter-value type-of-parameter state-of-resource certificate-thumbprint certificate-algorithm name-of-vm-image path-to-vhd name-of-availability-set caching-mode label-of-data-disk name-of-disk 0 50 path-to-vhd caching-mode label-of-operating-system-disk name-of-disk path-to-vhd name-of-source-image operating-system-of-image path-to-source-image 125 size-of-virtual-machine true 126 disk-name 127 name-of-virtual-network dns-name
dns-ip-address
name-of-reserved-ip name-of-internal-load-balancer Private name-of-subnet static-ip-address
` deployment := DeploymentRequest{} if err := xml.Unmarshal([]byte(xmlString), &deployment); err != nil { t.Fatal(err) } if deployment.Name != "name-of-deployment" { t.Fatalf("Expected deployment.Name=\"name-of-deployment\", but got \"%s\"", deployment.Name) } // ====== t.Logf("deployment.RoleList[0]: %+v", deployment.RoleList[0]) if expected := "name-of-the-virtual-machine"; deployment.RoleList[0].RoleName != expected { t.Fatalf("Expected deployment.RoleList[0].RoleName=%v, but got %v", expected, deployment.RoleList[0].RoleName) } // ====== t.Logf("deployment.DNSServers[0]: %+v", deployment.DNSServers[0]) if deployment.DNSServers[0].Name != "dns-name" { t.Fatalf("Expected deployment.DNSServers[0].Name=\"dns-name\", but got \"%s\"", deployment.DNSServers[0].Name) } // ====== t.Logf("deployment.LoadBalancers[0]: %+v", deployment.LoadBalancers[0]) if deployment.LoadBalancers[0].Name != "name-of-internal-load-balancer" { t.Fatalf("Expected deployment.LoadBalancers[0].Name=\"name-of-internal-load-balancer\", but got \"%s\"", deployment.LoadBalancers[0].Name) } if deployment.LoadBalancers[0].Type != IPAddressTypePrivate { t.Fatalf("Expected deployment.LoadBalancers[0].Type=IPAddressTypePrivate, but got \"%s\"", deployment.LoadBalancers[0].Type) } if deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress != "static-ip-address" { t.Fatalf("Expected deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress=\"static-ip-address\", but got \"%s\"", deployment.LoadBalancers[0].StaticVirtualNetworkIPAddress) } // ====== extensionReferences := (*deployment.RoleList[0].ResourceExtensionReferences) t.Logf("(*deployment.RoleList[0].ResourceExtensionReferences)[0]: %+v", extensionReferences[0]) if extensionReferences[0].Name != "name-of-extension" { t.Fatalf("Expected (*deployment.RoleList[0].ResourceExtensionReferences)[0].Name=\"name-of-extension\", but got \"%s\"", extensionReferences[0].Name) } if extensionReferences[0].ParameterValues[0].Key != "name-of-parameter-key" { t.Fatalf("Expected (*deployment.RoleList[0].ResourceExtensionReferences)[0].ParameterValues[0].Key=\"name-of-parameter-key\", but got %v", extensionReferences[0].ParameterValues[0].Key) } // ====== if deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB != 127 { t.Fatalf("Expected deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB=127, but got %v", deployment.RoleList[0].VMImageInput.DataDiskConfigurations[0].ResizedSizeInGB) } // ====== winRMlisteners := *deployment.RoleList[0].ConfigurationSets[0].WinRMListeners if string(winRMlisteners[0].Protocol) != "listener-protocol" { t.Fatalf("Expected winRMlisteners[0].Protocol to be listener-protocol, but got %s", string(winRMlisteners[0].Protocol)) } winRMlisteners2 := *deployment.RoleList[0].ConfigurationSets[0].WinRMListeners if winRMlisteners2[1].CertificateThumbprint != "certificate-thumbprint" { t.Fatalf("Expected winRMlisteners2[1].CertificateThumbprint to be certificate-thumbprint, but got %s", winRMlisteners2[1].CertificateThumbprint) } }