Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
matchers.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_SPANNER_GOOGLE_CLOUD_SPANNER_TESTING_MATCHERS_H_
16 #define GOOGLE_CLOUD_CPP_SPANNER_GOOGLE_CLOUD_SPANNER_TESTING_MATCHERS_H_
17 
18 #include "google/cloud/spanner/internal/session_holder.h"
21 #include <google/protobuf/util/message_differencer.h>
22 #include <gmock/gmock.h>
23 #include <cstdint>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner_testing {
28 inline namespace SPANNER_CLIENT_NS {
29 
30 MATCHER_P(IsProtoEqual, value, "") {
31  std::string delta;
32  google::protobuf::util::MessageDifferencer differencer;
33  differencer.ReportDifferencesToString(&delta);
34  auto const result = differencer.Compare(arg, value);
35  *result_listener << "\n" << delta;
36  return result;
37 }
38 
41  HasSessionAndTransactionId, session_id, transaction_id,
42  "Verifies a Transaction has the expected Session and Transaction IDs") {
43  return google::cloud::spanner::internal::Visit(
44  arg, [&](google::cloud::spanner::internal::SessionHolder& session,
45  google::spanner::v1::TransactionSelector& s, std::int64_t) {
46  bool result = true;
47  if (session.session_name() != session_id) {
48  *result_listener << "Session ID mismatch: " << session.session_name()
49  << " != " << session_id;
50  result = false;
51  }
52  if (s.id() != transaction_id) {
53  *result_listener << "Transaction ID mismatch: " << s.id()
54  << " != " << transaction_id;
55  result = false;
56  }
57  return result;
58  });
59 }
60 
61 } // namespace SPANNER_CLIENT_NS
62 } // namespace spanner_testing
63 } // namespace cloud
64 } // namespace google
65 
66 #endif // GOOGLE_CLOUD_CPP_SPANNER_GOOGLE_CLOUD_SPANNER_TESTING_MATCHERS_H_
MATCHER_P(IsProtoEqual, value, "")
Definition: matchers.h:30
MATCHER_P2(HasSessionAndTransactionId, session_id, transaction_id, "Verifies a Transaction has the expected Session and Transaction IDs")
Verifies a Transaction has the expected Session and Transaction IDs.
Definition: matchers.h:40
#define SPANNER_CLIENT_NS
Definition: version.h:22