// +build go1.7
package virtualmachineimage
// 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"
)
const xml1 = `
imgName
User
packer made image
OSDisk
ReadWrite
Generalized
Linux
https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12.vhd
30
Standard
PkrSrvf3mz03u4mi
PkrVMf3mz03u4mi
PkrVMf3mz03u4mi
Central US
2015-12-12T08:59:29.1936858Z
2015-12-12T08:59:29.1936858Z
PackerMade
Small
false
VMImageReadyForUse
StoppedVM
Small
`
const xml2 = `
imgName
User
packer made image
OSDisk
ReadWrite
Generalized
Linux
https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12.vhd
30
Standard
DataDisk1
ReadWrite
https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12-dd1.vhd
31
Standard
DataDisk2
ReadWrite
https://sa.blob.core.windows.net/images/PackerMade_Ubuntu_Serv14_2015-12-12-dd2.vhd
32
Standard
PkrSrvf3mz03u4mi
PkrVMf3mz03u4mi
PkrVMf3mz03u4mi
Central US
2015-12-12T08:59:29.1936858Z
2015-12-12T08:59:29.1936858Z
PackerMade
Small
false
VMImageReadyForUse
StoppedVM
Small
`
func Test_NoDataDisksUnmarshal(t *testing.T) {
var image VMImage
if err := xml.Unmarshal([]byte(xml1), &image); err != nil {
t.Fatal(err)
}
check := checker{t}
check.Equal(0, len(image.DataDiskConfigurations))
}
func Test_DataDiskCountUnmarshal(t *testing.T) {
var image VMImage
if err := xml.Unmarshal([]byte(xml2), &image); err != nil {
t.Fatal(err)
}
check := checker{t}
check.Equal(2, len(image.DataDiskConfigurations))
check.Equal("DataDisk1", image.DataDiskConfigurations[0].Name)
check.Equal("DataDisk2", image.DataDiskConfigurations[1].Name)
}
type checker struct{ *testing.T }
func (a *checker) Equal(expected, actual interface{}) {
if expected != actual {
a.T.Fatalf("Expected %q, but got %q", expected, actual)
}
}