Fixup unit tests

pull/6/head
derekwaynecarr 2014-10-23 16:55:48 -04:00
parent 341e404290
commit c6eb371c93
6 changed files with 52 additions and 55 deletions

View File

@ -146,17 +146,17 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
}
func TestListEmptyPods(t *testing.T) {
ctx := api.NewContext()
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200, Body: &api.PodList{}},
}
podList, err := c.Setup().ListPods(ctx, labels.Everything())
podList, err := c.Setup().Pods(ns).List(labels.Everything())
c.Validate(t, podList, err)
}
func TestListPods(t *testing.T) {
ctx := api.NewDefaultContext()
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200,
@ -177,7 +177,7 @@ func TestListPods(t *testing.T) {
},
},
}
receivedPodList, err := c.Setup().ListPods(ctx, labels.Everything())
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything())
c.Validate(t, receivedPodList, err)
}
@ -188,7 +188,7 @@ func validateLabels(a, b string) bool {
}
func TestListPodsLabels(t *testing.T) {
ctx := api.NewDefaultContext()
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
Response: Response{
@ -213,12 +213,12 @@ func TestListPodsLabels(t *testing.T) {
c.Setup()
c.QueryValidator["labels"] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.ListPods(ctx, selector)
receivedPodList, err := c.Pods(ns).List(selector)
c.Validate(t, receivedPodList, err)
}
func TestGetPod(t *testing.T) {
ctx := api.NewDefaultContext()
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods/foo"},
Response: Response{
@ -236,7 +236,7 @@ func TestGetPod(t *testing.T) {
},
},
}
receivedPod, err := c.Setup().GetPod(ctx, "foo")
receivedPod, err := c.Setup().Pods(ns).Get("foo")
c.Validate(t, receivedPod, err)
}
@ -245,7 +245,7 @@ func TestDeletePod(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/pods/foo"},
Response: Response{StatusCode: 200},
}
err := c.Setup().DeletePod(api.NewDefaultContext(), "foo")
err := c.Setup().Pods(api.NamespaceDefault).Delete("foo")
c.Validate(t, nil, err)
}
@ -268,7 +268,7 @@ func TestCreatePod(t *testing.T) {
Body: requestPod,
},
}
receivedPod, err := c.Setup().CreatePod(api.NewDefaultContext(), requestPod)
receivedPod, err := c.Setup().Pods(api.NamespaceDefault).Create(requestPod)
c.Validate(t, receivedPod, err)
}
@ -290,7 +290,7 @@ func TestUpdatePod(t *testing.T) {
Request: testRequest{Method: "PUT", Path: "/pods/foo"},
Response: Response{StatusCode: 200, Body: requestPod},
}
receivedPod, err := c.Setup().UpdatePod(api.NewDefaultContext(), requestPod)
receivedPod, err := c.Setup().Pods(api.NamespaceDefault).Update(requestPod)
c.Validate(t, receivedPod, err)
}
@ -316,7 +316,7 @@ func TestListControllers(t *testing.T) {
},
},
}
receivedControllerList, err := c.Setup().ListReplicationControllers(api.NewContext(), labels.Everything())
receivedControllerList, err := c.Setup().ReplicationControllers(api.NamespaceAll).List(labels.Everything())
c.Validate(t, receivedControllerList, err)
}
@ -340,7 +340,7 @@ func TestGetController(t *testing.T) {
},
},
}
receivedController, err := c.Setup().GetReplicationController(api.NewDefaultContext(), "foo")
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Get("foo")
c.Validate(t, receivedController, err)
}
@ -366,7 +366,7 @@ func TestUpdateController(t *testing.T) {
},
},
}
receivedController, err := c.Setup().UpdateReplicationController(api.NewDefaultContext(), requestController)
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Update(requestController)
c.Validate(t, receivedController, err)
}
@ -375,7 +375,7 @@ func TestDeleteController(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/replicationControllers/foo"},
Response: Response{StatusCode: 200},
}
err := c.Setup().DeleteReplicationController(api.NewDefaultContext(), "foo")
err := c.Setup().ReplicationControllers(api.NamespaceDefault).Delete("foo")
c.Validate(t, nil, err)
}
@ -401,7 +401,7 @@ func TestCreateController(t *testing.T) {
},
},
}
receivedController, err := c.Setup().CreateReplicationController(api.NewDefaultContext(), requestController)
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Create(requestController)
c.Validate(t, receivedController, err)
}
@ -436,7 +436,7 @@ func TestListServices(t *testing.T) {
},
},
}
receivedServiceList, err := c.Setup().ListServices(api.NewDefaultContext(), labels.Everything())
receivedServiceList, err := c.Setup().Services(api.NamespaceDefault).List(labels.Everything())
t.Logf("received services: %v %#v", err, receivedServiceList)
c.Validate(t, receivedServiceList, err)
}
@ -466,7 +466,7 @@ func TestListServicesLabels(t *testing.T) {
c.Setup()
c.QueryValidator["labels"] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.ListServices(api.NewDefaultContext(), selector)
receivedServiceList, err := c.Services(api.NamespaceDefault).List(selector)
c.Validate(t, receivedServiceList, err)
}
@ -475,7 +475,7 @@ func TestGetService(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/services/1"},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
}
response, err := c.Setup().GetService(api.NewDefaultContext(), "1")
response, err := c.Setup().Services(api.NamespaceDefault).Get("1")
c.Validate(t, response, err)
}
@ -484,7 +484,7 @@ func TestCreateService(t *testing.T) {
Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
}
response, err := c.Setup().CreateService(api.NewDefaultContext(), &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
response, err := c.Setup().Services(api.NamespaceDefault).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
c.Validate(t, response, err)
}
@ -494,7 +494,7 @@ func TestUpdateService(t *testing.T) {
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
Response: Response{StatusCode: 200, Body: svc},
}
response, err := c.Setup().UpdateService(api.NewDefaultContext(), svc)
response, err := c.Setup().Services(api.NamespaceDefault).Update(svc)
c.Validate(t, response, err)
}
@ -503,7 +503,7 @@ func TestDeleteService(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/services/1"},
Response: Response{StatusCode: 200},
}
err := c.Setup().DeleteService(api.NewDefaultContext(), "1")
err := c.Setup().Services(api.NamespaceDefault).Delete("1")
c.Validate(t, nil, err)
}
@ -521,7 +521,7 @@ func TestListEndpooints(t *testing.T) {
},
},
}
receivedEndpointsList, err := c.Setup().ListEndpoints(api.NewDefaultContext(), labels.Everything())
receivedEndpointsList, err := c.Setup().Endpoints(api.NamespaceDefault).List(labels.Everything())
c.Validate(t, receivedEndpointsList, err)
}
@ -530,7 +530,7 @@ func TestGetEndpoints(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"},
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
}
response, err := c.Setup().GetEndpoints(api.NewDefaultContext(), "endpoint-1")
response, err := c.Setup().Endpoints(api.NamespaceDefault).Get("endpoint-1")
c.Validate(t, response, err)
}
@ -566,7 +566,7 @@ func TestListMinions(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/minions"},
Response: Response{StatusCode: 200, Body: &api.MinionList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
}
response, err := c.Setup().ListMinions()
response, err := c.Setup().Minions().List()
c.Validate(t, response, err)
}
@ -590,7 +590,7 @@ func TestCreateMinion(t *testing.T) {
Body: requestMinion,
},
}
receivedMinion, err := c.Setup().CreateMinion(requestMinion)
receivedMinion, err := c.Setup().Minions().Create(requestMinion)
c.Validate(t, receivedMinion, err)
}
@ -599,6 +599,6 @@ func TestDeleteMinion(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/minions/foo"},
Response: Response{StatusCode: 200},
}
err := c.Setup().DeleteMinion("foo")
err := c.Setup().Minions().Delete("foo")
c.Validate(t, nil, err)
}

