Add matchers for RTCError, rename old matcher for RTCErrorOr.
Needed for testing in a follow-up CL. Using ToString rather than absl::StrCat because I want the name of the enum (e.g. "INVALID_MODIFICATION") as opposed to the enum value (int). Bug: none Change-Id: I45a925fad65395d1e6a886a9f787c2f360fb8604 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374343 Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43777}
This commit is contained in:
parent
860a13c6fd
commit
283a84d92a
@ -37,7 +37,41 @@ MATCHER_P(IsRtcOkAndHolds,
|
||||
return testing::ExplainMatchResult(matcher, arg.value(), result_listener);
|
||||
}
|
||||
|
||||
MATCHER_P2(IsRtcErrorWithMessage,
|
||||
MATCHER_P(IsRtcErrorWithType, error_type, ToString(error_type)) {
|
||||
if (arg.ok()) {
|
||||
*result_listener << "Expected " << ToString(error_type) << ", got OK.";
|
||||
return false;
|
||||
}
|
||||
if (arg.type() != error_type) {
|
||||
*result_listener << "Expected " << ToString(error_type) << ", got "
|
||||
<< ToString(arg.type());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MATCHER_P2(IsRtcErrorWithTypeAndMessage,
|
||||
error_type,
|
||||
message,
|
||||
ToString(error_type)) {
|
||||
if (arg.ok()) {
|
||||
*result_listener << "Expected " << ToString(error_type) << ", got OK.";
|
||||
return false;
|
||||
}
|
||||
if (arg.type() != error_type) {
|
||||
*result_listener << "Expected " << ToString(error_type) << ", got "
|
||||
<< ToString(arg.type());
|
||||
return false;
|
||||
}
|
||||
if (std::string(arg.message()) != message) {
|
||||
*result_listener << "Expected message \"" << message << "\", got \""
|
||||
<< arg.message() << "\"";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MATCHER_P2(IsRtcErrorOrWithMessage,
|
||||
error_matcher,
|
||||
message_matcher,
|
||||
"RtcErrorOr that is holding an error that " +
|
||||
|
||||
@ -54,7 +54,7 @@ TEST(WaitUntilTest, ReturnsErrorWhenTimeoutIsReached) {
|
||||
// flakiness.
|
||||
EXPECT_THAT(
|
||||
result,
|
||||
IsRtcErrorWithMessage(
|
||||
IsRtcErrorOrWithMessage(
|
||||
_, MatchesRegex(
|
||||
"Value of: counter\nExpected: is equal to 1\nActual: -\\d+")));
|
||||
}
|
||||
@ -71,7 +71,7 @@ TEST(WaitUntilTest, ErrorContainsMatcherExplanation) {
|
||||
// flakiness.
|
||||
EXPECT_THAT(
|
||||
result,
|
||||
IsRtcErrorWithMessage(
|
||||
IsRtcErrorOrWithMessage(
|
||||
_, MatchesRegex("Value of: counter\nExpected: \\(is > 0\\) and "
|
||||
"\\(is < 10\\)\nActual: -\\d+, which doesn't match "
|
||||
"\\(is > 0\\)")));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user