1// +build go1.7 2 3package virtualmachineimage 4 5// Copyright 2017 Microsoft Corporation 6// 7// Licensed under the Apache License, Version 2.0 (the "License"); 8// you may not use this file except in compliance with the License. 9// You may obtain a copy of the License at 10// 11// http://www.apache.org/licenses/LICENSE-2.0 12// 13// Unless required by applicable law or agreed to in writing, software 14// distributed under the License is distributed on an "AS IS" BASIS, 15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16// See the License for the specific language governing permissions and 17// limitations under the License. 18 19import ( 20 "encoding/xml" 21 "testing" 22) 23 24const xml1 = ` 25<VMImage> 26 <Name>imgName</Name> 27 <Label>PackerMade_Ubuntu_Serv14</Label> 28 <Category>User</Category> 29 <Description>packer made image</Description> 30 <OSDiskConfiguration> 31 <Name>OSDisk</Name> 32 <HostCaching>ReadWrite</HostCaching> 33 <OSState>Generalized</OSState> 34 <OS>Linux</OS> 35 <MediaLink>https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12.vhd</MediaLink> 36 <LogicalDiskSizeInGB>30</LogicalDiskSizeInGB> 37 <IOType>Standard</IOType> 38 </OSDiskConfiguration> 39 <DataDiskConfigurations/> 40 <ServiceName>PkrSrvf3mz03u4mi</ServiceName> 41 <DeploymentName>PkrVMf3mz03u4mi</DeploymentName> 42 <RoleName>PkrVMf3mz03u4mi</RoleName> 43 <Location>Central US</Location> 44 <CreatedTime>2015-12-12T08:59:29.1936858Z</CreatedTime> 45 <ModifiedTime>2015-12-12T08:59:29.1936858Z</ModifiedTime> 46 <ImageFamily>PackerMade</ImageFamily> 47 <RecommendedVMSize>Small</RecommendedVMSize> 48 <IsPremium>false</IsPremium> 49 <VMImageState>VMImageReadyForUse</VMImageState> 50 <RoleStateOnCapture>StoppedVM</RoleStateOnCapture> 51 <RoleSizeOnCapture>Small</RoleSizeOnCapture> 52</VMImage>` 53const xml2 = ` 54<VMImage> 55 <Name>imgName</Name> 56 <Label>PackerMade_Ubuntu_Serv14</Label> 57 <Category>User</Category> 58 <Description>packer made image</Description> 59 <OSDiskConfiguration> 60 <Name>OSDisk</Name> 61 <HostCaching>ReadWrite</HostCaching> 62 <OSState>Generalized</OSState> 63 <OS>Linux</OS> 64 <MediaLink>https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12.vhd</MediaLink> 65 <LogicalDiskSizeInGB>30</LogicalDiskSizeInGB> 66 <IOType>Standard</IOType> 67 </OSDiskConfiguration> 68 <DataDiskConfigurations> 69 <DataDiskConfiguration> 70 <Name>DataDisk1</Name> 71 <HostCaching>ReadWrite</HostCaching> 72 <MediaLink>https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12-dd1.vhd</MediaLink> 73 <LogicalDiskSizeInGB>31</LogicalDiskSizeInGB> 74 <IOType>Standard</IOType> 75 </DataDiskConfiguration> 76 <DataDiskConfiguration> 77 <Name>DataDisk2</Name> 78 <HostCaching>ReadWrite</HostCaching> 79 <MediaLink>https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12-dd2.vhd</MediaLink> 80 <LogicalDiskSizeInGB>32</LogicalDiskSizeInGB> 81 <IOType>Standard</IOType> 82 </DataDiskConfiguration> 83 </DataDiskConfigurations> 84 <ServiceName>PkrSrvf3mz03u4mi</ServiceName> 85 <DeploymentName>PkrVMf3mz03u4mi</DeploymentName> 86 <RoleName>PkrVMf3mz03u4mi</RoleName> 87 <Location>Central US</Location> 88 <CreatedTime>2015-12-12T08:59:29.1936858Z</CreatedTime> 89 <ModifiedTime>2015-12-12T08:59:29.1936858Z</ModifiedTime> 90 <ImageFamily>PackerMade</ImageFamily> 91 <RecommendedVMSize>Small</RecommendedVMSize> 92 <IsPremium>false</IsPremium> 93 <VMImageState>VMImageReadyForUse</VMImageState> 94 <RoleStateOnCapture>StoppedVM</RoleStateOnCapture> 95 <RoleSizeOnCapture>Small</RoleSizeOnCapture> 96</VMImage>` 97 98func Test_NoDataDisksUnmarshal(t *testing.T) { 99 var image VMImage 100 if err := xml.Unmarshal([]byte(xml1), &image); err != nil { 101 t.Fatal(err) 102 } 103 104 check := checker{t} 105 check.Equal(0, len(image.DataDiskConfigurations)) 106} 107 108func Test_DataDiskCountUnmarshal(t *testing.T) { 109 var image VMImage 110 if err := xml.Unmarshal([]byte(xml2), &image); err != nil { 111 t.Fatal(err) 112 } 113 114 check := checker{t} 115 check.Equal(2, len(image.DataDiskConfigurations)) 116 check.Equal("DataDisk1", image.DataDiskConfigurations[0].Name) 117 check.Equal("DataDisk2", image.DataDiskConfigurations[1].Name) 118} 119 120type checker struct{ *testing.T } 121 122func (a *checker) Equal(expected, actual interface{}) { 123 if expected != actual { 124 a.T.Fatalf("Expected %q, but got %q", expected, actual) 125 } 126} 127