mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
gofmt
This commit is contained in:
parent
9010ef954c
commit
9f76f13205
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func expectNoError(t *testing.T, err error) {
|
||||
@ -19,13 +19,13 @@ func TestFakeHandlerPath(t *testing.T) {
|
||||
method := "GET"
|
||||
path := "/foo/bar"
|
||||
body := "somebody"
|
||||
|
||||
req, err := http.NewRequest(method, server.URL + path, bytes.NewBufferString(body));
|
||||
|
||||
req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body))
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
expectNoError(t, err)
|
||||
|
||||
|
||||
handler.ValidateRequest(t, path, method, &body)
|
||||
}
|
||||
|
||||
@ -34,18 +34,18 @@ func TestFakeHandlerPathNoBody(t *testing.T) {
|
||||
server := httptest.NewServer(&handler)
|
||||
method := "GET"
|
||||
path := "/foo/bar"
|
||||
|
||||
req, err := http.NewRequest(method, server.URL + path, nil);
|
||||
|
||||
req, err := http.NewRequest(method, server.URL+path, nil)
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
expectNoError(t, err)
|
||||
|
||||
|
||||
handler.ValidateRequest(t, path, method, nil)
|
||||
}
|
||||
|
||||
type fakeError struct {
|
||||
errors[] string
|
||||
errors []string
|
||||
}
|
||||
|
||||
func (f *fakeError) Errorf(format string, args ...interface{}) {
|
||||
@ -59,12 +59,12 @@ func TestFakeHandlerWrongPath(t *testing.T) {
|
||||
path := "/foo/bar"
|
||||
fakeT := fakeError{}
|
||||
|
||||
req, err := http.NewRequest(method, server.URL + "/foo/baz", nil);
|
||||
req, err := http.NewRequest(method, server.URL+"/foo/baz", nil)
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
expectNoError(t, err)
|
||||
|
||||
|
||||
handler.ValidateRequest(&fakeT, path, method, nil)
|
||||
if len(fakeT.errors) != 1 {
|
||||
t.Errorf("Unexpected error set: %#v", fakeT.errors)
|
||||
@ -78,12 +78,12 @@ func TestFakeHandlerWrongMethod(t *testing.T) {
|
||||
path := "/foo/bar"
|
||||
fakeT := fakeError{}
|
||||
|
||||
req, err := http.NewRequest("PUT", server.URL + path, nil);
|
||||
req, err := http.NewRequest("PUT", server.URL+path, nil)
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
expectNoError(t, err)
|
||||
|
||||
|
||||
handler.ValidateRequest(&fakeT, path, method, nil)
|
||||
if len(fakeT.errors) != 1 {
|
||||
t.Errorf("Unexpected error set: %#v", fakeT.errors)
|
||||
@ -98,12 +98,12 @@ func TestFakeHandlerWrongBody(t *testing.T) {
|
||||
body := "somebody"
|
||||
fakeT := fakeError{}
|
||||
|
||||
req, err := http.NewRequest(method, server.URL + path, bytes.NewBufferString(body));
|
||||
req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body))
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
expectNoError(t, err)
|
||||
|
||||
|
||||
otherbody := "otherbody"
|
||||
handler.ValidateRequest(&fakeT, path, method, &otherbody)
|
||||
if len(fakeT.errors) != 1 {
|
||||
@ -119,7 +119,7 @@ func TestFakeHandlerNilBody(t *testing.T) {
|
||||
body := "somebody"
|
||||
fakeT := fakeError{}
|
||||
|
||||
req, err := http.NewRequest(method, server.URL + path, nil);
|
||||
req, err := http.NewRequest(method, server.URL+path, nil)
|
||||
expectNoError(t, err)
|
||||
client := http.Client{}
|
||||
_, err = client.Do(req)
|
||||
@ -130,5 +130,3 @@ func TestFakeHandlerNilBody(t *testing.T) {
|
||||
t.Errorf("Unexpected error set: %#v", fakeT.errors)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,22 +2,22 @@ package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
func TestMakeJSONString(t *testing.T) {
|
||||
pod := api.Pod{
|
||||
JSONBase: api.JSONBase{ ID: "foo" },
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
body := MakeJSONString(pod)
|
||||
|
||||
|
||||
expectedBody, err := json.Marshal(pod)
|
||||
expectNoError(t, err)
|
||||
if string(expectedBody) != body {
|
||||
@ -30,7 +30,7 @@ func TestHandleCrash(t *testing.T) {
|
||||
expect := 10
|
||||
for i := 0; i < expect; i = i + 1 {
|
||||
defer HandleCrash()
|
||||
if i % 2 == 0 {
|
||||
if i%2 == 0 {
|
||||
panic("Test Panic")
|
||||
}
|
||||
count = count + 1
|
||||
@ -39,4 +39,3 @@ func TestHandleCrash(t *testing.T) {
|
||||
t.Errorf("Expected %d iterations, found %d", expect, count)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user