comment cleanup
This commit is contained in:
parent
5182d96271
commit
7693b3a5d4
@ -236,8 +236,10 @@ type getOwnerIDAndNamer interface {
|
||||
// (PrincipalName for users, WebURL for sites).
|
||||
//
|
||||
// Consumers are allowed to pass in a path suffix (eg: /sites/foo) as a site
|
||||
// owner, but only if they also pass in a nameToID map. A nil map will cascade
|
||||
// to the fallback, which will fail for having a malformed id value.
|
||||
// owner, but only if they also pass in a nameToID map. A nil map will fallback
|
||||
// to a lookup by id using the suffix, which will fail for being malformed.
|
||||
// Suffix matching follows filter PathSuffix rules: only complete elements match,
|
||||
// case-independant, leading/tailing slashes are optional.
|
||||
func (r resourceClient) getOwnerIDAndNameFrom(
|
||||
ctx context.Context,
|
||||
discovery api.Client,
|
||||
@ -261,7 +263,7 @@ func (r resourceClient) getOwnerIDAndNameFrom(
|
||||
|
||||
// check if the provided owner is a suffix of a weburl in the lookup map
|
||||
if r.enum == Sites {
|
||||
url, _, ok := filters.PathSuffix([]string{owner}).CompareAny(ins.Names()...)
|
||||
url, ok := filters.PathSuffix([]string{owner}).CompareAny(ins.Names()...)
|
||||
if ok {
|
||||
id, _ := ins.IDOf(url)
|
||||
return id, url, nil
|
||||
|
||||
@ -360,22 +360,21 @@ func newSliceFilter(c comparator, targets, normTargets []string, negate bool) Fi
|
||||
|
||||
// CompareAny checks whether any one of all the provided
|
||||
// inputs passes the filter. If one passes, that value is
|
||||
// returned, as well as its index in the input range.
|
||||
// If nothing matches, returns ("", -1, false)
|
||||
// returned. If nothing matches, returns ("", false)
|
||||
//
|
||||
// Note that, as a gotcha, CompareAny can resolve truthily
|
||||
// for both the standard and negated versions of a filter.
|
||||
// Ex: consider the input CompareAny(true, false), which
|
||||
// will return true for both Equals(true) and NotEquals(true),
|
||||
// because at least one element matches for both filters.
|
||||
func (f Filter) CompareAny(inputs ...string) (string, int, bool) {
|
||||
for i, in := range inputs {
|
||||
func (f Filter) CompareAny(inputs ...string) (string, bool) {
|
||||
for _, in := range inputs {
|
||||
if f.Compare(in) {
|
||||
return in, i, true
|
||||
return in, true
|
||||
}
|
||||
}
|
||||
|
||||
return "", -1, false
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Compare checks whether the input passes the filter.
|
||||
|
||||
@ -79,14 +79,12 @@ func (suite *FiltersSuite) TestEquals_any() {
|
||||
suite.Run(test.name, func() {
|
||||
t := suite.T()
|
||||
|
||||
v, i, b := f.CompareAny(test.input...)
|
||||
v, b := f.CompareAny(test.input...)
|
||||
test.expectF(t, b, "filter")
|
||||
assert.Equal(t, test.expectFIdx, i, "index")
|
||||
assert.Equal(t, test.expectFVal, v, "value")
|
||||
|
||||
v, i, b = nf.CompareAny(test.input...)
|
||||
v, b = nf.CompareAny(test.input...)
|
||||
test.expectNF(t, b, "neg-filter")
|
||||
assert.Equal(t, test.expectNFIdx, i, "neg-index")
|
||||
assert.Equal(t, test.expectNFVal, v, "neg-value")
|
||||
})
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ func matchesAny[T scopeT, C categoryT](s T, cat C, inpts []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
_, _, pass := s[cat.String()].CompareAny(inpts...)
|
||||
_, pass := s[cat.String()].CompareAny(inpts...)
|
||||
|
||||
return pass
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user