2022-03-22 11:03:15 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
|
2022-05-24 04:04:42 -04:00
|
|
|
"github.com/edgelesssys/constellation/coordinator/cloudprovider/cloudtypes"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/edgelesssys/constellation/coordinator/role"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
2022-05-24 04:04:42 -04:00
|
|
|
wantInstances := []cloudtypes.Instance{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
|
|
|
Name: "instance-name",
|
|
|
|
ProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name",
|
2022-05-24 04:04:42 -04:00
|
|
|
PrivateIPs: []string{"192.0.2.0"},
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "scale-set-name-instance-id",
|
|
|
|
ProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
2022-05-24 04:04:42 -04:00
|
|
|
PrivateIPs: []string{"192.0.2.0"},
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
networkInterfacesAPI networkInterfacesAPI
|
|
|
|
scaleSetsAPI scaleSetsAPI
|
|
|
|
virtualMachinesAPI virtualMachinesAPI
|
|
|
|
virtualMachineScaleSetVMsAPI virtualMachineScaleSetVMsAPI
|
|
|
|
tagsAPI tagsAPI
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-05-24 04:04:42 -04:00
|
|
|
wantInstances []cloudtypes.Instance
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"List works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
|
|
|
virtualMachinesAPI: newVirtualMachinesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
|
|
|
tagsAPI: newTagsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstances: wantInstances,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"providerID cannot be retrieved": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: &stubIMDSAPI{retrieveErr: errors.New("imds err")},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"providerID cannot be parsed": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: newInvalidIMDSStub(),
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"listVMs fails": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
virtualMachinesAPI: newFailingListsVirtualMachinesStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"listScaleSetVMs fails": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
|
|
|
virtualMachinesAPI: newVirtualMachinesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newFailingListsVirtualMachineScaleSetsVMsStub(),
|
|
|
|
tagsAPI: newTagsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
networkInterfacesAPI: tc.networkInterfacesAPI,
|
|
|
|
scaleSetsAPI: tc.scaleSetsAPI,
|
|
|
|
virtualMachinesAPI: tc.virtualMachinesAPI,
|
|
|
|
virtualMachineScaleSetVMsAPI: tc.virtualMachineScaleSetVMsAPI,
|
|
|
|
tagsAPI: tc.tagsAPI,
|
|
|
|
}
|
|
|
|
instances, err := metadata.List(context.Background())
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.ElementsMatch(tc.wantInstances, instances)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSelf(t *testing.T) {
|
2022-05-24 04:04:42 -04:00
|
|
|
wantVMInstance := cloudtypes.Instance{
|
2022-03-22 11:03:15 -04:00
|
|
|
Name: "instance-name",
|
|
|
|
ProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name",
|
2022-05-24 04:04:42 -04:00
|
|
|
PrivateIPs: []string{"192.0.2.0"},
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
}
|
2022-05-24 04:04:42 -04:00
|
|
|
wantScaleSetInstance := cloudtypes.Instance{
|
2022-03-22 11:03:15 -04:00
|
|
|
Name: "scale-set-name-instance-id",
|
|
|
|
ProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
2022-05-24 04:04:42 -04:00
|
|
|
PrivateIPs: []string{"192.0.2.0"},
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
networkInterfacesAPI networkInterfacesAPI
|
|
|
|
virtualMachinesAPI virtualMachinesAPI
|
|
|
|
virtualMachineScaleSetVMsAPI virtualMachineScaleSetVMsAPI
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-05-24 04:04:42 -04:00
|
|
|
wantInstance cloudtypes.Instance
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"self for individual instance works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachinesAPI: newVirtualMachinesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstance: wantVMInstance,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"self for scale set instance works": {
|
|
|
|
imdsAPI: newScaleSetIMDSStub(),
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachinesAPI: newVirtualMachinesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstance: wantScaleSetInstance,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"providerID cannot be retrieved": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: &stubIMDSAPI{retrieveErr: errors.New("imds err")},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"GetInstance fails": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
virtualMachinesAPI: newFailingGetVirtualMachinesStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
networkInterfacesAPI: tc.networkInterfacesAPI,
|
|
|
|
virtualMachinesAPI: tc.virtualMachinesAPI,
|
|
|
|
virtualMachineScaleSetVMsAPI: tc.virtualMachineScaleSetVMsAPI,
|
|
|
|
}
|
|
|
|
instance, err := metadata.Self(context.Background())
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantInstance, instance)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSignalRole(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI imdsAPI
|
|
|
|
tagsAPI tagsAPI
|
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"SignalRole works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
tagsAPI: newTagsStub(),
|
|
|
|
},
|
|
|
|
"SignalRole is not attempted on scale set vm": {
|
|
|
|
imdsAPI: newScaleSetIMDSStub(),
|
|
|
|
},
|
|
|
|
"providerID cannot be retrieved": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: &stubIMDSAPI{retrieveErr: errors.New("imds err")},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"setting tag fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
tagsAPI: newFailingTagsStub(),
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
tagsAPI: tc.tagsAPI,
|
|
|
|
}
|
|
|
|
err := metadata.SignalRole(context.Background(), role.Coordinator)
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 04:04:42 -04:00
|
|
|
func TestGetNetworkSecurityGroupName(t *testing.T) {
|
|
|
|
name := "network-security-group-name"
|
|
|
|
testCases := map[string]struct {
|
|
|
|
securityGroupsAPI securityGroupsAPI
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
wantName string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"GetNetworkSecurityGroupName works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
securityGroupsAPI: &stubSecurityGroupsAPI{
|
|
|
|
listPages: [][]*armnetwork.SecurityGroup{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(name),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantName: name,
|
|
|
|
},
|
|
|
|
"no security group": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
securityGroupsAPI: &stubSecurityGroupsAPI{},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"missing name in security group struct": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
securityGroupsAPI: &stubSecurityGroupsAPI{listPages: [][]*armnetwork.SecurityGroup{{{}}}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
securityGroupsAPI: tc.securityGroupsAPI,
|
|
|
|
}
|
|
|
|
name, err := metadata.GetNetworkSecurityGroupName(context.Background())
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal(tc.wantName, name)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSubnetworkCIDR(t *testing.T) {
|
|
|
|
subnetworkCIDR := "192.0.2.0/24"
|
|
|
|
name := "name"
|
|
|
|
testCases := map[string]struct {
|
|
|
|
virtualNetworksAPI virtualNetworksAPI
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
wantNetworkCIDR string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"GetSubnetworkCIDR works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
virtualNetworksAPI: &stubVirtualNetworksAPI{listPages: [][]*armnetwork.VirtualNetwork{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(name),
|
|
|
|
Properties: &armnetwork.VirtualNetworkPropertiesFormat{
|
|
|
|
Subnets: []*armnetwork.Subnet{
|
|
|
|
{Properties: &armnetwork.SubnetPropertiesFormat{AddressPrefix: to.StringPtr(subnetworkCIDR)}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
wantNetworkCIDR: subnetworkCIDR,
|
|
|
|
},
|
|
|
|
"no virtual networks found": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
virtualNetworksAPI: &stubVirtualNetworksAPI{listPages: [][]*armnetwork.VirtualNetwork{
|
|
|
|
{},
|
|
|
|
}},
|
|
|
|
wantErr: true,
|
|
|
|
wantNetworkCIDR: subnetworkCIDR,
|
|
|
|
},
|
|
|
|
"malformed network struct": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
virtualNetworksAPI: &stubVirtualNetworksAPI{listPages: [][]*armnetwork.VirtualNetwork{
|
|
|
|
{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
wantErr: true,
|
|
|
|
wantNetworkCIDR: subnetworkCIDR,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
virtualNetworksAPI: tc.virtualNetworksAPI,
|
|
|
|
}
|
|
|
|
subnetworkCIDR, err := metadata.GetSubnetworkCIDR(context.Background())
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal(tc.wantNetworkCIDR, subnetworkCIDR)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetLoadBalancerName(t *testing.T) {
|
|
|
|
loadBalancerName := "load-balancer-name"
|
|
|
|
testCases := map[string]struct {
|
|
|
|
loadBalancerAPI loadBalancerAPI
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
wantName string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"GetLoadBalancerName works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantName: loadBalancerName,
|
|
|
|
},
|
|
|
|
"invalid load balancer struct": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{listPages: [][]*armnetwork.LoadBalancer{{{}}}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"invalid missing name": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{listPages: [][]*armnetwork.LoadBalancer{{{
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{},
|
|
|
|
}}}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
loadBalancerAPI: tc.loadBalancerAPI,
|
|
|
|
}
|
|
|
|
loadbalancerName, err := metadata.GetLoadBalancerName(context.Background())
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal(tc.wantName, loadbalancerName)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetLoadBalancerIP(t *testing.T) {
|
|
|
|
loadBalancerName := "load-balancer-name"
|
|
|
|
publicIP := "192.0.2.1"
|
|
|
|
correctPublicIPID := "/subscriptions/subscription/resourceGroups/resourceGroup/providers/Microsoft.Network/publicIPAddresses/pubIPName"
|
|
|
|
someErr := errors.New("some error")
|
|
|
|
testCases := map[string]struct {
|
|
|
|
loadBalancerAPI loadBalancerAPI
|
|
|
|
publicIPAddressesAPI publicIPAddressesAPI
|
|
|
|
imdsAPI imdsAPI
|
|
|
|
wantIP string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"GetLoadBalancerIP works": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{
|
|
|
|
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
|
|
|
|
PublicIPAddress: &armnetwork.PublicIPAddress{
|
|
|
|
ID: &correctPublicIPID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
publicIPAddressesAPI: &stubPublicIPAddressesAPI{getResponse: armnetwork.PublicIPAddressesClientGetResponse{
|
|
|
|
PublicIPAddressesClientGetResult: armnetwork.PublicIPAddressesClientGetResult{
|
|
|
|
PublicIPAddress: armnetwork.PublicIPAddress{
|
|
|
|
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
|
|
|
|
IPAddress: &publicIP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
wantIP: publicIP,
|
|
|
|
},
|
|
|
|
"no load balancer": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"load balancer missing public IP reference": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{
|
|
|
|
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"public IP reference has wrong format": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{
|
|
|
|
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
|
|
|
|
PublicIPAddress: &armnetwork.PublicIPAddress{
|
|
|
|
ID: to.StringPtr("wrong-format"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"no public IP address found": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{
|
|
|
|
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
|
|
|
|
PublicIPAddress: &armnetwork.PublicIPAddress{
|
|
|
|
ID: &correctPublicIPID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
publicIPAddressesAPI: &stubPublicIPAddressesAPI{getErr: someErr},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"found public IP has no address field": {
|
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
loadBalancerAPI: &stubLoadBalancersAPI{
|
|
|
|
listPages: [][]*armnetwork.LoadBalancer{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr(loadBalancerName),
|
|
|
|
Properties: &armnetwork.LoadBalancerPropertiesFormat{
|
|
|
|
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
|
|
|
|
PublicIPAddress: &armnetwork.PublicIPAddress{
|
|
|
|
ID: &correctPublicIPID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
publicIPAddressesAPI: &stubPublicIPAddressesAPI{getResponse: armnetwork.PublicIPAddressesClientGetResponse{
|
|
|
|
PublicIPAddressesClientGetResult: armnetwork.PublicIPAddressesClientGetResult{
|
|
|
|
PublicIPAddress: armnetwork.PublicIPAddress{
|
|
|
|
Properties: &armnetwork.PublicIPAddressPropertiesFormat{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
loadBalancerAPI: tc.loadBalancerAPI,
|
|
|
|
publicIPAddressesAPI: tc.publicIPAddressesAPI,
|
|
|
|
}
|
|
|
|
loadbalancerName, err := metadata.GetLoadBalancerIP(context.Background())
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.Equal(tc.wantIP, loadbalancerName)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
func TestSetVPNIP(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
metadata := Metadata{}
|
|
|
|
assert.NoError(metadata.SetVPNIP(context.Background(), "192.0.2.0"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetadataSupported(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
metadata := Metadata{}
|
|
|
|
assert.True(metadata.Supported())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProviderID(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI imdsAPI
|
|
|
|
wantErr bool
|
|
|
|
wantProviderID string
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"providerID for individual instance works": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: newIMDSStub(),
|
|
|
|
wantProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"providerID for scale set instance works": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: newScaleSetIMDSStub(),
|
|
|
|
wantProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"imds retrieval fails": {
|
2022-04-26 10:54:05 -04:00
|
|
|
imdsAPI: &stubIMDSAPI{retrieveErr: errors.New("imds err")},
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
metadata := Metadata{
|
|
|
|
imdsAPI: tc.imdsAPI,
|
|
|
|
}
|
|
|
|
providerID, err := metadata.providerID(context.Background())
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantProviderID, providerID)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExtractInstanceTags(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
in map[string]*string
|
|
|
|
wantTags map[string]string
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"tags are extracted": {
|
2022-04-26 10:54:05 -04:00
|
|
|
in: map[string]*string{"key": to.StringPtr("value")},
|
|
|
|
wantTags: map[string]string{"key": "value"},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"nil values are skipped": {
|
2022-04-26 10:54:05 -04:00
|
|
|
in: map[string]*string{"key": nil},
|
|
|
|
wantTags: map[string]string{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tags := extractInstanceTags(tc.in)
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantTags, tags)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExtractSSHKeys(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
in armcompute.SSHConfiguration
|
|
|
|
wantKeys map[string][]string
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"ssh key is extracted": {
|
|
|
|
in: armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantKeys: map[string][]string{"user": {"key-data"}},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"invalid path is skipped": {
|
|
|
|
in: armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("invalid-path"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantKeys: map[string][]string{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"key data is nil": {
|
|
|
|
in: armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantKeys: map[string][]string{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"path is nil": {
|
|
|
|
in: armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantKeys: map[string][]string{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"public keys are nil": {
|
2022-04-26 10:54:05 -04:00
|
|
|
in: armcompute.SSHConfiguration{},
|
|
|
|
wantKeys: map[string][]string{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
keys := extractSSHKeys(tc.in)
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantKeys, keys)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newIMDSStub() *stubIMDSAPI {
|
|
|
|
return &stubIMDSAPI{
|
|
|
|
res: metadataResponse{Compute: struct {
|
|
|
|
ResourceID string `json:"resourceId,omitempty"`
|
|
|
|
}{"/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name"}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newScaleSetIMDSStub() *stubIMDSAPI {
|
|
|
|
return &stubIMDSAPI{
|
|
|
|
res: metadataResponse{Compute: struct {
|
|
|
|
ResourceID string `json:"resourceId,omitempty"`
|
|
|
|
}{"/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newInvalidIMDSStub() *stubIMDSAPI {
|
|
|
|
return &stubIMDSAPI{
|
|
|
|
res: metadataResponse{Compute: struct {
|
|
|
|
ResourceID string `json:"resourceId,omitempty"`
|
|
|
|
}{"invalid-resource-id"}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingIMDSStub() *stubIMDSAPI {
|
|
|
|
return &stubIMDSAPI{
|
|
|
|
retrieveErr: errors.New("imds retrieve error"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newNetworkInterfacesStub() *stubNetworkInterfacesAPI {
|
|
|
|
return &stubNetworkInterfacesAPI{
|
|
|
|
getInterface: armnetwork.Interface{
|
|
|
|
Name: to.StringPtr("interface-name"),
|
|
|
|
Properties: &armnetwork.InterfacePropertiesFormat{
|
|
|
|
IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
|
|
|
|
PrivateIPAddress: to.StringPtr("192.0.2.0"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newScaleSetsStub() *stubScaleSetsAPI {
|
|
|
|
return &stubScaleSetsAPI{
|
|
|
|
listPages: [][]*armcompute.VirtualMachineScaleSet{
|
|
|
|
{
|
|
|
|
&armcompute.VirtualMachineScaleSet{
|
|
|
|
Name: to.StringPtr("scale-set-name"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newVirtualMachinesStub() *stubVirtualMachinesAPI {
|
|
|
|
return &stubVirtualMachinesAPI{
|
|
|
|
getVM: armcompute.VirtualMachine{
|
|
|
|
Name: to.StringPtr("instance-name"),
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name"),
|
|
|
|
Properties: &armcompute.VirtualMachineProperties{
|
|
|
|
NetworkProfile: &armcompute.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
|
|
|
|
{
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/resource-group/providers/Microsoft.Network/networkInterfaces/interface-name"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OSProfile: &armcompute.OSProfile{
|
|
|
|
LinuxConfiguration: &armcompute.LinuxConfiguration{
|
|
|
|
SSH: &armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
listPages: [][]*armcompute.VirtualMachine{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: to.StringPtr("instance-name"),
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name"),
|
|
|
|
Properties: &armcompute.VirtualMachineProperties{
|
|
|
|
NetworkProfile: &armcompute.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
|
|
|
|
{
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Network/networkInterfaces/interface-name"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OSProfile: &armcompute.OSProfile{
|
|
|
|
LinuxConfiguration: &armcompute.LinuxConfiguration{
|
|
|
|
SSH: &armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingListsVirtualMachinesStub() *stubVirtualMachinesAPI {
|
|
|
|
return &stubVirtualMachinesAPI{
|
|
|
|
listPages: [][]*armcompute.VirtualMachine{
|
|
|
|
{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingGetVirtualMachinesStub() *stubVirtualMachinesAPI {
|
|
|
|
return &stubVirtualMachinesAPI{
|
|
|
|
getErr: errors.New("get err"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newVirtualMachineScaleSetsVMsStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
|
|
|
getVM: armcompute.VirtualMachineScaleSetVM{
|
|
|
|
Name: to.StringPtr("scale-set-name_instance-id"),
|
|
|
|
InstanceID: to.StringPtr("instance-id"),
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"),
|
|
|
|
Properties: &armcompute.VirtualMachineScaleSetVMProperties{
|
|
|
|
NetworkProfile: &armcompute.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
|
|
|
|
{
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id/networkInterfaces/interface-name"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OSProfile: &armcompute.OSProfile{
|
|
|
|
ComputerName: to.StringPtr("scale-set-name-instance-id"),
|
|
|
|
LinuxConfiguration: &armcompute.LinuxConfiguration{
|
|
|
|
SSH: &armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
listPages: [][]*armcompute.VirtualMachineScaleSetVM{
|
|
|
|
{
|
|
|
|
&armcompute.VirtualMachineScaleSetVM{
|
|
|
|
Name: to.StringPtr("scale-set-name_instance-id"),
|
|
|
|
InstanceID: to.StringPtr("instance-id"),
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"),
|
|
|
|
Properties: &armcompute.VirtualMachineScaleSetVMProperties{
|
|
|
|
NetworkProfile: &armcompute.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
|
|
|
|
{
|
|
|
|
ID: to.StringPtr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id/networkInterfaces/interface-name"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OSProfile: &armcompute.OSProfile{
|
|
|
|
ComputerName: to.StringPtr("scale-set-name-instance-id"),
|
|
|
|
LinuxConfiguration: &armcompute.LinuxConfiguration{
|
|
|
|
SSH: &armcompute.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcompute.SSHPublicKey{
|
|
|
|
{
|
|
|
|
KeyData: to.StringPtr("key-data"),
|
|
|
|
Path: to.StringPtr("/home/user/.ssh/authorized_keys"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingListsVirtualMachineScaleSetsVMsStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
|
|
|
listPages: [][]*armcompute.VirtualMachineScaleSetVM{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InstanceID: to.StringPtr("invalid-instance-id"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTagsStub() *stubTagsAPI {
|
|
|
|
return &stubTagsAPI{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingTagsStub() *stubTagsAPI {
|
|
|
|
return &stubTagsAPI{
|
|
|
|
createOrUpdateAtScopeErr: errors.New("createOrUpdateErr"),
|
|
|
|
updateAtScopeErr: errors.New("updateErr"),
|
|
|
|
}
|
|
|
|
}
|