mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Test if headers are set
This commit is contained in:
parent
cd3ab5d82d
commit
ac5d2cec44
@ -58,6 +58,33 @@ func TestNewRequestSetsAccept(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type clientFunc func(req *http.Request) (*http.Response, error)
|
||||
|
||||
func (f clientFunc) Do(req *http.Request) (*http.Response, error) {
|
||||
return f(req)
|
||||
}
|
||||
|
||||
func TestRequestSetsHeaders(t *testing.T) {
|
||||
server := clientFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if req.Header.Get("Accept") != "application/other, */*" {
|
||||
t.Errorf("unexpected headers: %#v", req.Header)
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusForbidden,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, nil
|
||||
})
|
||||
config := defaultContentConfig()
|
||||
config.ContentType = "application/other"
|
||||
serializers := defaultSerializers()
|
||||
r := NewRequest(server, "get", &url.URL{Path: "/path"}, "", config, serializers, nil, nil)
|
||||
|
||||
// Check if all "issue" methods are setting headers.
|
||||
_ = r.Do()
|
||||
_, _ = r.Watch()
|
||||
_, _ = r.Stream()
|
||||
}
|
||||
|
||||
func TestRequestWithErrorWontChange(t *testing.T) {
|
||||
original := Request{
|
||||
err: errors.New("test"),
|
||||
@ -463,12 +490,6 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type clientFunc func(req *http.Request) (*http.Response, error)
|
||||
|
||||
func (f clientFunc) Do(req *http.Request) (*http.Response, error) {
|
||||
return f(req)
|
||||
}
|
||||
|
||||
func TestRequestWatch(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Request *Request
|
||||
|
Loading…
Reference in New Issue
Block a user