-
Notifications
You must be signed in to change notification settings - Fork 4.1k
util/must: convenience wrapper for making many assertions #107418
Copy link
Copy link
Closed
Labels
A-testingTesting tools and infrastructureTesting tools and infrastructureC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-testengTestEng TeamTestEng Team
Description
See #106508.
It's common to execute many assertions at once, see e.g. storage.assertMVCCIteratorInvariants(). Returning errors from each individual assertion can get tedious and clutter the code. It would be convenient to run many assertions in a block, if we can do so efficiently.
Here's an example of how this might look:
err := must.With(ctx, func(m *must.Must) {
m.True(true, "yep")
m.False(false, "again")
value, err := someFunc()
m.NoError(err, "someFunc failed")
m.Equal(value, "foo", "someFunc returned invalid value")
})This would be implemented by throwing panics on assertion failures, and recovering the panic in must.With. A specific panic value would be thrown, wrapping the assertion error, and only this value would be recovered -- other panics would be propagated.
must.With itself would handle the assertion failure like any other assertion failure, i.e. fatal or propagate.
Jira issue: CRDB-30031
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-testingTesting tools and infrastructureTesting tools and infrastructureC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-testengTestEng TeamTestEng Team