mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #115685 from skitt/rest-req-error
client-go: add an Error() function on Request
This commit is contained in:
commit
30f1567145
@ -481,7 +481,13 @@ func (r *Request) Body(obj interface{}) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL returns the current working URL.
|
// Error returns any error encountered constructing the request, if any.
|
||||||
|
func (r *Request) Error() error {
|
||||||
|
return r.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL returns the current working URL. Check the result of Error() to ensure
|
||||||
|
// that the returned URL is valid.
|
||||||
func (r *Request) URL() *url.URL {
|
func (r *Request) URL() *url.URL {
|
||||||
p := r.pathPrefix
|
p := r.pathPrefix
|
||||||
if r.namespaceSet && len(r.namespace) > 0 {
|
if r.namespaceSet && len(r.namespace) > 0 {
|
||||||
|
@ -269,6 +269,26 @@ func TestRequestVersionedParamsFromListOptions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRequestVersionedParamsWithInvalidScheme(t *testing.T) {
|
||||||
|
parameterCodec := runtime.NewParameterCodec(runtime.NewScheme())
|
||||||
|
r := (&Request{c: &RESTClient{content: ClientContentConfig{GroupVersion: v1.SchemeGroupVersion}}})
|
||||||
|
r.VersionedParams(&v1.PodExecOptions{Stdin: false, Stdout: true},
|
||||||
|
parameterCodec)
|
||||||
|
|
||||||
|
if r.Error() == nil {
|
||||||
|
t.Errorf("should have recorded an error: %#v", r.params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestError(t *testing.T) {
|
||||||
|
// Invalid body, see TestRequestBody()
|
||||||
|
r := (&Request{}).Body([]string{"test"})
|
||||||
|
|
||||||
|
if r.Error() != r.err {
|
||||||
|
t.Errorf("getter should be identical to reference: %#v %#v", r.Error(), r.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRequestURI(t *testing.T) {
|
func TestRequestURI(t *testing.T) {
|
||||||
r := (&Request{}).Param("foo", "a")
|
r := (&Request{}).Param("foo", "a")
|
||||||
r.Prefix("other")
|
r.Prefix("other")
|
||||||
|
Loading…
Reference in New Issue
Block a user