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
f65d4765
Commit
f65d4765
authored
Sep 30, 2016
by
yarntime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test cases to test the default value of HPA
parent
a61a1f51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
defaults_test.go
pkg/apis/extensions/v1beta1/defaults_test.go
+72
-0
No files found.
pkg/apis/extensions/v1beta1/defaults_test.go
View file @
f65d4765
...
...
@@ -765,6 +765,78 @@ func TestDefaultRequestIsNotSetForReplicaSet(t *testing.T) {
}
}
func
TestSetDefaultHorizontalPodAutoscalerMinReplicas
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
hpa
HorizontalPodAutoscaler
expectReplicas
int32
}{
{
hpa
:
HorizontalPodAutoscaler
{},
expectReplicas
:
1
,
},
{
hpa
:
HorizontalPodAutoscaler
{
Spec
:
HorizontalPodAutoscalerSpec
{
MinReplicas
:
newInt32
(
3
),
},
},
expectReplicas
:
3
,
},
}
for
_
,
test
:=
range
tests
{
hpa
:=
&
test
.
hpa
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
hpa
))
hpa2
,
ok
:=
obj2
.
(
*
HorizontalPodAutoscaler
)
if
!
ok
{
t
.
Errorf
(
"unexpected object: %v"
,
hpa2
)
t
.
FailNow
()
}
if
hpa2
.
Spec
.
MinReplicas
==
nil
{
t
.
Errorf
(
"unexpected nil MinReplicas"
)
}
else
if
test
.
expectReplicas
!=
*
hpa2
.
Spec
.
MinReplicas
{
t
.
Errorf
(
"expected: %d MinReplicas, got: %d"
,
test
.
expectReplicas
,
*
hpa2
.
Spec
.
MinReplicas
)
}
}
}
func
TestSetDefaultHorizontalPodAutoscalerCpuUtilization
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
hpa
HorizontalPodAutoscaler
expectUtilization
int32
}{
{
hpa
:
HorizontalPodAutoscaler
{},
expectUtilization
:
80
,
},
{
hpa
:
HorizontalPodAutoscaler
{
Spec
:
HorizontalPodAutoscalerSpec
{
CPUUtilization
:
&
CPUTargetUtilization
{
TargetPercentage
:
int32
(
50
),
},
},
},
expectUtilization
:
50
,
},
}
for
_
,
test
:=
range
tests
{
hpa
:=
&
test
.
hpa
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
hpa
))
hpa2
,
ok
:=
obj2
.
(
*
HorizontalPodAutoscaler
)
if
!
ok
{
t
.
Errorf
(
"unexpected object: %v"
,
hpa2
)
t
.
FailNow
()
}
if
hpa2
.
Spec
.
CPUUtilization
==
nil
{
t
.
Errorf
(
"unexpected nil CPUUtilization"
)
}
else
if
test
.
expectUtilization
!=
hpa2
.
Spec
.
CPUUtilization
.
TargetPercentage
{
t
.
Errorf
(
"expected: %d CPUUtilization, got: %d"
,
test
.
expectUtilization
,
hpa2
.
Spec
.
CPUUtilization
.
TargetPercentage
)
}
}
}
func
roundTrip
(
t
*
testing
.
T
,
obj
runtime
.
Object
)
runtime
.
Object
{
data
,
err
:=
runtime
.
Encode
(
api
.
Codecs
.
LegacyCodec
(
SchemeGroupVersion
),
obj
)
if
err
!=
nil
{
...
...
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