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
85ff1d3e
Commit
85ff1d3e
authored
Aug 05, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fake client to make testing easier.
parent
09714754
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
1 deletion
+158
-1
kubecfg.go
cmd/kubecfg/kubecfg.go
+1
-1
client.go
pkg/client/client.go
+15
-0
fake.go
pkg/client/fake.go
+105
-0
fake_test.go
pkg/client/fake_test.go
+37
-0
No files found.
cmd/kubecfg/kubecfg.go
View file @
85ff1d3e
...
...
@@ -247,7 +247,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
r
:=
s
.
Verb
(
verb
)
.
Path
(
path
)
.
ParseSelector
(
*
selector
)
ParseSelector
Param
(
"labels"
,
*
selector
)
if
setBody
{
if
version
!=
0
{
data
:=
readConfig
(
storage
)
...
...
pkg/client/client.go
View file @
85ff1d3e
...
...
@@ -28,11 +28,14 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
)
// Interface holds the methods for clients of Kubenetes,
// an interface to allow mock testing.
// TODO: split this up by resource?
// TODO: these should return/take pointers.
type
Interface
interface
{
ListPods
(
selector
labels
.
Selector
)
(
api
.
PodList
,
error
)
GetPod
(
name
string
)
(
api
.
Pod
,
error
)
...
...
@@ -45,6 +48,7 @@ type Interface interface {
CreateReplicationController
(
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
UpdateReplicationController
(
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
DeleteReplicationController
(
string
)
error
WatchReplicationControllers
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
GetService
(
name
string
)
(
api
.
Service
,
error
)
CreateService
(
api
.
Service
)
(
api
.
Service
,
error
)
...
...
@@ -233,6 +237,17 @@ func (c *Client) DeleteReplicationController(name string) error {
return
c
.
Delete
()
.
Path
(
"replicationControllers"
)
.
Path
(
name
)
.
Do
()
.
Error
()
}
// WatchReplicationControllers returns a watch.Interface that watches the requested controllers.
func
(
c
*
Client
)
WatchReplicationControllers
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
return
c
.
Get
()
.
Path
(
"watch"
)
.
Path
(
"replicationControllers"
)
.
UintParam
(
"resourceVersion"
,
resourceVersion
)
.
SelectorParam
(
"labels"
,
label
)
.
SelectorParam
(
"fields"
,
field
)
.
Watch
()
}
// GetService returns information about a particular service.
func
(
c
*
Client
)
GetService
(
name
string
)
(
result
api
.
Service
,
err
error
)
{
err
=
c
.
Get
()
.
Path
(
"services"
)
.
Path
(
name
)
.
Do
()
.
Into
(
&
result
)
...
...
pkg/client/fake.go
0 → 100644
View file @
85ff1d3e
/*
Copyright 2014 Google Inc. All rights reserved.
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
client
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
// FakeClient 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.
type
FakeClient
struct
{
// FakeClient by default keeps a simple list of the methods that have been called.
Actions
[]
string
}
func
(
client
*
FakeClient
)
ListPods
(
selector
labels
.
Selector
)
(
api
.
PodList
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"list-pods"
)
return
api
.
PodList
{},
nil
}
func
(
client
*
FakeClient
)
GetPod
(
name
string
)
(
api
.
Pod
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"get-pod"
)
return
api
.
Pod
{},
nil
}
func
(
client
*
FakeClient
)
DeletePod
(
name
string
)
error
{
client
.
Actions
=
append
(
client
.
Actions
,
"delete-pod"
)
return
nil
}
func
(
client
*
FakeClient
)
CreatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"create-pod"
)
return
api
.
Pod
{},
nil
}
func
(
client
*
FakeClient
)
UpdatePod
(
pod
api
.
Pod
)
(
api
.
Pod
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"update-pod"
)
return
api
.
Pod
{},
nil
}
func
(
client
*
FakeClient
)
ListReplicationControllers
(
selector
labels
.
Selector
)
(
api
.
ReplicationControllerList
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"list-controllers"
)
return
api
.
ReplicationControllerList
{},
nil
}
func
(
client
*
FakeClient
)
GetReplicationController
(
name
string
)
(
api
.
ReplicationController
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"get-controller"
)
return
api
.
ReplicationController
{},
nil
}
func
(
client
*
FakeClient
)
CreateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"create-controller"
)
return
api
.
ReplicationController
{},
nil
}
func
(
client
*
FakeClient
)
UpdateReplicationController
(
controller
api
.
ReplicationController
)
(
api
.
ReplicationController
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"update-controller"
)
return
api
.
ReplicationController
{},
nil
}
func
(
client
*
FakeClient
)
DeleteReplicationController
(
controller
string
)
error
{
client
.
Actions
=
append
(
client
.
Actions
,
"delete-controller"
)
return
nil
}
func
(
client
*
FakeClient
)
WatchReplicationControllers
(
label
,
field
labels
.
Selector
,
resourceVersion
uint64
)
(
watch
.
Interface
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"watch-controllers"
)
return
watch
.
NewFake
(),
nil
}
func
(
client
*
FakeClient
)
GetService
(
name
string
)
(
api
.
Service
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"get-controller"
)
return
api
.
Service
{},
nil
}
func
(
client
*
FakeClient
)
CreateService
(
controller
api
.
Service
)
(
api
.
Service
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"create-service"
)
return
api
.
Service
{},
nil
}
func
(
client
*
FakeClient
)
UpdateService
(
controller
api
.
Service
)
(
api
.
Service
,
error
)
{
client
.
Actions
=
append
(
client
.
Actions
,
"update-service"
)
return
api
.
Service
{},
nil
}
func
(
client
*
FakeClient
)
DeleteService
(
controller
string
)
error
{
client
.
Actions
=
append
(
client
.
Actions
,
"delete-service"
)
return
nil
}
pkg/client/fake_test.go
0 → 100644
View file @
85ff1d3e
/*
Copyright 2014 Google Inc. All rights reserved.
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
client
import
(
"testing"
)
// This test file just ensures that FakeClient and structs it is embedded in
// implement Interface.
func
TestFakeImplementsInterface
(
t
*
testing
.
T
)
{
_
=
Interface
(
&
FakeClient
{})
}
type
MyFake
struct
{
*
FakeClient
}
func
TestEmbeddedFakeImplementsInterface
(
t
*
testing
.
T
)
{
_
=
Interface
(
MyFake
{
&
FakeClient
{}})
_
=
Interface
(
&
MyFake
{
&
FakeClient
{}})
}
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