mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Report all errors when trying multiple matchers
This commit is contained in:
parent
e7e78a6754
commit
5e9b594826
@ -276,11 +276,18 @@ func MatchRoomSubscription(roomID string, matchers ...RoomMatcher) RespMatcher {
|
||||
if !ok {
|
||||
return fmt.Errorf("MatchRoomSubscription[%s]: want sub but it was missing", roomID)
|
||||
}
|
||||
errs := make([]error, 0, len(matchers))
|
||||
for _, m := range matchers {
|
||||
if err := m(room); err != nil {
|
||||
return fmt.Errorf("MatchRoomSubscription[%s]: %s", roomID, err)
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 1 {
|
||||
return fmt.Errorf("MatchRoomSubscription[%s]: %d errors:\n%w", roomID, len(errs), errors.Join(errs...))
|
||||
} else if len(errs) == 1 {
|
||||
return fmt.Errorf("MatchRoomSubscription[%s]: %w", roomID, errs[0])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -755,13 +762,22 @@ const AnsiResetForeground = "\x1b[39m"
|
||||
|
||||
func MatchResponse(t *testing.T, res *sync3.Response, matchers ...RespMatcher) {
|
||||
t.Helper()
|
||||
errs := []error{}
|
||||
for _, m := range matchers {
|
||||
err := m(res)
|
||||
if err != nil {
|
||||
b, _ := json.MarshalIndent(res, "", " ")
|
||||
t.Errorf("%vMatchResponse: %s\n%s%v", AnsiRedForeground, err, string(b), AnsiResetForeground)
|
||||
errs = append(errs, fmt.Errorf("%v%s%v", AnsiRedForeground, err, AnsiResetForeground))
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
if len(errs) == 1 {
|
||||
t.Errorf("%vMatchResponse: %s", AnsiRedForeground, errs[0])
|
||||
} else {
|
||||
t.Errorf("%vMatchResponse: there were %d errors\n%s", AnsiRedForeground, len(errs), errors.Join(errs...))
|
||||
}
|
||||
LogResponse(t)(res)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckRoom(r sync3.Room, matchers ...RoomMatcher) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user