|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "google/cloud/bigtable/internal/query_plan.h" |
16 | | -#include "google/cloud/completion_queue.h" |
| 16 | +#include "google/cloud/testing_util/is_proto_equal.h" |
| 17 | +#include "google/cloud/testing_util/mock_completion_queue_impl.h" |
| 18 | +#include "google/cloud/testing_util/status_matchers.h" |
17 | 19 | #include <google/bigtable/v2/data.pb.h> |
| 20 | +#include <google/protobuf/text_format.h> |
| 21 | +#include <google/protobuf/util/time_util.h> |
18 | 22 | #include <gmock/gmock.h> |
| 23 | +#include <gtest/gtest.h> |
19 | 24 |
|
20 | 25 | namespace google { |
21 | 26 | namespace cloud { |
22 | 27 | namespace bigtable_internal { |
23 | 28 | GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
24 | 29 | namespace { |
25 | 30 |
|
26 | | -/// @test Basic test to confirm compilation and dummy behavior. |
27 | | -/// Remove this after implementing QueryPlan. |
28 | | -TEST(QueryPlanTest, TestDummyMethods) { |
29 | | - auto cq = CompletionQueue(); |
30 | | - auto response = google::bigtable::v2::PrepareQueryResponse(); |
31 | | - auto fn = QueryPlan::RefreshFn(); |
32 | | - auto created = QueryPlan::Create(cq, response, fn); |
33 | | - ASSERT_EQ("", (*created).prepared_query()); |
34 | | - ASSERT_EQ(0, created->metadata().ByteSizeLong()); |
| 31 | +using ::google::cloud::testing_util::IsProtoEqual; |
| 32 | +using ::google::cloud::testing_util::MockCompletionQueueImpl; |
| 33 | +using ::google::protobuf::util::TimeUtil; |
| 34 | + |
| 35 | +TEST(QueryPlanTest, Accessors) { |
| 36 | + auto mock_cq = std::make_shared<MockCompletionQueueImpl>(); |
| 37 | + CompletionQueue cq(mock_cq); |
| 38 | + google::bigtable::v2::PrepareQueryResponse response; |
| 39 | + response.set_prepared_query("test-query"); |
| 40 | + auto constexpr kResultMetadataText = R"pb( |
| 41 | + proto_schema { |
| 42 | + columns { |
| 43 | + name: "user_id" |
| 44 | + type { string_type {} } |
| 45 | + } |
| 46 | + } |
| 47 | + )pb"; |
| 48 | + google::bigtable::v2::ResultSetMetadata metadata; |
| 49 | + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(kResultMetadataText, |
| 50 | + &metadata)); |
| 51 | + *response.mutable_metadata() = metadata; |
| 52 | + *response.mutable_valid_until() = |
| 53 | + TimeUtil::GetCurrentTime() + TimeUtil::SecondsToDuration(300); |
| 54 | + |
| 55 | + auto plan = QueryPlan::Create(cq, response, [] { |
| 56 | + return google::bigtable::v2::PrepareQueryResponse{}; |
| 57 | + }); |
| 58 | + |
| 59 | + auto prepared_query = plan->prepared_query(); |
| 60 | + ASSERT_STATUS_OK(prepared_query); |
| 61 | + EXPECT_EQ(*prepared_query, "test-query"); |
| 62 | + auto actual_metadata = plan->metadata(); |
| 63 | + ASSERT_STATUS_OK(actual_metadata); |
| 64 | + EXPECT_THAT(*actual_metadata, IsProtoEqual(metadata)); |
35 | 65 | } |
36 | 66 |
|
37 | 67 | } // namespace |
|
0 commit comments