mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Adjust unit tests for vmss
This commit is contained in:
parent
4d5e7b7cfb
commit
f32bd6a081
@ -28,6 +28,7 @@ go_library(
|
|||||||
"azure_storageaccount.go",
|
"azure_storageaccount.go",
|
||||||
"azure_vmsets.go",
|
"azure_vmsets.go",
|
||||||
"azure_vmss.go",
|
"azure_vmss.go",
|
||||||
|
"azure_vmss_cache.go",
|
||||||
"azure_wrap.go",
|
"azure_wrap.go",
|
||||||
"azure_zones.go",
|
"azure_zones.go",
|
||||||
],
|
],
|
||||||
|
@ -674,7 +674,7 @@ func (fVMC *fakeVirtualMachineScaleSetVMsClient) Get(resourceGroupName string, V
|
|||||||
fVMC.mutex.Lock()
|
fVMC.mutex.Lock()
|
||||||
defer fVMC.mutex.Unlock()
|
defer fVMC.mutex.Unlock()
|
||||||
|
|
||||||
vmKey := fmt.Sprintf("%s-%s", VMScaleSetName, instanceID)
|
vmKey := fmt.Sprintf("%s_%s", VMScaleSetName, instanceID)
|
||||||
if scaleSetMap, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
if scaleSetMap, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
||||||
if entity, ok := scaleSetMap[vmKey]; ok {
|
if entity, ok := scaleSetMap[vmKey]; ok {
|
||||||
return entity, nil
|
return entity, nil
|
||||||
|
@ -24,12 +24,15 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestScaleSet(scaleSetName string, vmList []string) *scaleSet {
|
func newTestScaleSet(scaleSetName string, vmList []string) (*scaleSet, error) {
|
||||||
cloud := getTestCloud()
|
cloud := getTestCloud()
|
||||||
setTestVirtualMachineCloud(cloud, scaleSetName, vmList)
|
setTestVirtualMachineCloud(cloud, scaleSetName, vmList)
|
||||||
ss := newScaleSet(cloud)
|
ss, err := newScaleSet(cloud)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return ss.(*scaleSet)
|
return ss.(*scaleSet), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string) {
|
func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string) {
|
||||||
@ -46,16 +49,16 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string)
|
|||||||
ssVMs := make(map[string]map[string]compute.VirtualMachineScaleSetVM)
|
ssVMs := make(map[string]map[string]compute.VirtualMachineScaleSetVM)
|
||||||
ssVMs["rg"] = make(map[string]compute.VirtualMachineScaleSetVM)
|
ssVMs["rg"] = make(map[string]compute.VirtualMachineScaleSetVM)
|
||||||
for i := range vmList {
|
for i := range vmList {
|
||||||
ID := fmt.Sprintf("azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d", scaleSetName, i)
|
ID := fmt.Sprintf("/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d", scaleSetName, i)
|
||||||
nodeName := vmList[i]
|
nodeName := vmList[i]
|
||||||
instanceID := fmt.Sprintf("%d", i)
|
instanceID := fmt.Sprintf("%d", i)
|
||||||
vmKey := fmt.Sprintf("%s-%s", scaleSetName, nodeName)
|
vmName := fmt.Sprintf("%s_%s", scaleSetName, instanceID)
|
||||||
networkInterfaces := []compute.NetworkInterfaceReference{
|
networkInterfaces := []compute.NetworkInterfaceReference{
|
||||||
{
|
{
|
||||||
ID: &nodeName,
|
ID: &nodeName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ssVMs["rg"][vmKey] = compute.VirtualMachineScaleSetVM{
|
ssVMs["rg"][vmName] = compute.VirtualMachineScaleSetVM{
|
||||||
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
|
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
|
||||||
OsProfile: &compute.OSProfile{
|
OsProfile: &compute.OSProfile{
|
||||||
ComputerName: &nodeName,
|
ComputerName: &nodeName,
|
||||||
@ -66,6 +69,7 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string)
|
|||||||
},
|
},
|
||||||
ID: &ID,
|
ID: &ID,
|
||||||
InstanceID: &instanceID,
|
InstanceID: &instanceID,
|
||||||
|
Name: &vmName,
|
||||||
Location: &ss.Location,
|
Location: &ss.Location,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,28 +120,29 @@ func TestGetInstanceIDByNodeName(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "scaleSet should get instance by node name",
|
description: "scaleSet should get instance by node name",
|
||||||
scaleSet: "ss",
|
scaleSet: "ss",
|
||||||
vmList: []string{"vm1", "vm2"},
|
vmList: []string{"vmssee6c2000000", "vmssee6c2000001"},
|
||||||
nodeName: "vm1",
|
nodeName: "vmssee6c2000001",
|
||||||
expected: "azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/0",
|
expected: "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "scaleSet should get instance by node name with upper cases hostname",
|
description: "scaleSet should get instance by node name with upper cases hostname",
|
||||||
scaleSet: "ss",
|
scaleSet: "ss",
|
||||||
vmList: []string{"VM1", "vm2"},
|
vmList: []string{"VMSSEE6C2000000", "VMSSEE6C2000001"},
|
||||||
nodeName: "vm1",
|
nodeName: "vmssee6c2000000",
|
||||||
expected: "azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/0",
|
expected: "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/0",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "scaleSet should not get instance for non-exist nodes",
|
description: "scaleSet should not get instance for non-exist nodes",
|
||||||
scaleSet: "ss",
|
scaleSet: "ss",
|
||||||
vmList: []string{"VM1", "vm2"},
|
vmList: []string{"vmssee6c2000000", "vmssee6c2000001"},
|
||||||
nodeName: "vm3",
|
nodeName: "agente6c2000005",
|
||||||
expectError: true,
|
expectError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
ss := newTestScaleSet(test.scaleSet, test.vmList)
|
ss, err := newTestScaleSet(test.scaleSet, test.vmList)
|
||||||
|
assert.NoError(t, err, test.description)
|
||||||
|
|
||||||
real, err := ss.GetInstanceIDByNodeName(test.nodeName)
|
real, err := ss.GetInstanceIDByNodeName(test.nodeName)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
|
Loading…
Reference in New Issue
Block a user