mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Remove unnecessary expectNoError helper function
This patch completes a TODO item for the kubecfg package test suite by removing the expectNoError helper function, which does not reduce enough typing to justify its usage.
This commit is contained in:
parent
b577f36492
commit
682efb7ca5
@ -27,13 +27,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
action string
|
action string
|
||||||
value interface{}
|
value interface{}
|
||||||
@ -223,7 +216,9 @@ func TestCloudCfgDeleteController(t *testing.T) {
|
|||||||
fakeClient := FakeKubeClient{}
|
fakeClient := FakeKubeClient{}
|
||||||
name := "name"
|
name := "name"
|
||||||
err := DeleteController(name, &fakeClient)
|
err := DeleteController(name, &fakeClient)
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
if len(fakeClient.actions) != 2 {
|
if len(fakeClient.actions) != 2 {
|
||||||
t.Errorf("Unexpected actions: %#v", fakeClient.actions)
|
t.Errorf("Unexpected actions: %#v", fakeClient.actions)
|
||||||
}
|
}
|
||||||
|
@ -26,20 +26,30 @@ import (
|
|||||||
func TestFileServing(t *testing.T) {
|
func TestFileServing(t *testing.T) {
|
||||||
data := "This is test data"
|
data := "This is test data"
|
||||||
dir, err := ioutil.TempDir("", "data")
|
dir, err := ioutil.TempDir("", "data")
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
err = ioutil.WriteFile(dir+"/test.txt", []byte(data), 0755)
|
err = ioutil.WriteFile(dir+"/test.txt", []byte(data), 0755)
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
prefix := "/foo/"
|
prefix := "/foo/"
|
||||||
handler := makeFileHandler(prefix, dir)
|
handler := makeFileHandler(prefix, dir)
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
req, err := http.NewRequest("GET", server.URL+prefix+"test.txt", nil)
|
req, err := http.NewRequest("GET", server.URL+prefix+"test.txt", nil)
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(res.Body)
|
b, err := ioutil.ReadAll(res.Body)
|
||||||
expectNoError(t, err)
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
t.Errorf("Unexpected status: %d", res.StatusCode)
|
t.Errorf("Unexpected status: %d", res.StatusCode)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user