Fix selfLinks of pods started from manifests

This commit is contained in:
xiangpengzhao
2017-05-25 09:48:20 +08:00
parent ee0de5f376
commit 4ec3fc4e2a
2 changed files with 29 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string {
if len(namespace) == 0 {
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
}

View File

@@ -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)
}
}
}