Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/test_common/status_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
namespace Envoy {
namespace StatusHelpers {

// Check that a StatusOr is OK and has a value equal to its argument.
// Check that a StatusOr is OK and has a value equal to or matching its argument.
//
// For example:
//
// StatusOr<int> status(3);
// EXPECT_THAT(status, IsOkAndHolds(3));
// EXPECT_THAT(status, IsOkAndHolds(Gt(2)));
MATCHER_P(IsOkAndHolds, expected, "") {
if (!arg.ok()) {
*result_listener << "which has unexpected status: " << arg.status();
return false;
}
if (*arg != expected) {
*result_listener << "which has wrong value: " << *arg;
if (!::testing::Matches(expected)(*arg)) {
*result_listener << "which has wrong value: " << ::testing::PrintToString(*arg);
return false;
}
return true;
Expand Down
11 changes: 10 additions & 1 deletion test/test_common/status_utility_test.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <sstream>

#include "test/test_common/status_utility.h"

namespace Envoy {
Expand Down Expand Up @@ -126,7 +128,14 @@ TEST(StatusUtilityTest, IsOkAndHoldsSuccess) {

TEST(StatusUtilityTest, IsOkAndHoldsFailureByValue) {
::testing::StringMatchResultListener listener;
::testing::ExplainMatchResult(IsOkAndHolds(5), absl::StatusOr<int>{6}, &listener);
EXPECT_FALSE(::testing::ExplainMatchResult(IsOkAndHolds(5), absl::StatusOr<int>{6}, &listener));
EXPECT_EQ("which has wrong value: 6", listener.str());
}

TEST(StatusUtilityTest, IsOkAndHoldsFailureByValueMatcher) {
::testing::StringMatchResultListener listener;
EXPECT_FALSE(::testing::ExplainMatchResult(IsOkAndHolds(::testing::Lt(4)), absl::StatusOr<int>{6},
&listener));
EXPECT_EQ("which has wrong value: 6", listener.str());
}

Expand Down