1 //
2 //
3 // Copyright 2021 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include "src/core/server/server_config_selector.h"
20
21 #include <grpc/grpc.h>
22
23 #include "absl/status/status.h"
24 #include "gtest/gtest.h"
25 #include "src/core/lib/channel/channel_args.h"
26 #include "test/core/test_util/test_config.h"
27
28 namespace grpc_core {
29 namespace testing {
30 namespace {
31
32 class TestServerConfigSelectorProvider : public ServerConfigSelectorProvider {
Watch(std::unique_ptr<ServerConfigSelectorWatcher>)33 absl::StatusOr<RefCountedPtr<ServerConfigSelector>> Watch(
34 std::unique_ptr<ServerConfigSelectorWatcher> /*watcher*/) override {
35 return absl::UnavailableError("Test ServerConfigSelector");
36 }
37
Orphaned()38 void Orphaned() override {}
39
CancelWatch()40 void CancelWatch() override {}
41 };
42
43 // Test that ServerConfigSelectorProvider can be safely copied to channel args
44 // and destroyed
TEST(ServerConfigSelectorProviderTest,CopyChannelArgs)45 TEST(ServerConfigSelectorProviderTest, CopyChannelArgs) {
46 RefCountedPtr<ServerConfigSelectorProvider> server_config_selector_provider =
47 MakeRefCounted<TestServerConfigSelectorProvider>();
48 auto args = ChannelArgs().SetObject(server_config_selector_provider);
49 EXPECT_EQ(server_config_selector_provider,
50 args.GetObject<ServerConfigSelectorProvider>());
51 }
52
53 // Test compare on channel args with the same ServerConfigSelectorProvider
TEST(ServerConfigSelectorProviderTest,ChannelArgsCompare)54 TEST(ServerConfigSelectorProviderTest, ChannelArgsCompare) {
55 auto server_config_selector_provider =
56 MakeRefCounted<TestServerConfigSelectorProvider>();
57 auto args = ChannelArgs().SetObject(server_config_selector_provider);
58 auto args2 = ChannelArgs().SetObject(server_config_selector_provider);
59 EXPECT_EQ(args, args2);
60 }
61
62 } // namespace
63 } // namespace testing
64 } // namespace grpc_core
65
main(int argc,char ** argv)66 int main(int argc, char** argv) {
67 ::testing::InitGoogleTest(&argc, argv);
68 grpc::testing::TestEnvironment env(&argc, argv);
69 grpc_init();
70 int ret = RUN_ALL_TESTS();
71 grpc_shutdown();
72 return ret;
73 }
74