From 3b9029ee94b8e3675cb0c3beea730facaad887b2 Mon Sep 17 00:00:00 2001 From: Kelsey Hightower Date: Sun, 20 Jul 2014 09:13:11 -0700 Subject: [PATCH 1/2] remove unnecessary expectNoError helper function This patch completes a TODO item for the replication_controller test suite by removing the expectNoError helper function, which does not reduce enough typing to justify its usage. --- pkg/controller/replication_controller_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index 4b147f83fdd..ac7b4aa7380 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -34,13 +34,6 @@ import ( // TODO: Move this to a common place, it's needed in multiple tests. var apiPath = "/api/v1beta1" -// TODO: This doesn't reduce typing enough to make it worth the less readable errors. Remove. -func expectNoError(t *testing.T, err error) { - if err != nil { - t.Errorf("Unexpected error: %#v", err) - } -} - func makeURL(suffix string) string { return apiPath + suffix } @@ -234,7 +227,9 @@ func TestHandleWatchResponseNotSet(t *testing.T) { _, err := manager.handleWatchResponse(&etcd.Response{ Action: "update", }) - expectNoError(t, err) + if err != nil { + t.Errorf("Unexpected error: %#v", err) + } } func TestHandleWatchResponseNoNode(t *testing.T) { @@ -299,7 +294,9 @@ func TestHandleWatchResponse(t *testing.T) { controller := makeReplicationController(2) data, err := json.Marshal(controller) - expectNoError(t, err) + if err != nil { + t.Errorf("Unexpected error: %#v", err) + } controllerOut, err := manager.handleWatchResponse(&etcd.Response{ Action: "set", Node: &etcd.Node{ @@ -331,7 +328,9 @@ func TestHandleWatchResponseDelete(t *testing.T) { controller := makeReplicationController(2) data, err := json.Marshal(controller) - expectNoError(t, err) + if err != nil { + t.Errorf("Unexpected error: %#v", err) + } controllerOut, err := manager.handleWatchResponse(&etcd.Response{ Action: "delete", PrevNode: &etcd.Node{ From a9e0b0d1a3a5a3c54e7fe8694820c2370dc12f85 Mon Sep 17 00:00:00 2001 From: Kelsey Hightower Date: Sun, 20 Jul 2014 11:58:22 -0700 Subject: [PATCH 2/2] use %v instead of %#v when logging failures --- pkg/controller/replication_controller_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index ac7b4aa7380..54abf5bf510 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -228,7 +228,7 @@ func TestHandleWatchResponseNotSet(t *testing.T) { Action: "update", }) if err != nil { - t.Errorf("Unexpected error: %#v", err) + t.Errorf("Unexpected error: %v", err) } } @@ -295,7 +295,7 @@ func TestHandleWatchResponse(t *testing.T) { data, err := json.Marshal(controller) if err != nil { - t.Errorf("Unexpected error: %#v", err) + t.Errorf("Unexpected error: %v", err) } controllerOut, err := manager.handleWatchResponse(&etcd.Response{ Action: "set", @@ -329,7 +329,7 @@ func TestHandleWatchResponseDelete(t *testing.T) { data, err := json.Marshal(controller) if err != nil { - t.Errorf("Unexpected error: %#v", err) + t.Errorf("Unexpected error: %v", err) } controllerOut, err := manager.handleWatchResponse(&etcd.Response{ Action: "delete",