|
| 1 | +// Copyright 2022 Google Inc. |
| 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 | +// https://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 | +#include "google/cloud/bigtable/instance_admin.h" |
| 16 | +#include "google/cloud/bigtable/testing/mock_instance_admin_client.h" |
| 17 | +#include <gmock/gmock.h> |
| 18 | + |
| 19 | +namespace google { |
| 20 | +namespace cloud { |
| 21 | +namespace bigtable { |
| 22 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 23 | +namespace { |
| 24 | + |
| 25 | +using ::testing::ReturnRef; |
| 26 | + |
| 27 | +using MockAdminClient = |
| 28 | + ::google::cloud::bigtable::testing::MockInstanceAdminClient; |
| 29 | + |
| 30 | +std::string const kProjectId = "the-project"; |
| 31 | + |
| 32 | +/// A fixture for the bigtable::InstanceAdmin tests. |
| 33 | +class InstanceAdminTest : public ::testing::Test { |
| 34 | + protected: |
| 35 | + void SetUp() override { |
| 36 | + EXPECT_CALL(*client_, project()).WillRepeatedly(ReturnRef(kProjectId)); |
| 37 | + } |
| 38 | + |
| 39 | + std::shared_ptr<MockAdminClient> client_ = |
| 40 | + std::make_shared<MockAdminClient>(); |
| 41 | +}; |
| 42 | + |
| 43 | +/// @test Verify basic functionality in the `bigtable::InstanceAdmin` class. |
| 44 | +TEST_F(InstanceAdminTest, Default) { |
| 45 | + InstanceAdmin tested(client_); |
| 46 | + EXPECT_EQ("the-project", tested.project_id()); |
| 47 | +} |
| 48 | + |
| 49 | +TEST_F(InstanceAdminTest, CopyConstructor) { |
| 50 | + InstanceAdmin source(client_); |
| 51 | + std::string const& expected = source.project_id(); |
| 52 | + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) |
| 53 | + InstanceAdmin copy(source); |
| 54 | + EXPECT_EQ(expected, copy.project_id()); |
| 55 | +} |
| 56 | + |
| 57 | +TEST_F(InstanceAdminTest, MoveConstructor) { |
| 58 | + InstanceAdmin source(client_); |
| 59 | + std::string expected = source.project_id(); |
| 60 | + InstanceAdmin copy(std::move(source)); |
| 61 | + EXPECT_EQ(expected, copy.project_id()); |
| 62 | +} |
| 63 | + |
| 64 | +TEST_F(InstanceAdminTest, CopyAssignment) { |
| 65 | + std::shared_ptr<MockAdminClient> other_client = |
| 66 | + std::make_shared<MockAdminClient>(); |
| 67 | + std::string other_project = "other-project"; |
| 68 | + EXPECT_CALL(*other_client, project()) |
| 69 | + .WillRepeatedly(ReturnRef(other_project)); |
| 70 | + |
| 71 | + InstanceAdmin source(client_); |
| 72 | + std::string const& expected = source.project_id(); |
| 73 | + InstanceAdmin dest(other_client); |
| 74 | + EXPECT_NE(expected, dest.project_id()); |
| 75 | + dest = source; |
| 76 | + EXPECT_EQ(expected, dest.project_id()); |
| 77 | +} |
| 78 | + |
| 79 | +TEST_F(InstanceAdminTest, MoveAssignment) { |
| 80 | + std::shared_ptr<MockAdminClient> other_client = |
| 81 | + std::make_shared<MockAdminClient>(); |
| 82 | + std::string other_project = "other-project"; |
| 83 | + EXPECT_CALL(*other_client, project()) |
| 84 | + .WillRepeatedly(ReturnRef(other_project)); |
| 85 | + |
| 86 | + InstanceAdmin source(client_); |
| 87 | + std::string expected = source.project_id(); |
| 88 | + InstanceAdmin dest(other_client); |
| 89 | + EXPECT_NE(expected, dest.project_id()); |
| 90 | + dest = std::move(source); |
| 91 | + EXPECT_EQ(expected, dest.project_id()); |
| 92 | +} |
| 93 | + |
| 94 | +} // namespace |
| 95 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 96 | +} // namespace bigtable |
| 97 | +} // namespace cloud |
| 98 | +} // namespace google |
0 commit comments