Remove expectNoError from client, kubelet, and util

This commit is contained in:
Clayton Coleman
2014-08-03 19:59:47 -04:00
parent 2282f9ce3a
commit f7149926c0
5 changed files with 118 additions and 64 deletions

View File

@@ -23,12 +23,6 @@ import (
"testing"
)
func expectNoError(t *testing.T, err error) {
if err != nil {
t.Errorf("Unexpected error: %#v", err)
}
}
func TestFakeHandlerPath(t *testing.T) {
handler := FakeHandler{}
server := httptest.NewServer(&handler)
@@ -37,10 +31,15 @@ func TestFakeHandlerPath(t *testing.T) {
body := "somebody"
req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body))
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
handler.ValidateRequest(t, path, method, &body)
}
@@ -52,10 +51,15 @@ func TestFakeHandlerPathNoBody(t *testing.T) {
path := "/foo/bar"
req, err := http.NewRequest(method, server.URL+path, nil)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
handler.ValidateRequest(t, path, method, nil)
}
@@ -76,10 +80,15 @@ func TestFakeHandlerWrongPath(t *testing.T) {
fakeT := fakeError{}
req, err := http.NewRequest(method, server.URL+"/foo/baz", nil)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
handler.ValidateRequest(&fakeT, path, method, nil)
if len(fakeT.errors) != 1 {
@@ -95,10 +104,15 @@ func TestFakeHandlerWrongMethod(t *testing.T) {
fakeT := fakeError{}
req, err := http.NewRequest("PUT", server.URL+path, nil)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
handler.ValidateRequest(&fakeT, path, method, nil)
if len(fakeT.errors) != 1 {
@@ -115,10 +129,15 @@ func TestFakeHandlerWrongBody(t *testing.T) {
fakeT := fakeError{}
req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body))
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
otherbody := "otherbody"
handler.ValidateRequest(&fakeT, path, method, &otherbody)
@@ -136,10 +155,15 @@ func TestFakeHandlerNilBody(t *testing.T) {
fakeT := fakeError{}
req, err := http.NewRequest(method, server.URL+path, nil)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := http.Client{}
_, err = client.Do(req)
expectNoError(t, err)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
handler.ValidateRequest(&fakeT, path, method, &body)
if len(fakeT.errors) != 1 {