Commit 4ec3fc4e authored by xiangpengzhao's avatar xiangpengzhao

Fix selfLinks of pods started from manifests

parent ee0de5f3
...@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string { ...@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string {
if len(namespace) == 0 { if len(namespace) == 0 {
namespace = metav1.NamespaceDefault namespace = metav1.NamespaceDefault
} }
selfLink = fmt.Sprintf("/api/"+api.Registry.GroupOrDie(api.GroupName).GroupVersion.Version+"/pods/namespaces/%s/%s", name, namespace) selfLink = fmt.Sprintf("/api/"+api.Registry.GroupOrDie(api.GroupName).GroupVersion.Version+"/namespaces/%s/pods/%s", namespace, name)
return selfLink return selfLink
} }
......
...@@ -160,3 +160,31 @@ func TestDecodePodList(t *testing.T) { ...@@ -160,3 +160,31 @@ func TestDecodePodList(t *testing.T) {
} }
} }
} }
func TestGetSelfLink(t *testing.T) {
var testCases = []struct {
desc string
name string
namespace string
expectedSelfLink string
}{
{
desc: "No namespace specified",
name: "foo",
namespace: "",
expectedSelfLink: "/api/v1/namespaces/default/pods/foo",
},
{
desc: "Namespace specified",
name: "foo",
namespace: "bar",
expectedSelfLink: "/api/v1/namespaces/bar/pods/foo",
},
}
for _, testCase := range testCases {
selfLink := getSelfLink(testCase.name, testCase.namespace)
if testCase.expectedSelfLink != selfLink {
t.Errorf("%s: getSelfLink error, expected: %s, got: %s", testCase.desc, testCase.expectedSelfLink, selfLink)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment