-
Notifications
You must be signed in to change notification settings - Fork 280
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
Enhance RestLayerPrivilegesEvaluator Code Coverage #3218
Enhance RestLayerPrivilegesEvaluator Code Coverage #3218
Conversation
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If code cov says that there is a no change, are you sure these tests are executed and their coverage data submitted? Do you see these tests executed from the artifacts of the check runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not look like it ran. I am not sure how to fix that though. I don't think it is something related to this change--I triggered a re-run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scrawfor99 I think you need to call it RestPathMatchesTests.java
not RestPathMatchesTest.java
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is not only your case but others as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @willyborankin . I've got a change that will expect 100% code coverage in the tests (e.g. all test code should be executed) that should help us catch this kind of issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did the same mistake :-D. Here is PR: #3224. Lets see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, who knew. I will swap over the name.
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
|
This is the code coverage for the other It still labels a significant amount as uncovered. I am not sure what is expected here however, as the way to exercise the files is to extract the internal method logic into separate functions so we can provide good and bad inputs and test the handling. |
In RestLayerPrivilegesEvaluator there was a number of unused parameters removed those to trim down the test requirements. For the test cases switched to assertThat for easy of reading, enabled debug logging to exercise debug logging code, adjusted usages of mocks for cleaner test flow in a couple of spaces. Verified locally with the following command and then checked the jacoco report under build/reports/jacoco/test/html/... ./gradlew jacocoTestReport test --tests \ org.opensearch.security.privileges.RestLayerPrivilegesEvaluatorTest Signed-off-by: Peter Nied <petern@amazon.com>
…erage Signed-off-by: Peter Nied <petern@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a pull request for your fork that reduces the product code, adds more assertions, and gets more coverage, take a look and see if you'd like to include it with PR
Increase coverage target
Codecov Report
@@ Coverage Diff @@
## main #3218 +/- ##
============================================
+ Coverage 62.43% 62.45% +0.01%
+ Complexity 3352 3351 -1
============================================
Files 254 254
Lines 19748 19743 -5
Branches 3334 3334
============================================
Hits 12330 12330
+ Misses 5789 5785 -4
+ Partials 1629 1628 -1
|
src/test/java/org/opensearch/security/privileges/RestLayerPrivilegesEvaluatorTest.java
Show resolved
Hide resolved
src/test/java/org/opensearch/security/privileges/RestLayerPrivilegesEvaluatorTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Cleans up RestLayerPrivilegesEvaluatorTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @scrawfor99 !
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/security/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/security/backport-2.x
# Create a new branch
git switch --create backport/backport-3218-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 46dfd841abeae193075d8cf95dd4023e9ea71ef9
# Push it to GitHub
git push --set-upstream origin backport/backport-3218-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/security/backport-2.x Then, create a pull request where the |
…t#3218) Enhance RestLayerPrivilegesEvaluator Code Coverage Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Peter Nied <petern@amazon.com> Signed-off-by: Darshit Chanpura <dchanp@amazon.com> Co-authored-by: Peter Nied <petern@amazon.com> Co-authored-by: Darshit Chanpura <dchanp@amazon.com> (cherry picked from commit 46dfd84)
Backported in #2956 as that is the parent change for this PR. |
Description
RestLayerPrivilegesEvaluator
is expected to have 100% code coverage. This change should boost the coverage as high as is reasonable. Per this comment: #2929 (comment), I am not adding tests for debug logs.Issues Resolved
Resolves #2929
Check List
New functionality has been documentedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.