Make Request#RequestURI honor configured context root

Kubernetes-commit: 5677f7ab0b1b1ab22a71d01e4a710bf0f5e633aa
This commit is contained in:
Jordan Liggitt
2025-04-03 12:51:46 -04:00
committed by Kubernetes Publisher
parent 7aa362d5dd
commit 25d4fa6ba8
3 changed files with 40 additions and 10 deletions

View File

@@ -292,14 +292,36 @@ func TestRequestError(t *testing.T) {
}
func TestRequestURI(t *testing.T) {
r := (&Request{}).Param("foo", "a")
r := (&Request{c: &RESTClient{base: &url.URL{Path: "/"}}}).Param("foo", "a").Param("bar", "b")
r.Prefix("other")
r.RequestURI("/test?foo=b&a=b&c=1&c=2")
if r.pathPrefix != "/test" {
t.Errorf("path is wrong: %#v", r)
}
if !reflect.DeepEqual(r.params, url.Values{"a": []string{"b"}, "foo": []string{"b"}, "c": []string{"1", "2"}}) {
t.Errorf("should have set a param: %#v", r)
t.Errorf("should have set a param, got: %#v", r.params)
}
}
func TestRequestURIContext(t *testing.T) {
r := (&Request{c: &RESTClient{base: &url.URL{Path: "/context"}}}).Param("foo", "a").Param("bar", "b")
r.Prefix("other")
r.RequestURI("/test?foo=b&a=b&c=1&c=2")
if r.pathPrefix != "/context/test" {
t.Errorf("path is wrong: %#v", r)
}
if !reflect.DeepEqual(r.params, url.Values{"a": []string{"b"}, "foo": []string{"b"}, "c": []string{"1", "2"}}) {
t.Errorf("should have set a param, got: %#v", r.params)
}
r = (&Request{c: &RESTClient{base: &url.URL{Path: "/context"}}}).Param("foo", "a").Param("bar", "b")
r.Prefix("other")
r.RequestURI("../test?foo=b&a=b&c=1&c=2")
if r.pathPrefix != "/test" {
t.Errorf("path is wrong: %#v", r)
}
if !reflect.DeepEqual(r.params, url.Values{"a": []string{"b"}, "foo": []string{"b"}, "c": []string{"1", "2"}}) {
t.Errorf("should have set a param, got: %#v", r.params)
}
}