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
82b0ec51
Commit
82b0ec51
authored
Aug 15, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace pkg/kubecfg#FakeKubeClient with the fake in pkg/client
parent
59bb81e2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
43 deletions
+50
-43
fake.go
pkg/client/fake.go
+43
-36
fake_test.go
pkg/client/fake_test.go
+5
-5
replication_controller_test.go
pkg/controller/replication_controller_test.go
+2
-2
kubecfg_test.go
pkg/kubecfg/kubecfg_test.go
+0
-0
No files found.
pkg/client/fake.go
View file @
82b0ec51
...
@@ -22,84 +22,91 @@ import (
...
@@ -22,84 +22,91 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
// FakeClient implements Interface. Meant to be embedded into a struct to get a default
type
FakeAction
struct
{
Action
string
Value
interface
{}
}
// Fake implements Interface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the method you want to test easier.
// implementation. This makes faking out just the method you want to test easier.
type
FakeClient
struct
{
type
Fake
struct
{
// FakeClient by default keeps a simple list of the methods that have been called.
// Fake by default keeps a simple list of the methods that have been called.
Actions
[]
string
Actions
[]
FakeAction
Pods
api
.
PodList
Ctrl
api
.
ReplicationController
}
}
func
(
c
lient
*
FakeClient
)
ListPods
(
selector
labels
.
Selector
)
(
api
.
PodList
,
error
)
{
func
(
c
*
Fake
)
ListPods
(
selector
labels
.
Selector
)
(
api
.
PodList
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"list-pods"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"list-pods"
}
)
return
api
.
PodList
{}
,
nil
return
c
.
Pods
,
nil
}
}
func
(
c
lient
*
FakeClient
)
GetPod
(
name
string
)
(
api
.
Pod
,
error
)
{
func
(
c
*
Fake
)
GetPod
(
name
string
)
(
api
.
Pod
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"get-pod"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-pod"
,
Value
:
name
}
)
return
api
.
Pod
{},
nil
return
api
.
Pod
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
DeletePod
(
name
string
)
error
{
func
(
c
*
Fake
)
DeletePod
(
name
string
)
error
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"delete-pod"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"delete-pod"
,
Value
:
name
}
)
return
nil
return
nil
}
}
func
(
c
lient
*
FakeClient
)
CreatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
func
(
c
*
Fake
)
CreatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"create-pod"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"create-pod"
}
)
return
api
.
Pod
{},
nil
return
api
.
Pod
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
UpdatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
func
(
c
*
Fake
)
UpdatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"update-pod"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"update-pod"
,
Value
:
pod
.
ID
}
)
return
api
.
Pod
{},
nil
return
api
.
Pod
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
ListReplicationControllers
(
selector
labels
.
Selector
)
(
api
.
ReplicationControllerList
,
error
)
{
func
(
c
*
Fake
)
ListReplicationControllers
(
selector
labels
.
Selector
)
(
api
.
ReplicationControllerList
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"list-controllers"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"list-controllers"
}
)
return
api
.
ReplicationControllerList
{},
nil
return
api
.
ReplicationControllerList
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
GetReplicationController
(
name
string
)
(
api
.
ReplicationController
,
error
)
{
func
(
c
*
Fake
)
GetReplicationController
(
name
string
)
(
api
.
ReplicationController
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"get-controller"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-controller"
,
Value
:
name
}
)
return
api
.
ReplicationController
{}
,
nil
return
c
.
Ctrl
,
nil
}
}
func
(
c
lient
*
FakeClient
)
CreateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
func
(
c
*
Fake
)
CreateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"create-controller"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"create-controller"
,
Value
:
controller
}
)
return
api
.
ReplicationController
{},
nil
return
api
.
ReplicationController
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
UpdateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
func
(
c
*
Fake
)
UpdateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"update-controller"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"update-controller"
,
Value
:
controller
}
)
return
api
.
ReplicationController
{},
nil
return
api
.
ReplicationController
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
DeleteReplicationController
(
controller
string
)
error
{
func
(
c
*
Fake
)
DeleteReplicationController
(
controller
string
)
error
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"delete-controller"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"delete-controller"
,
Value
:
controller
}
)
return
nil
return
nil
}
}
func
(
c
lient
*
FakeClient
)
WatchReplicationControllers
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
func
(
c
*
Fake
)
WatchReplicationControllers
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"watch-controllers"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"watch-controllers"
}
)
return
watch
.
NewFake
(),
nil
return
watch
.
NewFake
(),
nil
}
}
func
(
c
lient
*
FakeClient
)
GetService
(
name
string
)
(
api
.
Service
,
error
)
{
func
(
c
*
Fake
)
GetService
(
name
string
)
(
api
.
Service
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"get-controller"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-service"
,
Value
:
name
}
)
return
api
.
Service
{},
nil
return
api
.
Service
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
CreateService
(
controller
api
.
Service
)
(
api
.
Service
,
error
)
{
func
(
c
*
Fake
)
CreateService
(
service
api
.
Service
)
(
api
.
Service
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"create-service"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"create-service"
,
Value
:
service
}
)
return
api
.
Service
{},
nil
return
api
.
Service
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
UpdateService
(
controller
api
.
Service
)
(
api
.
Service
,
error
)
{
func
(
c
*
Fake
)
UpdateService
(
service
api
.
Service
)
(
api
.
Service
,
error
)
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"update-service"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"update-service"
,
Value
:
service
}
)
return
api
.
Service
{},
nil
return
api
.
Service
{},
nil
}
}
func
(
c
lient
*
FakeClient
)
DeleteService
(
controller
string
)
error
{
func
(
c
*
Fake
)
DeleteService
(
service
string
)
error
{
c
lient
.
Actions
=
append
(
client
.
Actions
,
"delete-service"
)
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"delete-service"
,
Value
:
service
}
)
return
nil
return
nil
}
}
pkg/client/fake_test.go
View file @
82b0ec51
...
@@ -20,18 +20,18 @@ import (
...
@@ -20,18 +20,18 @@ import (
"testing"
"testing"
)
)
// This test file just ensures that Fake
Client
and structs it is embedded in
// This test file just ensures that Fake and structs it is embedded in
// implement Interface.
// implement Interface.
func
TestFakeImplementsInterface
(
t
*
testing
.
T
)
{
func
TestFakeImplementsInterface
(
t
*
testing
.
T
)
{
_
=
Interface
(
&
Fake
Client
{})
_
=
Interface
(
&
Fake
{})
}
}
type
MyFake
struct
{
type
MyFake
struct
{
*
Fake
Client
*
Fake
}
}
func
TestEmbeddedFakeImplementsInterface
(
t
*
testing
.
T
)
{
func
TestEmbeddedFakeImplementsInterface
(
t
*
testing
.
T
)
{
_
=
Interface
(
MyFake
{
&
Fake
Client
{}})
_
=
Interface
(
MyFake
{
&
Fake
{}})
_
=
Interface
(
&
MyFake
{
&
Fake
Client
{}})
_
=
Interface
(
&
MyFake
{
&
Fake
{}})
}
}
pkg/controller/replication_controller_test.go
View file @
82b0ec51
...
@@ -319,7 +319,7 @@ func TestSyncronize(t *testing.T) {
...
@@ -319,7 +319,7 @@ func TestSyncronize(t *testing.T) {
type
FakeWatcher
struct
{
type
FakeWatcher
struct
{
w
*
watch
.
FakeWatcher
w
*
watch
.
FakeWatcher
*
client
.
Fake
Client
*
client
.
Fake
}
}
func
(
fw
FakeWatcher
)
WatchReplicationControllers
(
l
,
f
labels
.
Selector
,
rv
uint64
)
(
watch
.
Interface
,
error
)
{
func
(
fw
FakeWatcher
)
WatchReplicationControllers
(
l
,
f
labels
.
Selector
,
rv
uint64
)
(
watch
.
Interface
,
error
)
{
...
@@ -327,7 +327,7 @@ func (fw FakeWatcher) WatchReplicationControllers(l, f labels.Selector, rv uint6
...
@@ -327,7 +327,7 @@ func (fw FakeWatcher) WatchReplicationControllers(l, f labels.Selector, rv uint6
}
}
func
TestWatchControllers
(
t
*
testing
.
T
)
{
func
TestWatchControllers
(
t
*
testing
.
T
)
{
client
:=
FakeWatcher
{
watch
.
NewFake
(),
&
client
.
Fake
Client
{}}
client
:=
FakeWatcher
{
watch
.
NewFake
(),
&
client
.
Fake
{}}
manager
:=
MakeReplicationManager
(
client
)
manager
:=
MakeReplicationManager
(
client
)
var
testControllerSpec
api
.
ReplicationController
var
testControllerSpec
api
.
ReplicationController
received
:=
make
(
chan
struct
{})
received
:=
make
(
chan
struct
{})
...
...
pkg/kubecfg/kubecfg_test.go
View file @
82b0ec51
This diff is collapsed.
Click to expand it.
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