Skip to content

test: add unit tests for consistency/forcefull.go#2916

Merged
miparnisari merged 2 commits intoauthzed:mainfrom
ivanauth:fix/issue-2900-add-forcefull-tests
Mar 7, 2026
Merged

test: add unit tests for consistency/forcefull.go#2916
miparnisari merged 2 commits intoauthzed:mainfrom
ivanauth:fix/issue-2900-add-forcefull-tests

Conversation

@ivanauth
Copy link
Contributor

Fixes #2900

Adds 21 test cases covering all exported functions in pkg/middleware/consistency/forcefull.go: unary and stream interceptors, bypass whitelist, error propagation, and readonly error rewriting.

@ivanauth ivanauth requested a review from a team as a code owner February 20, 2026 19:18
@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Feb 20, 2026
@ivanauth ivanauth changed the title Add unit tests for consistency/forcefull.go test: add unit tests for consistency/forcefull.go Feb 20, 2026
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.74%. Comparing base (645d0e5) to head (261a0eb).
⚠️ Report is 1 commits behind head on main.

❌ Your project status has failed because the head coverage (74.74%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2916      +/-   ##
==========================================
+ Coverage   74.71%   74.74%   +0.03%     
==========================================
  Files         494      494              
  Lines       60623    60623              
==========================================
+ Hits        45290    45308      +18     
+ Misses      12169    12148      -21     
- Partials     3164     3167       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ds.AssertExpectations(t)
})

t.Run("returns nil for request without consistency interface", func(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.

there is nothing returning nil here. you should change the assertion - call RevisionFromContext and then assert that you got nothing back.

t.Run("returns nil for request without consistency interface", func(t *testing.T) {
t.Parallel()
ctx := ContextWithHandle(t.Context())
err := setFullConsistencyRevisionToContext(ctx, "not-a-consistency-request", nil, "", TreatMismatchingTokensAsFullConsistency)
Copy link
Contributor

Choose a reason for hiding this comment

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

you are passing a request without consistency, but you are also passing nil as the datastore. as a reader of this test, i have no proof that the result that you got back is because of the former and not because of the latter. please pass a valid ds.

resp, err := interceptor(
context.Background(),
&v1.ReadRelationshipsRequest{},
&grpc.UnaryServerInfo{FullMethod: "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo"},
Copy link
Contributor

Choose a reason for hiding this comment

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

@josephschorr could you explain why the ForceFull interceptors use the bypassServiceWhitelist? what is the point? none of the methods in those services will satisfy the hasConsistency check here

if _, ok := req.(hasConsistency); ok {
anyway. So it seems like we're just wasting CPU for no good reason.

Comment on lines +114 to +116
require.NoError(err)
require.Equal("response", resp)
require.True(handlerCalled)
Copy link
Contributor

Choose a reason for hiding this comment

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

these assertions don't show that the bypassServiceWhitelist is being used, right? you need to show that setFullConsistencyRevisionToContext didn't produce any side effects

@ivanauth
Copy link
Contributor Author

I addressed all the comments. Thank you.

@miparnisari
Copy link
Contributor

can you fix the compilation errors?

also, were you not able to use testpb.InterceptorTestSuite?

@ivanauth ivanauth force-pushed the fix/issue-2900-add-forcefull-tests branch from e8f727b to 0dbd233 Compare March 5, 2026 15:56
@ivanauth
Copy link
Contributor Author

ivanauth commented Mar 5, 2026

Fixed the compilation errors.

Also added testpb.InterceptorTestSuite tests.

@ivanauth ivanauth force-pushed the fix/issue-2900-add-forcefull-tests branch 3 times, most recently from bcfab08 to f3887fd Compare March 5, 2026 19:32
miparnisari
miparnisari previously approved these changes Mar 7, 2026
@miparnisari miparnisari enabled auto-merge (squash) March 7, 2026 00:29
@miparnisari miparnisari force-pushed the fix/issue-2900-add-forcefull-tests branch from 2fd1b6d to e299ceb Compare March 7, 2026 00:29
@miparnisari miparnisari force-pushed the fix/issue-2900-add-forcefull-tests branch from e299ceb to 10e0d29 Compare March 7, 2026 01:47
@miparnisari miparnisari force-pushed the fix/issue-2900-add-forcefull-tests branch from 10e0d29 to 261a0eb Compare March 7, 2026 01:57
@miparnisari miparnisari merged commit cf317c7 into authzed:main Mar 7, 2026
43 of 45 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) Skip-Changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit tests to consistency/forcefull.go

2 participants