mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Fix PathPrefix for subresources
This commit is contained in:
parent
21f30db4c6
commit
dde1221839
@ -1284,30 +1284,47 @@ func TestRootSelfLink(t *testing.T) {
|
|||||||
takesPath: "atAPath",
|
takesPath: "atAPath",
|
||||||
}
|
}
|
||||||
storage["simple"] = &simpleStorage
|
storage["simple"] = &simpleStorage
|
||||||
|
storage["simple/sub"] = &simpleStorage
|
||||||
handler := handle(storage)
|
handler := handle(storage)
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
resp, err := http.Get(server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo")
|
testCases := []struct {
|
||||||
if err != nil {
|
url string
|
||||||
t.Fatalf("unexpected error: %v", err)
|
selfLink string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
url: server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo",
|
||||||
|
selfLink: "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo/sub",
|
||||||
|
selfLink: "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo/sub",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
for _, test := range testCases {
|
||||||
t.Errorf("Unexpected status: %d, Expected: %d, %#v", resp.StatusCode, http.StatusOK, resp)
|
resp, err := http.Get(test.url)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
t.Logf("Data: %s", string(body))
|
|
||||||
}
|
|
||||||
var out genericapitesting.SimpleRoot
|
|
||||||
if _, err := extractBody(resp, &out); err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if out.SelfLink != "/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/simple/foo" {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("unexpected self link: %#v", out)
|
t.Errorf("Unexpected status: %d, Expected: %d, %#v", resp.StatusCode, http.StatusOK, resp)
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
t.Logf("Data: %s", string(body))
|
||||||
|
}
|
||||||
|
var out genericapitesting.SimpleRoot
|
||||||
|
if _, err := extractBody(resp, &out); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if out.SelfLink != test.selfLink {
|
||||||
|
t.Errorf("unexpected self link: %#v", out.SelfLink)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
GetContext: ctxFn,
|
GetContext: ctxFn,
|
||||||
SelfLinker: a.group.Linker,
|
SelfLinker: a.group.Linker,
|
||||||
ClusterScoped: true,
|
ClusterScoped: true,
|
||||||
SelfLinkPathPrefix: gpath.Join(a.prefix, resourcePath) + "/",
|
SelfLinkPathPrefix: gpath.Join(a.prefix, resource) + "/",
|
||||||
SelfLinkPathSuffix: suffix,
|
SelfLinkPathSuffix: suffix,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user