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
4ef90335
Commit
4ef90335
authored
Jul 06, 2018
by
Joachim Bartosik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract helpers from prepareTestClient
Each of the subhelpers generates one client.
parent
a5ebe7dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
replica_calculator_test.go
pkg/controller/podautoscaler/replica_calculator_test.go
+17
-2
No files found.
pkg/controller/podautoscaler/replica_calculator_test.go
View file @
4ef90335
...
@@ -87,8 +87,7 @@ const (
...
@@ -87,8 +87,7 @@ const (
numContainersPerPod
=
2
numContainersPerPod
=
2
)
)
func
(
tc
*
replicaCalcTestCase
)
prepareTestClient
(
t
*
testing
.
T
)
(
*
fake
.
Clientset
,
*
metricsfake
.
Clientset
,
*
cmfake
.
FakeCustomMetricsClient
,
*
emfake
.
FakeExternalMetricsClient
)
{
func
(
tc
*
replicaCalcTestCase
)
prepareTestClientSet
()
*
fake
.
Clientset
{
fakeClient
:=
&
fake
.
Clientset
{}
fakeClient
:=
&
fake
.
Clientset
{}
fakeClient
.
AddReactor
(
"list"
,
"pods"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fakeClient
.
AddReactor
(
"list"
,
"pods"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
obj
:=
&
v1
.
PodList
{}
obj
:=
&
v1
.
PodList
{}
...
@@ -145,7 +144,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
...
@@ -145,7 +144,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
}
}
return
true
,
obj
,
nil
return
true
,
obj
,
nil
})
})
return
fakeClient
}
func
(
tc
*
replicaCalcTestCase
)
prepareTestMetricsClient
()
*
metricsfake
.
Clientset
{
fakeMetricsClient
:=
&
metricsfake
.
Clientset
{}
fakeMetricsClient
:=
&
metricsfake
.
Clientset
{}
// NB: we have to sound like Gollum due to gengo's inability to handle already-plural resource names
// NB: we have to sound like Gollum due to gengo's inability to handle already-plural resource names
fakeMetricsClient
.
AddReactor
(
"list"
,
"pods"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fakeMetricsClient
.
AddReactor
(
"list"
,
"pods"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
...
@@ -185,7 +187,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
...
@@ -185,7 +187,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
return
true
,
nil
,
fmt
.
Errorf
(
"no pod resource metrics specified in test client"
)
return
true
,
nil
,
fmt
.
Errorf
(
"no pod resource metrics specified in test client"
)
})
})
return
fakeMetricsClient
}
func
(
tc
*
replicaCalcTestCase
)
prepareTestCMClient
(
t
*
testing
.
T
)
*
cmfake
.
FakeCustomMetricsClient
{
fakeCMClient
:=
&
cmfake
.
FakeCustomMetricsClient
{}
fakeCMClient
:=
&
cmfake
.
FakeCustomMetricsClient
{}
fakeCMClient
.
AddReactor
(
"get"
,
"*"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fakeCMClient
.
AddReactor
(
"get"
,
"*"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
getForAction
,
wasGetFor
:=
action
.
(
cmfake
.
GetForAction
)
getForAction
,
wasGetFor
:=
action
.
(
cmfake
.
GetForAction
)
...
@@ -250,7 +255,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
...
@@ -250,7 +255,10 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
return
true
,
metrics
,
nil
return
true
,
metrics
,
nil
})
})
return
fakeCMClient
}
func
(
tc
*
replicaCalcTestCase
)
prepareTestEMClient
(
t
*
testing
.
T
)
*
emfake
.
FakeExternalMetricsClient
{
fakeEMClient
:=
&
emfake
.
FakeExternalMetricsClient
{}
fakeEMClient
:=
&
emfake
.
FakeExternalMetricsClient
{}
fakeEMClient
.
AddReactor
(
"list"
,
"*"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fakeEMClient
.
AddReactor
(
"list"
,
"*"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
listAction
,
wasList
:=
action
.
(
core
.
ListAction
)
listAction
,
wasList
:=
action
.
(
core
.
ListAction
)
...
@@ -283,7 +291,14 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
...
@@ -283,7 +291,14 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
return
true
,
&
metrics
,
nil
return
true
,
&
metrics
,
nil
})
})
return
fakeEMClient
}
func
(
tc
*
replicaCalcTestCase
)
prepareTestClient
(
t
*
testing
.
T
)
(
*
fake
.
Clientset
,
*
metricsfake
.
Clientset
,
*
cmfake
.
FakeCustomMetricsClient
,
*
emfake
.
FakeExternalMetricsClient
)
{
fakeClient
:=
tc
.
prepareTestClientSet
()
fakeMetricsClient
:=
tc
.
prepareTestMetricsClient
()
fakeCMClient
:=
tc
.
prepareTestCMClient
(
t
)
fakeEMClient
:=
tc
.
prepareTestEMClient
(
t
)
return
fakeClient
,
fakeMetricsClient
,
fakeCMClient
,
fakeEMClient
return
fakeClient
,
fakeMetricsClient
,
fakeCMClient
,
fakeEMClient
}
}
...
...
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