Commit 82b0ec51 authored by Clayton Coleman's avatar Clayton Coleman

Replace pkg/kubecfg#FakeKubeClient with the fake in pkg/client

parent 59bb81e2
...@@ -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 (client *FakeClient) ListPods(selector labels.Selector) (api.PodList, error) { func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) {
client.Actions = append(client.Actions, "list-pods") c.Actions = append(c.Actions, FakeAction{Action: "list-pods"})
return api.PodList{}, nil return c.Pods, nil
} }
func (client *FakeClient) GetPod(name string) (api.Pod, error) { func (c *Fake) GetPod(name string) (api.Pod, error) {
client.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 (client *FakeClient) DeletePod(name string) error { func (c *Fake) DeletePod(name string) error {
client.Actions = append(client.Actions, "delete-pod") c.Actions = append(c.Actions, FakeAction{Action: "delete-pod", Value: name})
return nil return nil
} }
func (client *FakeClient) CreatePod(pod api.Pod) (api.Pod, error) { func (c *Fake) CreatePod(pod api.Pod) (api.Pod, error) {
client.Actions = append(client.Actions, "create-pod") c.Actions = append(c.Actions, FakeAction{Action: "create-pod"})
return api.Pod{}, nil return api.Pod{}, nil
} }
func (client *FakeClient) UpdatePod(pod api.Pod) (api.Pod, error) { func (c *Fake) UpdatePod(pod api.Pod) (api.Pod, error) {
client.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 (client *FakeClient) ListReplicationControllers(selector labels.Selector) (api.ReplicationControllerList, error) { func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.ReplicationControllerList, error) {
client.Actions = append(client.Actions, "list-controllers") c.Actions = append(c.Actions, FakeAction{Action: "list-controllers"})
return api.ReplicationControllerList{}, nil return api.ReplicationControllerList{}, nil
} }
func (client *FakeClient) GetReplicationController(name string) (api.ReplicationController, error) { func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) {
client.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 (client *FakeClient) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) { func (c *Fake) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) {
client.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 (client *FakeClient) UpdateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) { func (c *Fake) UpdateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) {
client.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 (client *FakeClient) DeleteReplicationController(controller string) error { func (c *Fake) DeleteReplicationController(controller string) error {
client.Actions = append(client.Actions, "delete-controller") c.Actions = append(c.Actions, FakeAction{Action: "delete-controller", Value: controller})
return nil return nil
} }
func (client *FakeClient) WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (c *Fake) WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
client.Actions = append(client.Actions, "watch-controllers") c.Actions = append(c.Actions, FakeAction{Action: "watch-controllers"})
return watch.NewFake(), nil return watch.NewFake(), nil
} }
func (client *FakeClient) GetService(name string) (api.Service, error) { func (c *Fake) GetService(name string) (api.Service, error) {
client.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 (client *FakeClient) CreateService(controller api.Service) (api.Service, error) { func (c *Fake) CreateService(service api.Service) (api.Service, error) {
client.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 (client *FakeClient) UpdateService(controller api.Service) (api.Service, error) { func (c *Fake) UpdateService(service api.Service) (api.Service, error) {
client.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 (client *FakeClient) DeleteService(controller string) error { func (c *Fake) DeleteService(service string) error {
client.Actions = append(client.Actions, "delete-service") c.Actions = append(c.Actions, FakeAction{Action: "delete-service", Value: service})
return nil return nil
} }
...@@ -20,18 +20,18 @@ import ( ...@@ -20,18 +20,18 @@ import (
"testing" "testing"
) )
// This test file just ensures that FakeClient 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(&FakeClient{}) _ = Interface(&Fake{})
} }
type MyFake struct { type MyFake struct {
*FakeClient *Fake
} }
func TestEmbeddedFakeImplementsInterface(t *testing.T) { func TestEmbeddedFakeImplementsInterface(t *testing.T) {
_ = Interface(MyFake{&FakeClient{}}) _ = Interface(MyFake{&Fake{}})
_ = Interface(&MyFake{&FakeClient{}}) _ = Interface(&MyFake{&Fake{}})
} }
...@@ -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.FakeClient *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.FakeClient{}} 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{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment