mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
fix azure TestGetInstanceIDByNodeName data race
This commit is contained in:
parent
bc361fae40
commit
d77d20dd54
@ -24,12 +24,15 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestScaleSet() *scaleSet {
|
func newTestScaleSet(scaleSetName string, vmList []string) *scaleSet {
|
||||||
ss := newScaleSet(getTestCloud())
|
cloud := getTestCloud()
|
||||||
|
setTestVirtualMachineCloud(cloud, scaleSetName, vmList)
|
||||||
|
ss := newScaleSet(cloud)
|
||||||
|
|
||||||
return ss.(*scaleSet)
|
return ss.(*scaleSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTestVirtualMachineScaleSets(ss *scaleSet, scaleSetName string, vmList []string) {
|
func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string) {
|
||||||
virtualMachineScaleSetsClient := newFakeVirtualMachineScaleSetsClient()
|
virtualMachineScaleSetsClient := newFakeVirtualMachineScaleSetsClient()
|
||||||
scaleSets := make(map[string]map[string]compute.VirtualMachineScaleSet)
|
scaleSets := make(map[string]map[string]compute.VirtualMachineScaleSet)
|
||||||
scaleSets["rg"] = map[string]compute.VirtualMachineScaleSet{
|
scaleSets["rg"] = map[string]compute.VirtualMachineScaleSet{
|
||||||
@ -63,13 +66,13 @@ func setTestVirtualMachineScaleSets(ss *scaleSet, scaleSetName string, vmList []
|
|||||||
},
|
},
|
||||||
ID: &ID,
|
ID: &ID,
|
||||||
InstanceID: &instanceID,
|
InstanceID: &instanceID,
|
||||||
Location: &ss.Cloud.Location,
|
Location: &ss.Location,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtualMachineScaleSetVMsClient.setFakeStore(ssVMs)
|
virtualMachineScaleSetVMsClient.setFakeStore(ssVMs)
|
||||||
|
|
||||||
ss.Cloud.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
ss.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
||||||
ss.Cloud.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
ss.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetScaleSetVMInstanceID(t *testing.T) {
|
func TestGetScaleSetVMInstanceID(t *testing.T) {
|
||||||
@ -102,8 +105,6 @@ func TestGetScaleSetVMInstanceID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInstanceIDByNodeName(t *testing.T) {
|
func TestGetInstanceIDByNodeName(t *testing.T) {
|
||||||
ss := newTestScaleSet()
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
scaleSet string
|
scaleSet string
|
||||||
@ -136,7 +137,8 @@ func TestGetInstanceIDByNodeName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
setTestVirtualMachineScaleSets(ss, test.scaleSet, test.vmList)
|
ss := newTestScaleSet(test.scaleSet, test.vmList)
|
||||||
|
|
||||||
real, err := ss.GetInstanceIDByNodeName(test.nodeName)
|
real, err := ss.GetInstanceIDByNodeName(test.nodeName)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
assert.Error(t, err, test.description)
|
assert.Error(t, err, test.description)
|
||||||
|
Loading…
Reference in New Issue
Block a user