mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Add unit tests
This commit is contained in:
parent
620a5b32a9
commit
d35c3a2299
@ -80,6 +80,21 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
|
|||||||
ID: &interfaceID,
|
ID: &interfaceID,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
ipConfigurations := []compute.VirtualMachineScaleSetIPConfiguration{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("ipconfig1"),
|
||||||
|
VirtualMachineScaleSetIPConfigurationProperties: &compute.VirtualMachineScaleSetIPConfigurationProperties{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
networkConfigurations := []compute.VirtualMachineScaleSetNetworkConfiguration{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("ipconfig1"),
|
||||||
|
ID: to.StringPtr("fakeNetworkConfiguration"),
|
||||||
|
VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{
|
||||||
|
IPConfigurations: &ipConfigurations,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
vmssVM := compute.VirtualMachineScaleSetVM{
|
vmssVM := compute.VirtualMachineScaleSetVM{
|
||||||
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
|
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
|
||||||
OsProfile: &compute.OSProfile{
|
OsProfile: &compute.OSProfile{
|
||||||
@ -88,6 +103,9 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
|
|||||||
NetworkProfile: &compute.NetworkProfile{
|
NetworkProfile: &compute.NetworkProfile{
|
||||||
NetworkInterfaces: &networkInterfaces,
|
NetworkInterfaces: &networkInterfaces,
|
||||||
},
|
},
|
||||||
|
NetworkProfileConfiguration: &compute.VirtualMachineScaleSetVMNetworkProfileConfiguration{
|
||||||
|
NetworkInterfaceConfigurations: &networkConfigurations,
|
||||||
|
},
|
||||||
InstanceView: &compute.VirtualMachineScaleSetVMInstanceView{
|
InstanceView: &compute.VirtualMachineScaleSetVMInstanceView{
|
||||||
PlatformFaultDomain: &faultDomain,
|
PlatformFaultDomain: &faultDomain,
|
||||||
},
|
},
|
||||||
@ -307,3 +325,52 @@ func TestGetIPByNodeName(t *testing.T) {
|
|||||||
assert.Equal(t, test.expected, []string{privateIP, publicIP}, test.description)
|
assert.Equal(t, test.expected, []string{privateIP, publicIP}, test.description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetNodeNameByIPConfigurationID(t *testing.T) {
|
||||||
|
ipConfigurationIDTemplate := "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s/networkInterfaces/%s/ipConfigurations/ipconfig1"
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
scaleSet string
|
||||||
|
vmList []string
|
||||||
|
ipConfigurationID string
|
||||||
|
expected string
|
||||||
|
expectError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "getNodeNameByIPConfigurationID should get node's Name when the node is existing",
|
||||||
|
scaleSet: "scaleset1",
|
||||||
|
ipConfigurationID: fmt.Sprintf(ipConfigurationIDTemplate, "scaleset1", "0", "scaleset1"),
|
||||||
|
vmList: []string{"vmssee6c2000000", "vmssee6c2000001"},
|
||||||
|
expected: "vmssee6c2000000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "getNodeNameByIPConfigurationID should return error for non-exist nodes",
|
||||||
|
scaleSet: "scaleset2",
|
||||||
|
ipConfigurationID: fmt.Sprintf(ipConfigurationIDTemplate, "scaleset2", "3", "scaleset1"),
|
||||||
|
vmList: []string{"vmssee6c2000002", "vmssee6c2000003"},
|
||||||
|
expectError: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "getNodeNameByIPConfigurationID should return error for wrong ipConfigurationID",
|
||||||
|
scaleSet: "scaleset3",
|
||||||
|
ipConfigurationID: "invalid-configuration-id",
|
||||||
|
vmList: []string{"vmssee6c2000004", "vmssee6c2000005"},
|
||||||
|
expectError: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
ss, err := newTestScaleSet(test.scaleSet, "", 0, test.vmList)
|
||||||
|
assert.NoError(t, err, test.description)
|
||||||
|
|
||||||
|
nodeName, err := ss.getNodeNameByIPConfigurationID(test.ipConfigurationID)
|
||||||
|
if test.expectError {
|
||||||
|
assert.Error(t, err, test.description)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, err, test.description)
|
||||||
|
assert.Equal(t, test.expected, nodeName, test.description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user