Fixup tests

This commit is contained in:
derekwaynecarr 2014-10-02 12:52:01 -04:00
parent fc67d822c6
commit d5ec260db8
3 changed files with 38 additions and 33 deletions

View File

@ -145,15 +145,17 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
} }
func TestListEmptyPods(t *testing.T) { func TestListEmptyPods(t *testing.T) {
ctx := api.NewContext()
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"}, Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200, Body: &api.PodList{}}, Response: Response{StatusCode: 200, Body: &api.PodList{}},
} }
podList, err := c.Setup().ListPods(labels.Everything()) podList, err := c.Setup().ListPods(ctx, labels.Everything())
c.Validate(t, podList, err) c.Validate(t, podList, err)
} }
func TestListPods(t *testing.T) { func TestListPods(t *testing.T) {
ctx := api.NewDefaultContext()
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"}, Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
@ -172,7 +174,7 @@ func TestListPods(t *testing.T) {
}, },
}, },
} }
receivedPodList, err := c.Setup().ListPods(labels.Everything()) receivedPodList, err := c.Setup().ListPods(ctx, labels.Everything())
c.Validate(t, receivedPodList, err) c.Validate(t, receivedPodList, err)
} }
@ -183,6 +185,7 @@ func validateLabels(a, b string) bool {
} }
func TestListPodsLabels(t *testing.T) { func TestListPodsLabels(t *testing.T) {
ctx := api.NewDefaultContext()
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}}, Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
Response: Response{ Response: Response{
@ -205,11 +208,12 @@ func TestListPodsLabels(t *testing.T) {
c.Setup() c.Setup()
c.QueryValidator["labels"] = validateLabels c.QueryValidator["labels"] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector() selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.ListPods(selector) receivedPodList, err := c.ListPods(ctx, selector)
c.Validate(t, receivedPodList, err) c.Validate(t, receivedPodList, err)
} }
func TestGetPod(t *testing.T) { func TestGetPod(t *testing.T) {
ctx := api.NewDefaultContext()
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods/foo"}, Request: testRequest{Method: "GET", Path: "/pods/foo"},
Response: Response{ Response: Response{
@ -225,7 +229,7 @@ func TestGetPod(t *testing.T) {
}, },
}, },
} }
receivedPod, err := c.Setup().GetPod("foo") receivedPod, err := c.Setup().GetPod(ctx, "foo")
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
@ -234,7 +238,7 @@ func TestDeletePod(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/pods/foo"}, Request: testRequest{Method: "DELETE", Path: "/pods/foo"},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().DeletePod("foo") err := c.Setup().DeletePod(api.NewDefaultContext(), "foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
@ -255,7 +259,7 @@ func TestCreatePod(t *testing.T) {
Body: requestPod, Body: requestPod,
}, },
} }
receivedPod, err := c.Setup().CreatePod(requestPod) receivedPod, err := c.Setup().CreatePod(api.NewDefaultContext(), requestPod)
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
@ -274,7 +278,7 @@ func TestUpdatePod(t *testing.T) {
Request: testRequest{Method: "PUT", Path: "/pods/foo"}, Request: testRequest{Method: "PUT", Path: "/pods/foo"},
Response: Response{StatusCode: 200, Body: requestPod}, Response: Response{StatusCode: 200, Body: requestPod},
} }
receivedPod, err := c.Setup().UpdatePod(requestPod) receivedPod, err := c.Setup().UpdatePod(api.NewDefaultContext(), requestPod)
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
@ -298,7 +302,7 @@ func TestListControllers(t *testing.T) {
}, },
}, },
} }
receivedControllerList, err := c.Setup().ListReplicationControllers(labels.Everything()) receivedControllerList, err := c.Setup().ListReplicationControllers(api.NewContext(), labels.Everything())
c.Validate(t, receivedControllerList, err) c.Validate(t, receivedControllerList, err)
} }
@ -320,7 +324,7 @@ func TestGetController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().GetReplicationController("foo") receivedController, err := c.Setup().GetReplicationController(api.NewDefaultContext(), "foo")
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
@ -344,7 +348,7 @@ func TestUpdateController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().UpdateReplicationController(requestController) receivedController, err := c.Setup().UpdateReplicationController(api.NewDefaultContext(), requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
@ -353,7 +357,7 @@ func TestDeleteController(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/replicationControllers/foo"}, Request: testRequest{Method: "DELETE", Path: "/replicationControllers/foo"},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().DeleteReplicationController("foo") err := c.Setup().DeleteReplicationController(api.NewDefaultContext(), "foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
@ -377,7 +381,7 @@ func TestCreateController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().CreateReplicationController(requestController) receivedController, err := c.Setup().CreateReplicationController(api.NewDefaultContext(), requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
@ -410,7 +414,7 @@ func TestListServices(t *testing.T) {
}, },
}, },
} }
receivedServiceList, err := c.Setup().ListServices(labels.Everything()) receivedServiceList, err := c.Setup().ListServices(api.NewDefaultContext(), labels.Everything())
c.Validate(t, receivedServiceList, err) c.Validate(t, receivedServiceList, err)
} }
@ -437,7 +441,7 @@ func TestListServicesLabels(t *testing.T) {
c.Setup() c.Setup()
c.QueryValidator["labels"] = validateLabels c.QueryValidator["labels"] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector() selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.ListServices(selector) receivedServiceList, err := c.ListServices(api.NewDefaultContext(), selector)
c.Validate(t, receivedServiceList, err) c.Validate(t, receivedServiceList, err)
} }
@ -446,7 +450,7 @@ func TestGetService(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/services/1"}, Request: testRequest{Method: "GET", Path: "/services/1"},
Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
} }
response, err := c.Setup().GetService("1") response, err := c.Setup().GetService(api.NewDefaultContext(), "1")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
@ -455,7 +459,7 @@ func TestCreateService(t *testing.T) {
Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
} }
response, err := c.Setup().CreateService(&api.Service{JSONBase: api.JSONBase{ID: "service-1"}}) response, err := c.Setup().CreateService(api.NewDefaultContext(), &api.Service{JSONBase: api.JSONBase{ID: "service-1"}})
c.Validate(t, response, err) c.Validate(t, response, err)
} }
@ -465,7 +469,7 @@ func TestUpdateService(t *testing.T) {
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc}, Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
Response: Response{StatusCode: 200, Body: svc}, Response: Response{StatusCode: 200, Body: svc},
} }
response, err := c.Setup().UpdateService(svc) response, err := c.Setup().UpdateService(api.NewDefaultContext(), svc)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
@ -474,7 +478,7 @@ func TestDeleteService(t *testing.T) {
Request: testRequest{Method: "DELETE", Path: "/services/1"}, Request: testRequest{Method: "DELETE", Path: "/services/1"},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().DeleteService("1") err := c.Setup().DeleteService(api.NewDefaultContext(), "1")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
@ -492,7 +496,7 @@ func TestListEndpooints(t *testing.T) {
}, },
}, },
} }
receivedEndpointsList, err := c.Setup().ListEndpoints(labels.Everything()) receivedEndpointsList, err := c.Setup().ListEndpoints(api.NewDefaultContext(), labels.Everything())
c.Validate(t, receivedEndpointsList, err) c.Validate(t, receivedEndpointsList, err)
} }
@ -501,7 +505,7 @@ func TestGetEndpoints(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"}, Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"},
Response: Response{StatusCode: 200, Body: &api.Endpoints{JSONBase: api.JSONBase{ID: "endpoint-1"}}}, Response: Response{StatusCode: 200, Body: &api.Endpoints{JSONBase: api.JSONBase{ID: "endpoint-1"}}},
} }
response, err := c.Setup().GetEndpoints("endpoint-1") response, err := c.Setup().GetEndpoints(api.NewDefaultContext(), "endpoint-1")
c.Validate(t, response, err) c.Validate(t, response, err)
} }

