mirror of https://github.com/k3s-io/k3s
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 ```pull/6/head
commit
0b6b8cda6d
|
@ -24,12 +24,15 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newTestScaleSet() *scaleSet {
|
||||
ss := newScaleSet(getTestCloud())
|
||||
func newTestScaleSet(scaleSetName string, vmList []string) *scaleSet {
|
||||
cloud := getTestCloud()
|
||||
setTestVirtualMachineCloud(cloud, scaleSetName, vmList)
|
||||
ss := newScaleSet(cloud)
|
||||
|
||||
return ss.(*scaleSet)
|
||||
}
|
||||
|
||||
func setTestVirtualMachineScaleSets(ss *scaleSet, scaleSetName string, vmList []string) {
|
||||
func setTestVirtualMachineCloud(ss *Cloud, scaleSetName string, vmList []string) {
|
||||
virtualMachineScaleSetsClient := newFakeVirtualMachineScaleSetsClient()
|
||||
scaleSets := make(map[string]map[string]compute.VirtualMachineScaleSet)
|
||||
scaleSets["rg"] = map[string]compute.VirtualMachineScaleSet{
|
||||
|
@ -63,13 +66,13 @@ func setTestVirtualMachineScaleSets(ss *scaleSet, scaleSetName string, vmList []
|
|||
},
|
||||
ID: &ID,
|
||||
InstanceID: &instanceID,
|
||||
Location: &ss.Cloud.Location,
|
||||
Location: &ss.Location,
|
||||
}
|
||||
}
|
||||
virtualMachineScaleSetVMsClient.setFakeStore(ssVMs)
|
||||
|
||||
ss.Cloud.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
||||
ss.Cloud.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
||||
ss.VirtualMachineScaleSetsClient = virtualMachineScaleSetsClient
|
||||
ss.VirtualMachineScaleSetVMsClient = virtualMachineScaleSetVMsClient
|
||||
}
|
||||
|
||||
func TestGetScaleSetVMInstanceID(t *testing.T) {
|
||||
|
@ -102,8 +105,6 @@ func TestGetScaleSetVMInstanceID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetInstanceIDByNodeName(t *testing.T) {
|
||||
ss := newTestScaleSet()
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
scaleSet string
|
||||
|
@ -136,7 +137,8 @@ func TestGetInstanceIDByNodeName(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
setTestVirtualMachineScaleSets(ss, test.scaleSet, test.vmList)
|
||||
ss := newTestScaleSet(test.scaleSet, test.vmList)
|
||||
|
||||
real, err := ss.GetInstanceIDByNodeName(test.nodeName)
|
||||
if test.expectError {
|
||||
assert.Error(t, err, test.description)
|
||||
|
|
Loading…
Reference in New Issue