@ -26,6 +26,10 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
vmType := "type"
vmType := "type"
location := "westeurope"
location := "westeurope"
networkProfile := compute . NetworkProfile { }
networkProfile := compute . NetworkProfile { }
provisioningStatusCode := "ProvisioningState/succeeded"
provisionDisplayStatus := "Provisioning succeeded"
powerStatusCode := "PowerState/running"
powerDisplayStatus := "VM running"
properties := & compute . VirtualMachineProperties {
properties := & compute . VirtualMachineProperties {
StorageProfile : & compute . StorageProfile {
StorageProfile : & compute . StorageProfile {
OsDisk : & compute . OSDisk {
OsDisk : & compute . OSDisk {
@ -33,6 +37,20 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
} ,
} ,
} ,
} ,
NetworkProfile : & networkProfile ,
NetworkProfile : & networkProfile ,
InstanceView : & compute . VirtualMachineInstanceView {
Statuses : & [ ] compute . InstanceViewStatus {
{
Code : & provisioningStatusCode ,
Level : "Info" ,
DisplayStatus : & provisionDisplayStatus ,
} ,
{
Code : & powerStatusCode ,
Level : "Info" ,
DisplayStatus : & powerDisplayStatus ,
} ,
} ,
} ,
}
}
testVM := compute . VirtualMachine {
testVM := compute . VirtualMachine {
@ -52,6 +70,7 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
OsType : "Linux" ,
OsType : "Linux" ,
Tags : map [ string ] * string { } ,
Tags : map [ string ] * string { } ,
NetworkProfile : networkProfile ,
NetworkProfile : networkProfile ,
PowerStateCode : "PowerState/running" ,
}
}
actualVM := mapFromVM ( testVM )
actualVM := mapFromVM ( testVM )
@ -69,6 +88,10 @@ func TestMapFromVMWithTags(t *testing.T) {
tags := map [ string ] * string {
tags := map [ string ] * string {
"prometheus" : new ( string ) ,
"prometheus" : new ( string ) ,
}
}
provisioningStatusCode := "ProvisioningState/succeeded"
provisionDisplayStatus := "Provisioning succeeded"
powerStatusCode := "PowerState/running"
powerDisplayStatus := "VM running"
networkProfile := compute . NetworkProfile { }
networkProfile := compute . NetworkProfile { }
properties := & compute . VirtualMachineProperties {
properties := & compute . VirtualMachineProperties {
StorageProfile : & compute . StorageProfile {
StorageProfile : & compute . StorageProfile {
@ -77,6 +100,20 @@ func TestMapFromVMWithTags(t *testing.T) {
} ,
} ,
} ,
} ,
NetworkProfile : & networkProfile ,
NetworkProfile : & networkProfile ,
InstanceView : & compute . VirtualMachineInstanceView {
Statuses : & [ ] compute . InstanceViewStatus {
{
Code : & provisioningStatusCode ,
Level : "Info" ,
DisplayStatus : & provisionDisplayStatus ,
} ,
{
Code : & powerStatusCode ,
Level : "Info" ,
DisplayStatus : & powerDisplayStatus ,
} ,
} ,
} ,
}
}
testVM := compute . VirtualMachine {
testVM := compute . VirtualMachine {
@ -96,6 +133,7 @@ func TestMapFromVMWithTags(t *testing.T) {
OsType : "Linux" ,
OsType : "Linux" ,
Tags : tags ,
Tags : tags ,
NetworkProfile : networkProfile ,
NetworkProfile : networkProfile ,
PowerStateCode : "PowerState/running" ,
}
}
actualVM := mapFromVM ( testVM )
actualVM := mapFromVM ( testVM )
@ -111,6 +149,10 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
vmType := "type"
vmType := "type"
location := "westeurope"
location := "westeurope"
networkProfile := compute . NetworkProfile { }
networkProfile := compute . NetworkProfile { }
provisioningStatusCode := "ProvisioningState/succeeded"
provisionDisplayStatus := "Provisioning succeeded"
powerStatusCode := "PowerState/running"
powerDisplayStatus := "VM running"
properties := & compute . VirtualMachineScaleSetVMProperties {
properties := & compute . VirtualMachineScaleSetVMProperties {
StorageProfile : & compute . StorageProfile {
StorageProfile : & compute . StorageProfile {
OsDisk : & compute . OSDisk {
OsDisk : & compute . OSDisk {
@ -118,6 +160,20 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
} ,
} ,
} ,
} ,
NetworkProfile : & networkProfile ,
NetworkProfile : & networkProfile ,
InstanceView : & compute . VirtualMachineInstanceView {
Statuses : & [ ] compute . InstanceViewStatus {
{
Code : & provisioningStatusCode ,
Level : "Info" ,
DisplayStatus : & provisionDisplayStatus ,
} ,
{
Code : & powerStatusCode ,
Level : "Info" ,
DisplayStatus : & powerDisplayStatus ,
} ,
} ,
} ,
}
}
testVM := compute . VirtualMachineScaleSetVM {
testVM := compute . VirtualMachineScaleSetVM {
@ -139,6 +195,7 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
Tags : map [ string ] * string { } ,
Tags : map [ string ] * string { } ,
NetworkProfile : networkProfile ,
NetworkProfile : networkProfile ,
ScaleSet : scaleSet ,
ScaleSet : scaleSet ,
PowerStateCode : "PowerState/running" ,
}
}
actualVM := mapFromVMScaleSetVM ( testVM , scaleSet )
actualVM := mapFromVMScaleSetVM ( testVM , scaleSet )
@ -157,6 +214,10 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
"prometheus" : new ( string ) ,
"prometheus" : new ( string ) ,
}
}
networkProfile := compute . NetworkProfile { }
networkProfile := compute . NetworkProfile { }
provisioningStatusCode := "ProvisioningState/succeeded"
provisionDisplayStatus := "Provisioning succeeded"
powerStatusCode := "PowerState/running"
powerDisplayStatus := "VM running"
properties := & compute . VirtualMachineScaleSetVMProperties {
properties := & compute . VirtualMachineScaleSetVMProperties {
StorageProfile : & compute . StorageProfile {
StorageProfile : & compute . StorageProfile {
OsDisk : & compute . OSDisk {
OsDisk : & compute . OSDisk {
@ -164,6 +225,20 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
} ,
} ,
} ,
} ,
NetworkProfile : & networkProfile ,
NetworkProfile : & networkProfile ,
InstanceView : & compute . VirtualMachineInstanceView {
Statuses : & [ ] compute . InstanceViewStatus {
{
Code : & provisioningStatusCode ,
Level : "Info" ,
DisplayStatus : & provisionDisplayStatus ,
} ,
{
Code : & powerStatusCode ,
Level : "Info" ,
DisplayStatus : & powerDisplayStatus ,
} ,
} ,
} ,
}
}
testVM := compute . VirtualMachineScaleSetVM {
testVM := compute . VirtualMachineScaleSetVM {
@ -185,6 +260,7 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
Tags : tags ,
Tags : tags ,
NetworkProfile : networkProfile ,
NetworkProfile : networkProfile ,
ScaleSet : scaleSet ,
ScaleSet : scaleSet ,
PowerStateCode : "PowerState/running" ,
}
}
actualVM := mapFromVMScaleSetVM ( testVM , scaleSet )
actualVM := mapFromVMScaleSetVM ( testVM , scaleSet )
@ -193,3 +269,52 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
t . Errorf ( "Expected %v got %v" , expectedVM , actualVM )
t . Errorf ( "Expected %v got %v" , expectedVM , actualVM )
}
}
}
}
func TestGetPowerStatusFromVM ( t * testing . T ) {
provisioningStatusCode := "ProvisioningState/succeeded"
provisionDisplayStatus := "Provisioning succeeded"
powerStatusCode := "PowerState/running"
powerDisplayStatus := "VM running"
properties := & compute . VirtualMachineScaleSetVMProperties {
StorageProfile : & compute . StorageProfile {
OsDisk : & compute . OSDisk {
OsType : "Linux" ,
} ,
} ,
InstanceView : & compute . VirtualMachineInstanceView {
Statuses : & [ ] compute . InstanceViewStatus {
{
Code : & provisioningStatusCode ,
Level : "Info" ,
DisplayStatus : & provisionDisplayStatus ,
} ,
{
Code : & powerStatusCode ,
Level : "Info" ,
DisplayStatus : & powerDisplayStatus ,
} ,
} ,
} ,
}
testVM := compute . VirtualMachineScaleSetVM {
Properties : properties ,
}
actual := getPowerStateFromVMInstanceView ( testVM . Properties . InstanceView )
expected := "PowerState/running"
if actual != expected {
t . Errorf ( "expected powerStatus %s, but got %s instead" , expected , actual )
}
// Noq we test a virtualMachine with an empty InstanceView struct.
testVM . Properties . InstanceView = & compute . VirtualMachineInstanceView { }
actual = getPowerStateFromVMInstanceView ( testVM . Properties . InstanceView )
if actual != "" {
t . Errorf ( "expected powerStatus %s, but got %s instead" , expected , actual )
}
}