• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ext/filters/server_config_selector/server_config_selector.h"
20 
21 #include "absl/status/status.h"
22 #include "gtest/gtest.h"
23 
24 #include <grpc/grpc.h>
25 
26 #include "src/core/lib/channel/channel_args.h"
27 #include "test/core/util/test_config.h"
28 
29 namespace grpc_core {
30 namespace testing {
31 namespace {
32 
33 class TestServerConfigSelectorProvider : public ServerConfigSelectorProvider {
Watch(std::unique_ptr<ServerConfigSelectorWatcher>)34   absl::StatusOr<RefCountedPtr<ServerConfigSelector>> Watch(
35       std::unique_ptr<ServerConfigSelectorWatcher> /*watcher*/) override {
36     return absl::UnavailableError("Test ServerConfigSelector");
37   }
38 
Orphaned()39   void Orphaned() override {}
40 
CancelWatch()41   void CancelWatch() override {}
42 };
43 
44 // Test that ServerConfigSelectorProvider can be safely copied to channel args
45 // and destroyed
TEST(ServerConfigSelectorProviderTest,CopyChannelArgs)46 TEST(ServerConfigSelectorProviderTest, CopyChannelArgs) {
47   RefCountedPtr<ServerConfigSelectorProvider> server_config_selector_provider =
48       MakeRefCounted<TestServerConfigSelectorProvider>();
49   auto args = ChannelArgs().SetObject(server_config_selector_provider);
50   EXPECT_EQ(server_config_selector_provider,
51             args.GetObject<ServerConfigSelectorProvider>());
52 }
53 
54 // Test compare on channel args with the same ServerConfigSelectorProvider
TEST(ServerConfigSelectorProviderTest,ChannelArgsCompare)55 TEST(ServerConfigSelectorProviderTest, ChannelArgsCompare) {
56   auto server_config_selector_provider =
57       MakeRefCounted<TestServerConfigSelectorProvider>();
58   auto args = ChannelArgs().SetObject(server_config_selector_provider);
59   auto args2 = ChannelArgs().SetObject(server_config_selector_provider);
60   EXPECT_EQ(args, args2);
61 }
62 
63 }  // namespace
64 }  // namespace testing
65 }  // namespace grpc_core
66 
main(int argc,char ** argv)67 int main(int argc, char** argv) {
68   ::testing::InitGoogleTest(&argc, argv);
69   grpc::testing::TestEnvironment env(&argc, argv);
70   grpc_init();
71   int ret = RUN_ALL_TESTS();
72   grpc_shutdown();
73   return ret;
74 }
75