Merge pull request #66111 from fntlnz/fieldpath-tests-improvement

Automatic merge from submit-queue (batch tested with PRs 66011, 66111, 66106, 66039, 65745). 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>.

fieldpath: Add tests for missing cases

Tests some missing cases in `pkg/fieldpath`.

**Release note**:

```release-note
NONE
```


Signed-off-by: Lorenzo Fontana <lo@linux.com>
This commit is contained in:
Kubernetes Submit Queue 2018-07-12 17:57:05 -07:00 committed by GitHub
commit 4c4d18a582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,6 +107,28 @@ func TestExtractFieldPathAsString(t *testing.T) {
},
expectedValue: "1",
},
{
name: "ok - uid",
fieldPath: "metadata.uid",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
UID: "b70b3269-858e-12a8-9cf2-1232a194038a",
},
},
expectedValue: "b70b3269-858e-12a8-9cf2-1232a194038a",
},
{
name: "ok - label",
fieldPath: "metadata.labels['something']",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"something": "label value",
},
},
},
expectedValue: "label value",
},
{
name: "invalid expression",
fieldPath: "metadata.whoops",
@ -137,6 +159,12 @@ func TestExtractFieldPathAsString(t *testing.T) {
},
expectedMessageFragment: "invalid key subscript in metadata.labels",
},
{
name: "invalid subscript",
fieldPath: "metadata.notexisting['something']",
obj: &v1.Pod{},
expectedMessageFragment: "fieldPath \"metadata.notexisting['something']\" does not support subscript",
},
}
for _, tc := range cases {