From 1133cbffc1c08dec279904229d6144c190bc2ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Thu, 30 Jan 2020 12:04:23 +0100 Subject: [PATCH] Allow Action's Matches function to specify a subresource. In other parts of the system (notably in RBAC rules), the "resource/subresource" notation is common to specify an explicit subresource. This makes this notation available to tests that use the `Matches` function on client actions as well. Backwards compatibility is kept by ignoring the `Subresource` field if no specific subresource is defined in the resource string itself. Kubernetes-commit: 47277f281eb0e7d484555e4d210b0ddb42974793 --- testing/actions.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/testing/actions.go b/testing/actions.go index f56b34ee..b6b2c1f2 100644 --- a/testing/actions.go +++ b/testing/actions.go @@ -439,8 +439,18 @@ func (a ActionImpl) GetSubresource() string { return a.Subresource } func (a ActionImpl) Matches(verb, resource string) bool { + // Stay backwards compatible. + if !strings.Contains(resource, "/") { + return strings.EqualFold(verb, a.Verb) && + strings.EqualFold(resource, a.Resource.Resource) + } + + parts := strings.SplitN(resource, "/", 2) + topresource, subresource := parts[0], parts[1] + return strings.EqualFold(verb, a.Verb) && - strings.EqualFold(resource, a.Resource.Resource) + strings.EqualFold(topresource, a.Resource.Resource) && + strings.EqualFold(subresource, a.Subresource) } func (a ActionImpl) DeepCopy() Action { ret := a