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
2e646b0e
Commit
2e646b0e
authored
Jan 15, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more unit tests
parent
66b02311
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
58 deletions
+156
-58
BUILD
pkg/cloudprovider/providers/azure/BUILD
+5
-5
azure_standard_test.go
pkg/cloudprovider/providers/azure/azure_standard_test.go
+0
-53
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+2
-0
azure_vmss_test.go
pkg/cloudprovider/providers/azure/azure_vmss_test.go
+149
-0
No files found.
pkg/cloudprovider/providers/azure/BUILD
View file @
2e646b0e
...
...
@@ -12,6 +12,7 @@ go_library(
"azure.go",
"azure_backoff.go",
"azure_blobDiskController.go",
"azure_cache.go",
"azure_client.go",
"azure_controllerCommon.go",
"azure_fakes.go",
...
...
@@ -21,12 +22,11 @@ go_library(
"azure_managedDiskController.go",
"azure_metrics.go",
"azure_routes.go",
"azure_standard.go",
"azure_storage.go",
"azure_storageaccount.go",
"azure_util.go",
"azure_util_cache.go",
"azure_util_vmss.go",
"azure_vmsets.go",
"azure_vmss.go",
"azure_wrap.go",
"azure_zones.go",
],
...
...
@@ -64,11 +64,11 @@ go_library(
go_test(
name = "go_default_test",
srcs = [
"azure_cache_test.go",
"azure_loadbalancer_test.go",
"azure_metrics_test.go",
"azure_test.go",
"azure_util_cache_test.go",
"azure_util_test.go",
"azure_vmss_test.go",
"azure_wrap_test.go",
],
embed = [":go_default_library"],
...
...
pkg/cloudprovider/providers/azure/azure_standard_test.go
deleted
100644 → 0
View file @
66b02311
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
azure
import
(
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func
TestGetScaleSetVMInstanceID
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
msg
string
machineName
string
expectError
bool
expectedInstanceID
string
}{{
msg
:
"invalid vmss instance name"
,
machineName
:
"vmvm"
,
expectError
:
true
,
},
{
msg
:
"valid vmss instance name"
,
machineName
:
"vm00000Z"
,
expectError
:
false
,
expectedInstanceID
:
"35"
,
},
}
for
i
,
test
:=
range
tests
{
instanceID
,
err
:=
getScaleSetVMInstanceID
(
test
.
machineName
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"TestCase[%d]: %s"
,
i
,
test
.
msg
))
}
else
{
assert
.
Equal
(
t
,
test
.
expectedInstanceID
,
instanceID
,
fmt
.
Sprintf
(
"TestCase[%d]: %s"
,
i
,
test
.
msg
))
}
}
}
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
2e646b0e
...
...
@@ -190,10 +190,12 @@ func (ss *scaleSet) getCachedVirtualMachine(nodeName string) (scaleSetVMInfo, er
}
// Update cache and try again.
glog
.
V
(
10
)
.
Infof
(
"vmss cache before updateCache: %v"
,
ss
.
cache
)
if
err
:=
ss
.
updateCache
();
err
!=
nil
{
glog
.
Errorf
(
"updateCache failed with error: %v"
,
err
)
return
scaleSetVMInfo
{},
err
}
glog
.
V
(
10
)
.
Infof
(
"vmss cache after updateCache: %v"
,
ss
.
cache
)
vm
,
found
=
getVMFromCache
(
nodeName
)
if
found
{
return
vm
,
nil
...
...
pkg/cloudprovider/providers/azure/azure_vmss_test.go
0 → 100644
View file @
2e646b0e
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
azure
import
(
"fmt"
"testing"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/stretchr/testify/assert"
)
func
newTestScaleSet
()
*
scaleSet
{
ss
:=
newScaleSet
(
getTestCloud
())
return
ss
.
(
*
scaleSet
)
}
func
setTestVirtualMachineScaleSets
(
ss
*
scaleSet
,
scaleSetName
string
,
vmList
[]
string
)
{
virtualMachineScaleSetsClient
:=
newFakeVirtualMachineScaleSetsClient
()
scaleSets
:=
make
(
map
[
string
]
map
[
string
]
compute
.
VirtualMachineScaleSet
)
scaleSets
[
"rg"
]
=
map
[
string
]
compute
.
VirtualMachineScaleSet
{
scaleSetName
:
{
Name
:
&
scaleSetName
,
},
}
virtualMachineScaleSetsClient
.
setFakeStore
(
scaleSets
)
virtualMachineScaleSetVMsClient
:=
newFakeVirtualMachineScaleSetVMsClient
()
ssVMs
:=
make
(
map
[
string
]
map
[
string
]
compute
.
VirtualMachineScaleSetVM
)
ssVMs
[
"rg"
]
=
make
(
map
[
string
]
compute
.
VirtualMachineScaleSetVM
)
for
i
:=
range
vmList
{
ID
:=
fmt
.
Sprintf
(
"azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d"
,
scaleSetName
,
i
)
nodeName
:=
vmList
[
i
]
instanceID
:=
fmt
.
Sprintf
(
"%d"
,
i
)
vmKey
:=
fmt
.
Sprintf
(
"%s-%s"
,
scaleSetName
,
nodeName
)
networkInterfaces
:=
[]
compute
.
NetworkInterfaceReference
{
{
ID
:
&
nodeName
,
},
}
ssVMs
[
"rg"
][
vmKey
]
=
compute
.
VirtualMachineScaleSetVM
{
VirtualMachineScaleSetVMProperties
:
&
compute
.
VirtualMachineScaleSetVMProperties
{
OsProfile
:
&
compute
.
OSProfile
{
ComputerName
:
&
nodeName
,
},
NetworkProfile
:
&
compute
.
NetworkProfile
{
NetworkInterfaces
:
&
networkInterfaces
,
},
},
ID
:
&
ID
,
InstanceID
:
&
instanceID
,
Location
:
&
ss
.
Cloud
.
Location
,
}
}
virtualMachineScaleSetVMsClient
.
setFakeStore
(
ssVMs
)
ss
.
Cloud
.
VirtualMachineScaleSetsClient
=
virtualMachineScaleSetsClient
ss
.
Cloud
.
VirtualMachineScaleSetVMsClient
=
virtualMachineScaleSetVMsClient
}
func
TestGetScaleSetVMInstanceID
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
msg
string
machineName
string
expectError
bool
expectedInstanceID
string
}{{
msg
:
"invalid vmss instance name"
,
machineName
:
"vmvm"
,
expectError
:
true
,
},
{
msg
:
"valid vmss instance name"
,
machineName
:
"vm00000Z"
,
expectError
:
false
,
expectedInstanceID
:
"35"
,
},
}
for
i
,
test
:=
range
tests
{
instanceID
,
err
:=
getScaleSetVMInstanceID
(
test
.
machineName
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"TestCase[%d]: %s"
,
i
,
test
.
msg
))
}
else
{
assert
.
Equal
(
t
,
test
.
expectedInstanceID
,
instanceID
,
fmt
.
Sprintf
(
"TestCase[%d]: %s"
,
i
,
test
.
msg
))
}
}
}
func
TestGetInstanceIDByNodeName
(
t
*
testing
.
T
)
{
ss
:=
newTestScaleSet
()
testCases
:=
[]
struct
{
description
string
scaleSet
string
vmList
[]
string
nodeName
string
expected
string
expectError
bool
}{
{
description
:
"scaleSet should get instance by node name"
,
scaleSet
:
"ss"
,
vmList
:
[]
string
{
"vm1"
,
"vm2"
},
nodeName
:
"vm1"
,
expected
:
"azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/0"
,
},
{
description
:
"scaleSet should get instance by node name with upper cases hostname"
,
scaleSet
:
"ss"
,
vmList
:
[]
string
{
"VM1"
,
"vm2"
},
nodeName
:
"vm1"
,
expected
:
"azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/ss/virtualMachines/0"
,
},
{
description
:
"scaleSet should not get instance for non-exist nodes"
,
scaleSet
:
"ss"
,
vmList
:
[]
string
{
"VM1"
,
"vm2"
},
nodeName
:
"vm3"
,
expectError
:
true
,
},
}
for
_
,
test
:=
range
testCases
{
setTestVirtualMachineScaleSets
(
ss
,
test
.
scaleSet
,
test
.
vmList
)
real
,
err
:=
ss
.
GetInstanceIDByNodeName
(
test
.
nodeName
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
,
test
.
description
)
continue
}
assert
.
NoError
(
t
,
err
,
test
.
description
)
assert
.
Equal
(
t
,
test
.
expected
,
real
,
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