Merge pull request #115685 from skitt/rest-req-error

client-go: add an Error() function on Request
This commit is contained in:
Kubernetes Prow Robot 2023-02-13 14:53:41 -08:00 committed by GitHub
commit 30f1567145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -481,7 +481,13 @@ func (r *Request) Body(obj interface{}) *Request {
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 {
p := r.pathPrefix
if r.namespaceSet && len(r.namespace) > 0 {

View File

@ -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) {
r := (&Request{}).Param("foo", "a")
r.Prefix("other")