mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Merge pull request #58326 from hzxuzhonghu/fix-azure
Automatic merge from submit-queue (batch tested with PRs 58260, 58326). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. [azure] fix TestGetInstanceIDByNodeName data race **What this PR does / why we need it**: fix ut case data race **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #58325 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
0b6b8cda6d
@ -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