Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d35c3a22
Commit
d35c3a22
authored
Apr 16, 2019
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests
parent
620a5b32
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
azure_vmss_test.go
pkg/cloudprovider/providers/azure/azure_vmss_test.go
+67
-0
No files found.
pkg/cloudprovider/providers/azure/azure_vmss_test.go
View file @
d35c3a22
...
@@ -80,6 +80,21 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
...
@@ -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
...
@@ -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) {
...
@@ -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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment