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
5b5101b5
Commit
5b5101b5
authored
Aug 23, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for GetNodeResourceGroup and GetResourceGroups
parent
5fdc7154
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
1 deletion
+98
-1
azure_test.go
pkg/cloudprovider/providers/azure/azure_test.go
+98
-1
No files found.
pkg/cloudprovider/providers/azure/azure_test.go
View file @
5b5101b5
...
...
@@ -1067,7 +1067,7 @@ func getClusterResources(az *Cloud, vmCount int, availabilitySetCount int) (clus
az
.
InterfacesClient
.
CreateOrUpdate
(
ctx
,
az
.
Config
.
ResourceGroup
,
nicName
,
newNIC
)
// create vm
asID
:=
az
.
getAvailabilitySetID
(
asName
)
asID
:=
az
.
getAvailabilitySetID
(
a
z
.
Config
.
ResourceGroup
,
a
sName
)
newVM
:=
compute
.
VirtualMachine
{
Name
:
&
vmName
,
Location
:
&
az
.
Config
.
Location
,
...
...
@@ -2773,3 +2773,100 @@ func TestGetResourceGroupFromDiskURI(t *testing.T) {
}
}
}
func
TestGetResourceGroups
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
nodeResourceGroups
map
[
string
]
string
expected
sets
.
String
informerSynced
bool
expectError
bool
}{
{
name
:
"cloud provider configured RG should be returned by default"
,
nodeResourceGroups
:
map
[
string
]
string
{},
informerSynced
:
true
,
expected
:
sets
.
NewString
(
"rg"
),
},
{
name
:
"cloud provider configured RG and node RGs should be returned"
,
nodeResourceGroups
:
map
[
string
]
string
{
"node1"
:
"rg1"
,
"node2"
:
"rg2"
},
informerSynced
:
true
,
expected
:
sets
.
NewString
(
"rg"
,
"rg1"
,
"rg2"
),
},
{
name
:
"error should be returned if informer hasn't synced yet"
,
nodeResourceGroups
:
map
[
string
]
string
{
"node1"
:
"rg1"
,
"node2"
:
"rg2"
},
informerSynced
:
false
,
expectError
:
true
,
},
}
az
:=
getTestCloud
()
for
_
,
test
:=
range
tests
{
az
.
nodeResourceGroups
=
test
.
nodeResourceGroups
if
test
.
informerSynced
{
az
.
nodeInformerSynced
=
func
()
bool
{
return
true
}
}
else
{
az
.
nodeInformerSynced
=
func
()
bool
{
return
false
}
}
actual
,
err
:=
az
.
GetResourceGroups
()
if
test
.
expectError
{
assert
.
NotNil
(
t
,
err
,
test
.
name
)
continue
}
assert
.
Nil
(
t
,
err
,
test
.
name
)
assert
.
Equal
(
t
,
test
.
expected
,
actual
,
test
.
name
)
}
}
func
TestGetNodeResourceGroup
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
nodeResourceGroups
map
[
string
]
string
node
string
expected
string
informerSynced
bool
expectError
bool
}{
{
name
:
"cloud provider configured RG should be returned by default"
,
nodeResourceGroups
:
map
[
string
]
string
{},
informerSynced
:
true
,
node
:
"node1"
,
expected
:
"rg"
,
},
{
name
:
"node RGs should be returned"
,
nodeResourceGroups
:
map
[
string
]
string
{
"node1"
:
"rg1"
,
"node2"
:
"rg2"
},
informerSynced
:
true
,
node
:
"node1"
,
expected
:
"rg1"
,
},
{
name
:
"error should be returned if informer hasn't synced yet"
,
nodeResourceGroups
:
map
[
string
]
string
{
"node1"
:
"rg1"
,
"node2"
:
"rg2"
},
informerSynced
:
false
,
expectError
:
true
,
},
}
az
:=
getTestCloud
()
for
_
,
test
:=
range
tests
{
az
.
nodeResourceGroups
=
test
.
nodeResourceGroups
if
test
.
informerSynced
{
az
.
nodeInformerSynced
=
func
()
bool
{
return
true
}
}
else
{
az
.
nodeInformerSynced
=
func
()
bool
{
return
false
}
}
actual
,
err
:=
az
.
GetNodeResourceGroup
(
test
.
node
)
if
test
.
expectError
{
assert
.
NotNil
(
t
,
err
,
test
.
name
)
continue
}
assert
.
Nil
(
t
,
err
,
test
.
name
)
assert
.
Equal
(
t
,
test
.
expected
,
actual
,
test
.
name
)
}
}
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