2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
|
2022-07-27 16:02:33 -04:00
|
|
|
armcomputev2 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
|
2022-10-24 10:58:21 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/role"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetScaleSetVM(t *testing.T) {
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstance := metadata.InstanceMetadata{
|
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-10-06 06:14:41 -04:00
|
|
|
Role: role.Worker,
|
2022-08-04 05:08:20 -04:00
|
|
|
VPCIP: "192.0.2.0",
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
providerID string
|
|
|
|
networkInterfacesAPI networkInterfacesAPI
|
|
|
|
virtualMachineScaleSetVMsAPI virtualMachineScaleSetVMsAPI
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstance metadata.InstanceMetadata
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"getVM for scale set instance works": {
|
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstance: wantInstance,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"getVM for individual instance must fail": {
|
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"Get fails": {
|
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
|
|
|
virtualMachineScaleSetVMsAPI: newFailingGetScaleSetVirtualMachinesStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"conversion fails": {
|
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id",
|
|
|
|
virtualMachineScaleSetVMsAPI: newGetInvalidScaleSetVirtualMachinesStub(),
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
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{
|
|
|
|
networkInterfacesAPI: tc.networkInterfacesAPI,
|
|
|
|
virtualMachineScaleSetVMsAPI: tc.virtualMachineScaleSetVMsAPI,
|
|
|
|
}
|
|
|
|
instance, err := metadata.getScaleSetVM(context.Background(), tc.providerID)
|
|
|
|
|
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 TestListScaleSetVMs(t *testing.T) {
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstances := []metadata.InstanceMetadata{
|
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-10-06 06:14:41 -04:00
|
|
|
Role: role.Worker,
|
2022-08-04 05:08:20 -04:00
|
|
|
VPCIP: "192.0.2.0",
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{"user": {"key-data"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
networkInterfacesAPI networkInterfacesAPI
|
|
|
|
virtualMachineScaleSetVMsAPI virtualMachineScaleSetVMsAPI
|
|
|
|
scaleSetsAPI scaleSetsAPI
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstances []metadata.InstanceMetadata
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"listVMs works": {
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstances: wantInstances,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"invalid scale sets are skipped": {
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newVirtualMachineScaleSetsVMsStub(),
|
|
|
|
scaleSetsAPI: newListContainingNilScaleSetStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstances: wantInstances,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"listVMs can return 0 VMs": {
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
2022-07-27 16:02:33 -04:00
|
|
|
virtualMachineScaleSetVMsAPI: &stubVirtualMachineScaleSetVMsAPI{pager: &stubVirtualMachineScaleSetVMPager{}},
|
2022-03-22 11:03:15 -04:00
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstances: []metadata.InstanceMetadata{},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"can skip nil in VM list": {
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newListContainingNilScaleSetVirtualMachinesStub(),
|
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstances: wantInstances,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"converting instance fails": {
|
|
|
|
networkInterfacesAPI: newNetworkInterfacesStub(),
|
|
|
|
virtualMachineScaleSetVMsAPI: newListContainingInvalidScaleSetVirtualMachinesStub(),
|
|
|
|
scaleSetsAPI: newScaleSetsStub(),
|
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{
|
|
|
|
networkInterfacesAPI: tc.networkInterfacesAPI,
|
|
|
|
virtualMachineScaleSetVMsAPI: tc.virtualMachineScaleSetVMsAPI,
|
|
|
|
scaleSetsAPI: tc.scaleSetsAPI,
|
|
|
|
}
|
|
|
|
instances, err := metadata.listScaleSetVMs(context.Background(), "resource-group")
|
|
|
|
|
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 TestConvertScaleSetVMToCoreInstance(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
inVM armcomputev2.VirtualMachineScaleSetVM
|
2022-05-24 04:04:42 -04:00
|
|
|
inInterface []armnetwork.Interface
|
2022-08-04 05:08:20 -04:00
|
|
|
inPublicIP string
|
2022-05-24 04:04:42 -04:00
|
|
|
wantErr bool
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstance metadata.InstanceMetadata
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"conversion works": {
|
2022-07-27 16:02:33 -04:00
|
|
|
inVM: armcomputev2.VirtualMachineScaleSetVM{
|
|
|
|
Name: to.Ptr("scale-set-name_instance-id"),
|
|
|
|
ID: to.Ptr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"),
|
|
|
|
Tags: map[string]*string{"tag-key": to.Ptr("tag-value")},
|
|
|
|
Properties: &armcomputev2.VirtualMachineScaleSetVMProperties{
|
|
|
|
OSProfile: &armcomputev2.OSProfile{
|
|
|
|
ComputerName: to.Ptr("scale-set-name-instance-id"),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-24 04:04:42 -04:00
|
|
|
inInterface: []armnetwork.Interface{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
Name: to.Ptr("scale-set-name_instance-id"),
|
|
|
|
ID: to.Ptr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Network/networkInterfaces/interface-name"),
|
2022-05-24 04:04:42 -04:00
|
|
|
Properties: &armnetwork.InterfacePropertiesFormat{
|
|
|
|
IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
|
|
|
|
{
|
|
|
|
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
|
2022-07-27 16:02:33 -04:00
|
|
|
Primary: to.Ptr(true),
|
|
|
|
PrivateIPAddress: to.Ptr("192.0.2.0"),
|
2022-05-24 04:04:42 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-04 05:08:20 -04:00
|
|
|
inPublicIP: "192.0.2.100",
|
2022-06-28 10:08:05 -04:00
|
|
|
wantInstance: metadata.InstanceMetadata{
|
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-08-04 05:08:20 -04:00
|
|
|
VPCIP: "192.0.2.0",
|
|
|
|
PublicIP: "192.0.2.100",
|
2022-03-22 11:03:15 -04:00
|
|
|
SSHKeys: map[string][]string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid instance": {
|
2022-07-27 16:02:33 -04:00
|
|
|
inVM: armcomputev2.VirtualMachineScaleSetVM{},
|
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)
|
|
|
|
|
2022-10-06 06:14:41 -04:00
|
|
|
instance, err := convertScaleSetVMToCoreInstance(tc.inVM, tc.inInterface, tc.inPublicIP)
|
2022-03-22 11:03:15 -04:00
|
|
|
|
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 TestExtractScaleSetVMRole(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-10-06 06:14:41 -04:00
|
|
|
tags map[string]*string
|
2022-04-26 10:54:05 -04:00
|
|
|
wantRole role.Role
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
2022-10-06 06:14:41 -04:00
|
|
|
"control-plane role": {
|
2022-10-24 10:58:21 -04:00
|
|
|
tags: map[string]*string{cloud.TagRole: to.Ptr("control-plane")},
|
2022-06-29 09:26:29 -04:00
|
|
|
wantRole: role.ControlPlane,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-10-06 06:14:41 -04:00
|
|
|
"worker role": {
|
2022-10-24 10:58:21 -04:00
|
|
|
tags: map[string]*string{cloud.TagRole: to.Ptr("worker")},
|
2022-06-29 09:26:29 -04:00
|
|
|
wantRole: role.Worker,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"unknown role": {
|
2022-10-24 10:58:21 -04:00
|
|
|
tags: map[string]*string{cloud.TagRole: to.Ptr("foo")},
|
2022-10-06 06:14:41 -04:00
|
|
|
wantRole: role.Unknown,
|
|
|
|
},
|
|
|
|
"no role": {
|
|
|
|
tags: map[string]*string{},
|
|
|
|
wantRole: role.Unknown,
|
|
|
|
},
|
|
|
|
"nil role": {
|
2022-10-24 10:58:21 -04:00
|
|
|
tags: map[string]*string{cloud.TagRole: nil},
|
2022-10-06 06:14:41 -04:00
|
|
|
wantRole: role.Unknown,
|
|
|
|
},
|
|
|
|
"nil tags": {
|
|
|
|
tags: nil,
|
2022-04-26 10:54:05 -04:00
|
|
|
wantRole: role.Unknown,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2022-10-06 06:14:41 -04:00
|
|
|
role := extractScaleSetVMRole(tc.tags)
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantRole, role)
|
2022-03-22 11:03:15 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingGetScaleSetVirtualMachinesStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
|
|
|
getErr: errors.New("get err"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newGetInvalidScaleSetVirtualMachinesStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
2022-07-27 16:02:33 -04:00
|
|
|
getVM: armcomputev2.VirtualMachineScaleSetVM{},
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListContainingNilScaleSetVirtualMachinesStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
2022-07-27 16:02:33 -04:00
|
|
|
pager: &stubVirtualMachineScaleSetVMPager{
|
|
|
|
list: []armcomputev2.VirtualMachineScaleSetVM{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
Name: to.Ptr("scale-set-name_instance-id"),
|
|
|
|
ID: to.Ptr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"),
|
|
|
|
InstanceID: to.Ptr("instance-id"),
|
2022-03-22 11:03:15 -04:00
|
|
|
Tags: map[string]*string{
|
2022-10-24 10:58:21 -04:00
|
|
|
cloud.TagRole: to.Ptr("worker"),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-07-27 16:02:33 -04:00
|
|
|
Properties: &armcomputev2.VirtualMachineScaleSetVMProperties{
|
|
|
|
NetworkProfile: &armcomputev2.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcomputev2.NetworkInterfaceReference{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
ID: to.Ptr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id/networkInterfaces/interface-name"),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-27 16:02:33 -04:00
|
|
|
OSProfile: &armcomputev2.OSProfile{
|
|
|
|
ComputerName: to.Ptr("scale-set-name-instance-id"),
|
|
|
|
LinuxConfiguration: &armcomputev2.LinuxConfiguration{
|
|
|
|
SSH: &armcomputev2.SSHConfiguration{
|
|
|
|
PublicKeys: []*armcomputev2.SSHPublicKey{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
KeyData: to.Ptr("key-data"),
|
|
|
|
Path: to.Ptr("/home/user/.ssh/authorized_keys"),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListContainingInvalidScaleSetVirtualMachinesStub() *stubVirtualMachineScaleSetVMsAPI {
|
|
|
|
return &stubVirtualMachineScaleSetVMsAPI{
|
2022-07-27 16:02:33 -04:00
|
|
|
pager: &stubVirtualMachineScaleSetVMPager{
|
|
|
|
list: []armcomputev2.VirtualMachineScaleSetVM{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
InstanceID: to.Ptr("instance-id"),
|
|
|
|
Properties: &armcomputev2.VirtualMachineScaleSetVMProperties{
|
|
|
|
OSProfile: &armcomputev2.OSProfile{},
|
|
|
|
NetworkProfile: &armcomputev2.NetworkProfile{
|
|
|
|
NetworkInterfaces: []*armcomputev2.NetworkInterfaceReference{
|
2022-03-22 11:03:15 -04:00
|
|
|
{
|
2022-07-27 16:02:33 -04:00
|
|
|
ID: to.Ptr("/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id/networkInterfaces/interface-name"),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListContainingNilScaleSetStub() *stubScaleSetsAPI {
|
|
|
|
return &stubScaleSetsAPI{
|
2022-07-27 16:02:33 -04:00
|
|
|
pager: &stubVirtualMachineScaleSetsClientListPager{
|
|
|
|
list: []armcomputev2.VirtualMachineScaleSet{{Name: to.Ptr("scale-set-name")}},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 09:15:51 -04:00
|
|
|
|
|
|
|
func TestImageReferenceFromImage(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
img string
|
|
|
|
wantID *string
|
|
|
|
wantCommunityID *string
|
|
|
|
}{
|
|
|
|
"ID": {
|
|
|
|
img: "/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/constellation-images/providers/Microsoft.Compute/galleries/Constellation/images/constellation/versions/1.5.0",
|
|
|
|
wantID: to.Ptr("/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/constellation-images/providers/Microsoft.Compute/galleries/Constellation/images/constellation/versions/1.5.0"),
|
|
|
|
wantCommunityID: nil,
|
|
|
|
},
|
|
|
|
"Community": {
|
|
|
|
img: "/CommunityGalleries/ConstellationCVM-728bd310-e898-4450-a1ed-21cf2fb0d735/Images/feat-azure-cvm-sharing/Versions/2022.0826.084922",
|
|
|
|
wantID: nil,
|
|
|
|
wantCommunityID: to.Ptr("/CommunityGalleries/ConstellationCVM-728bd310-e898-4450-a1ed-21cf2fb0d735/Images/feat-azure-cvm-sharing/Versions/2022.0826.084922"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
ref := ImageReferenceFromImage(tc.img)
|
|
|
|
|
|
|
|
assert.Equal(tc.wantID, ref.ID)
|
|
|
|
assert.Equal(tc.wantCommunityID, ref.CommunityGalleryImageID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|