View File

@ -32,7 +32,7 @@ type testEventRecorder struct {
}
// CreateEvent records the event for testing.
func (t *testEventRecorder) CreateEvent(e *api.Event) (*api.Event, error) {
func (t *testEventRecorder) Create(e *api.Event) (*api.Event, error) {
if t.OnEvent != nil {
return t.OnEvent(e)
}

View File

@ -30,7 +30,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@ -44,20 +43,20 @@ func makeURL(suffix string) string {
type FakePodControl struct {
controllerSpec []api.ReplicationController
deletePodID []string
deletePodName []string
lock sync.Mutex
}
func (f *FakePodControl) createReplica(ctx api.Context, spec api.ReplicationController) {
func (f *FakePodControl) createReplica(namespace string, spec api.ReplicationController) {
f.lock.Lock()
defer f.lock.Unlock()
f.controllerSpec = append(f.controllerSpec, spec)
}
func (f *FakePodControl) deletePod(ctx api.Context, podID string) error {
func (f *FakePodControl) deletePod(namespace string, podName string) error {
f.lock.Lock()
defer f.lock.Unlock()
f.deletePodID = append(f.deletePodID, podID)
f.deletePodName = append(f.deletePodName, podName)
return nil
}
@ -102,8 +101,8 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
if len(fakePodControl.controllerSpec) != expectedCreates {
t.Errorf("Unexpected number of creates. Expected %d, saw %d\n", expectedCreates, len(fakePodControl.controllerSpec))
}
if len(fakePodControl.deletePodID) != expectedDeletes {
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", expectedDeletes, len(fakePodControl.deletePodID))
if len(fakePodControl.deletePodName) != expectedDeletes {
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", expectedDeletes, len(fakePodControl.deletePodName))
}
}
@ -168,7 +167,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
}
func TestCreateReplica(t *testing.T) {
ctx := api.NewDefaultContext()
ns := api.NamespaceDefault
body := runtime.EncodeOrDie(testapi.Codec(), &api.Pod{})
fakeHandler := util.FakeHandler{
StatusCode: 200,
@ -205,7 +204,7 @@ func TestCreateReplica(t *testing.T) {
},
}
podControl.createReplica(ctx, controllerSpec)
podControl.createReplica(ns, controllerSpec)
expectedPod := api.Pod{
ObjectMeta: api.ObjectMeta{
@ -322,12 +321,9 @@ type FakeWatcher struct {
*client.Fake
}
func (fw FakeWatcher) WatchReplicationControllers(ctx api.Context, l, f labels.Selector, rv string) (watch.Interface, error) {
return fw.w, nil
}
func TestWatchControllers(t *testing.T) {
client := FakeWatcher{watch.NewFake(), &client.Fake{}}
fakeWatch := watch.NewFake()
client := &client.Fake{Watch: fakeWatch}
manager := NewReplicationManager(client)
var testControllerSpec api.ReplicationController
received := make(chan struct{})
@ -344,7 +340,8 @@ func TestWatchControllers(t *testing.T) {
// Test normal case
testControllerSpec.Name = "foo"
client.w.Add(&testControllerSpec)
fakeWatch.Add(&testControllerSpec)
select {
case <-received:

View File

@ -36,7 +36,7 @@ func validateAction(expectedAction, actualAction client.FakeAction, t *testing.T
func TestUpdateWithPods(t *testing.T) {
fakeClient := client.Fake{
Pods: api.PodList{
PodsList: api.PodList{
Items: []api.Pod{
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},
@ -67,7 +67,7 @@ func TestUpdateNoPods(t *testing.T) {
func TestUpdateWithNewImage(t *testing.T) {
fakeClient := client.Fake{
Pods: api.PodList{
PodsList: api.PodList{
Items: []api.Pod{
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},

View File

@ -32,7 +32,7 @@ func TestServices(t *testing.T) {
fakeWatch := watch.NewFake()
fakeClient := &client.Fake{Watch: fakeWatch}
services := make(chan ServiceUpdate)
source := SourceAPI{client: fakeClient, services: services}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
resourceVersion := "1"
go func() {
// called twice
@ -84,7 +84,7 @@ func TestServicesFromZero(t *testing.T) {
},
}
services := make(chan ServiceUpdate)
source := SourceAPI{client: fakeClient, services: services}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
resourceVersion := ""
ch := make(chan struct{})
go func() {
@ -112,7 +112,7 @@ func TestServicesFromZero(t *testing.T) {
func TestServicesError(t *testing.T) {
fakeClient := &client.Fake{Err: errors.New("test")}
services := make(chan ServiceUpdate)
source := SourceAPI{client: fakeClient, services: services}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
resourceVersion := "1"
ch := make(chan struct{})
go func() {
@ -133,7 +133,7 @@ func TestServicesError(t *testing.T) {
func TestServicesFromZeroError(t *testing.T) {
fakeClient := &client.Fake{Err: errors.New("test")}
services := make(chan ServiceUpdate)
source := SourceAPI{client: fakeClient, services: services}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
resourceVersion := ""
ch := make(chan struct{})
go func() {
@ -157,7 +157,7 @@ func TestEndpoints(t *testing.T) {
fakeWatch := watch.NewFake()
fakeClient := &client.Fake{Watch: fakeWatch}
endpoints := make(chan EndpointsUpdate)
source := SourceAPI{client: fakeClient, endpoints: endpoints}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
resourceVersion := "1"
go func() {
// called twice
@ -209,7 +209,7 @@ func TestEndpointsFromZero(t *testing.T) {
},
}
endpoints := make(chan EndpointsUpdate)
source := SourceAPI{client: fakeClient, endpoints: endpoints}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
resourceVersion := ""
ch := make(chan struct{})
go func() {
@ -237,7 +237,7 @@ func TestEndpointsFromZero(t *testing.T) {
func TestEndpointsError(t *testing.T) {
fakeClient := &client.Fake{Err: errors.New("test")}
endpoints := make(chan EndpointsUpdate)
source := SourceAPI{client: fakeClient, endpoints: endpoints}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
resourceVersion := "1"
ch := make(chan struct{})
go func() {
@ -258,7 +258,7 @@ func TestEndpointsError(t *testing.T) {
func TestEndpointsFromZeroError(t *testing.T) {
fakeClient := &client.Fake{Err: errors.New("test")}
endpoints := make(chan EndpointsUpdate)
source := SourceAPI{client: fakeClient, endpoints: endpoints}
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
resourceVersion := ""
ch := make(chan struct{})
go func() {

View File

@ -385,7 +385,7 @@ func TestGetPodCloud(t *testing.T) {
func TestMakePodStatus(t *testing.T) {
fakeClient := client.Fake{
Minions: api.MinionList{
MinionsList: api.MinionList{
Items: []api.Minion{
{
ObjectMeta: api.ObjectMeta{Name: "machine"},
@ -517,7 +517,7 @@ func TestMakePodStatus(t *testing.T) {
},
}
for _, test := range tests {
if status, err := getPodStatus(test.pod, &fakeClient); status != test.status {
if status, err := getPodStatus(test.pod, fakeClient.Minions()); status != test.status {
t.Errorf("In test %s, expected %v, got %v", test.test, test.status, status)
if err != nil {
t.Errorf("In test %s, unexpected error: %v", test.test, err)