Skip to content

Commit ff09f3a

Browse files
authored
test(bigtable): split instance admin test in two (#8057)
1 parent 5a64d31 commit ff09f3a

File tree

4 files changed

+137
-88
lines changed

4 files changed

+137
-88
lines changed

google/cloud/bigtable/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ if (BUILD_TESTING)
304304
iam_policy_test.cc
305305
idempotent_mutation_policy_test.cc
306306
instance_admin_client_test.cc
307+
instance_admin_new_test.cc
307308
instance_admin_test.cc
308309
instance_config_test.cc
309310
instance_update_config_test.cc

google/cloud/bigtable/bigtable_client_unit_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bigtable_client_unit_tests = [
3434
"iam_policy_test.cc",
3535
"idempotent_mutation_policy_test.cc",
3636
"instance_admin_client_test.cc",
37+
"instance_admin_new_test.cc",
3738
"instance_admin_test.cc",
3839
"instance_config_test.cc",
3940
"instance_update_config_test.cc",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

Comments
 (0)