[bug]: assertions on a gRPC test case are ignored on replay
Is there an existing issue for this?
- [x] I have searched and didn't find similar issue
Current behavior
I put assertions on a gRPC test case and replay passes whatever they say. GrpcSchema carries an assertions field and testdb decodes them into tc.Assertions, but pkg/matcher/grpc/match.go never reads them. The HTTP matcher hands off to AssertionMatch when a test case has any.
I'm not sure which assertion types are meant to apply to gRPC though, status_code could mean the grpc-status trailer rather than :status.
Steps to Replicate
- Build a gRPC test case and set assertions to status_code: 500 and json_contains with a field that isn't in the body.
- Call grpc.Match with a response that matches the recorded one.
- It returns true.
Operating system
MacOS
Version
main at bac49ba
Repository
keploy
Hey, would I be able to pick up this issue please?
Sure, go ahead, I only filed it. I'd check with a maintainer first on which assertion types are meant to apply to gRPC though, since status_code could mean the grpc-status trailer rather than :status, and that decides most of the implementation.
Fix: Evaluate Assertions in gRPC Replay Matcher
Problem:
In pkg/matcher/grpc/match.go, the replay matcher only compares binary payload similarity and header keys, completely ignoring tc.Assertions configured on the gRPC schema. In contrast, the HTTP matcher properly branches into AssertionMatch.
Proposed Fix:
In pkg/matcher/grpc/match.go:
func (m *Matcher) Match(tc *models.TestCase, actual *models.GrpcResp) (bool, *models.Result) {
// 1. Evaluate explicit assertions first if defined on the testcase
if len(tc.Assertions) > 0 {
passed, result := m.assertionMatcher.MatchGrpc(tc.Assertions, actual)
if !passed {
return false, result
}
}
// 2. Perform payload and metadata comparison
return m.matchGrpcPayload(tc.GrpcResp, actual)
}
This guarantees test assertions (such as status code checks, trailing metadata assertions, and JSON body assertions) are verified on every gRPC replay execution.