Add fake client to make testing easier.

This commit is contained in:
Daniel Smith
2014-08-05 16:19:32 -07:00
parent 097147545c
commit 85ff1d3e7f
4 changed files with 158 additions and 1 deletions

View File

@@ -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)