Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GetElementByKey #3044

Merged
merged 1 commit into from
Sep 30, 2020

Conversation

Shell32-Natsu
Copy link
Contributor

for #3038

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Shell32-Natsu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Shell32-Natsu
Copy link
Contributor Author

/cc @monopole

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 28, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 28, 2020
@fejta-bot
Copy link

Unknown CLA label state. Rechecking for CLA labels.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/check-cla

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 29, 2020
@Shell32-Natsu Shell32-Natsu changed the title add element getter add GetElementByKey Sep 29, 2020
// NoValue indicates that matcher should only consider the key and ignore
// the actual value in the list. FieldValue must be empty when NoValue is
// set to true.
NoValue bool `yaml:"noValue,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name MatchAnyValue would be clearer here.

It's like using a wildcard * in the value.

Explicitly supporting wildcards or more general regexps could be the next step.

Any opinion on adding MatchAnyField?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, MatchAnyValue is better.

func GetElementByKey(key string) ElementMatcher {
return ElementMatcher{FieldName: key, NoValue: true}
}

// ElementMatcher returns the first element from a Sequence matching the
// specified field's value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// If there's no match, and no configuration error, the matcher returns nil, nil.


rn, err = node.Pipe(ElementMatcher{FieldName: "a"})
assert.NoError(t, err)
assert.Equal(t, "", assertNoErrorString(t)(rn.String()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L92 is meant to demonstrate a match failure for fieldValue "".

The documentation for type ElementMatcher struct doesn't actually specify
what is returned if there's no match- it's nil, but we should say so up above.

So L92 is technically correct, since (nil *RNode).String returns "" ,
but lets make it just

assert.Nil(t, rn)

assert.Equal(t, "f: g\n", assertNoErrorString(t)(rn.String()))
}

func TestElementMatcherWithNoValue(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, thanks for adding this. It covers all the bases (that's a baseball idiom).

Copy link
Contributor

@monopole monopole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit bb42d8a into kubernetes-sigs:master Sep 30, 2020
@Shell32-Natsu Shell32-Natsu deleted the element-getter branch October 1, 2020 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants