Automatic merge from submit-queue (batch tested with PRs 52461, 55503). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Add testcase for SelfLink function

**What this PR does / why we need it**:
Add testcase for SelfLink function.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-11 15:21:29 -08:00 committed by GitHub
commit 589b1b107d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,6 +74,36 @@ var status = &metav1.Status{
Message: "",
}
func TestSelfLink(t *testing.T) {
testCases := []struct {
resource string
name string
expected string
}{
{"resource", "name", "/api/" + Default.GroupVersion().Version + "/resource/name"},
{"resource", "", "/api/" + Default.GroupVersion().Version + "/resource"},
}
for _, item := range testCases {
if actual := Default.SelfLink(item.resource, item.name); actual != item.expected {
t.Errorf("Expected: %s, got: %s for resource: %s and name: %s", item.expected, actual, item.resource, item.name)
}
}
testGroupCases := []struct {
resource string
name string
expected string
}{
{"resource", "name", "/apis/" + Admission.GroupVersion().Group + "/" + Admission.GroupVersion().Version + "/resource/name"},
{"resource", "", "/apis/" + Admission.GroupVersion().Group + "/" + Admission.GroupVersion().Version + "/resource"},
}
for _, item := range testGroupCases {
if actual := Admission.SelfLink(item.resource, item.name); actual != item.expected {
t.Errorf("Expected: %s, got: %s for resource: %s and name: %s", item.expected, actual, item.resource, item.name)
}
}
}
func TestV1EncodeDecodeStatus(t *testing.T) {
v1Codec := Default.Codec()