View File

@ -49,13 +49,13 @@ type FakePodControl struct {
lock sync.Mutex lock sync.Mutex
} }
func (f *FakePodControl) createReplica(spec api.ReplicationController) { func (f *FakePodControl) createReplica(ctx api.Context, spec api.ReplicationController) {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
f.controllerSpec = append(f.controllerSpec, spec) f.controllerSpec = append(f.controllerSpec, spec)
} }
func (f *FakePodControl) deletePod(podID string) error { func (f *FakePodControl) deletePod(ctx api.Context, podID string) error {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
f.deletePodID = append(f.deletePodID, podID) f.deletePodID = append(f.deletePodID, podID)
@ -169,6 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
} }
func TestCreateReplica(t *testing.T) { func TestCreateReplica(t *testing.T) {
ctx := api.NewDefaultContext()
body := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), &api.Pod{}) body := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), &api.Pod{})
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
@ -204,7 +205,7 @@ func TestCreateReplica(t *testing.T) {
}, },
} }
podControl.createReplica(controllerSpec) podControl.createReplica(ctx, controllerSpec)
expectedPod := api.Pod{ expectedPod := api.Pod{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{
@ -323,7 +324,7 @@ type FakeWatcher struct {
*client.Fake *client.Fake
} }
func (fw FakeWatcher) WatchReplicationControllers(l, f labels.Selector, rv uint64) (watch.Interface, error) { func (fw FakeWatcher) WatchReplicationControllers(ctx api.Context, l, f labels.Selector, rv uint64) (watch.Interface, error) {
return fw.w, nil return fw.w, nil
} }

View File

@ -43,7 +43,7 @@ func TestUpdateWithPods(t *testing.T) {
}, },
}, },
} }
Update("foo", &fakeClient, 0, "") Update(api.NewDefaultContext(), "foo", &fakeClient, 0, "")
if len(fakeClient.Actions) != 5 { if len(fakeClient.Actions) != 5 {
t.Fatalf("Unexpected action list %#v", fakeClient.Actions) t.Fatalf("Unexpected action list %#v", fakeClient.Actions)
} }
@ -57,7 +57,7 @@ func TestUpdateWithPods(t *testing.T) {
func TestUpdateNoPods(t *testing.T) { func TestUpdateNoPods(t *testing.T) {
fakeClient := client.Fake{} fakeClient := client.Fake{}
Update("foo", &fakeClient, 0, "") Update(api.NewDefaultContext(), "foo", &fakeClient, 0, "")
if len(fakeClient.Actions) != 2 { if len(fakeClient.Actions) != 2 {
t.Errorf("Unexpected action list %#v", fakeClient.Actions) t.Errorf("Unexpected action list %#v", fakeClient.Actions)
} }
@ -87,7 +87,7 @@ func TestUpdateWithNewImage(t *testing.T) {
}, },
}, },
} }
Update("foo", &fakeClient, 0, "fooImage:2") Update(api.NewDefaultContext(), "foo", &fakeClient, 0, "fooImage:2")
if len(fakeClient.Actions) != 6 { if len(fakeClient.Actions) != 6 {
t.Errorf("Unexpected action list %#v", fakeClient.Actions) t.Errorf("Unexpected action list %#v", fakeClient.Actions)
} }
@ -109,7 +109,7 @@ func TestRunController(t *testing.T) {
name := "name" name := "name"
image := "foo/bar" image := "foo/bar"
replicas := 3 replicas := 3
RunController(image, name, replicas, &fakeClient, "8080:80", -1) RunController(api.NewDefaultContext(), image, name, replicas, &fakeClient, "8080:80", -1)
if len(fakeClient.Actions) != 1 || fakeClient.Actions[0].Action != "create-controller" { if len(fakeClient.Actions) != 1 || fakeClient.Actions[0].Action != "create-controller" {
t.Errorf("Unexpected actions: %#v", fakeClient.Actions) t.Errorf("Unexpected actions: %#v", fakeClient.Actions)
} }
@ -126,7 +126,7 @@ func TestRunControllerWithService(t *testing.T) {
name := "name" name := "name"
image := "foo/bar" image := "foo/bar"
replicas := 3 replicas := 3
RunController(image, name, replicas, &fakeClient, "", 8000) RunController(api.NewDefaultContext(), image, name, replicas, &fakeClient, "", 8000)
if len(fakeClient.Actions) != 2 || if len(fakeClient.Actions) != 2 ||
fakeClient.Actions[0].Action != "create-controller" || fakeClient.Actions[0].Action != "create-controller" ||
fakeClient.Actions[1].Action != "create-service" { fakeClient.Actions[1].Action != "create-service" {
@ -143,7 +143,7 @@ func TestRunControllerWithService(t *testing.T) {
func TestStopController(t *testing.T) { func TestStopController(t *testing.T) {
fakeClient := client.Fake{} fakeClient := client.Fake{}
name := "name" name := "name"
StopController(name, &fakeClient) StopController(api.NewDefaultContext(), name, &fakeClient)
if len(fakeClient.Actions) != 2 { if len(fakeClient.Actions) != 2 {
t.Errorf("Unexpected actions: %#v", fakeClient.Actions) t.Errorf("Unexpected actions: %#v", fakeClient.Actions)
} }
@ -162,7 +162,7 @@ func TestResizeController(t *testing.T) {
fakeClient := client.Fake{} fakeClient := client.Fake{}
name := "name" name := "name"
replicas := 17 replicas := 17
ResizeController(name, replicas, &fakeClient) ResizeController(api.NewDefaultContext(), name, replicas, &fakeClient)
if len(fakeClient.Actions) != 2 { if len(fakeClient.Actions) != 2 {
t.Errorf("Unexpected actions: %#v", fakeClient.Actions) t.Errorf("Unexpected actions: %#v", fakeClient.Actions)
} }
@ -180,7 +180,7 @@ func TestResizeController(t *testing.T) {
func TestCloudCfgDeleteController(t *testing.T) { func TestCloudCfgDeleteController(t *testing.T) {
fakeClient := client.Fake{} fakeClient := client.Fake{}
name := "name" name := "name"
err := DeleteController(name, &fakeClient) err := DeleteController(api.NewDefaultContext(), name, &fakeClient)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
@ -206,7 +206,7 @@ func TestCloudCfgDeleteControllerWithReplicas(t *testing.T) {
}, },
} }
name := "name" name := "name"
err := DeleteController(name, &fakeClient) err := DeleteController(api.NewDefaultContext(), name, &fakeClient)
if len(fakeClient.Actions) != 1 { if len(fakeClient.Actions) != 1 {
t.Errorf("Unexpected actions: %#v", fakeClient.Actions) t.Errorf("Unexpected actions: %#v", fakeClient.Actions)
} }