• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2015 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 <grpc/status.h>
20 
21 #include <memory>
22 
23 #include "absl/types/optional.h"
24 #include "gmock/gmock.h"
25 #include "gtest/gtest.h"
26 #include "src/core/util/time.h"
27 #include "test/core/end2end/end2end_tests.h"
28 
29 using testing::AnyOf;
30 using testing::StartsWith;
31 
32 namespace grpc_core {
33 namespace {
34 
CORE_END2END_TEST(CoreClientChannelTest,DefaultHost)35 CORE_END2END_TEST(CoreClientChannelTest, DefaultHost) {
36   auto c = NewClientCall("/foo").Timeout(Duration::Seconds(5)).Create();
37   EXPECT_NE(c.GetPeer(), absl::nullopt);
38   IncomingStatusOnClient server_status;
39   IncomingMetadata server_initial_metadata;
40   c.NewBatch(1)
41       .SendInitialMetadata({})
42       .SendCloseFromClient()
43       .RecvInitialMetadata(server_initial_metadata)
44       .RecvStatusOnClient(server_status);
45   auto s = RequestCall(101);
46   Expect(101, true);
47   Step();
48   EXPECT_NE(s.GetPeer(), absl::nullopt);
49   EXPECT_NE(c.GetPeer(), absl::nullopt);
50   IncomingCloseOnServer client_close;
51   s.NewBatch(102)
52       .SendInitialMetadata({})
53       .SendStatusFromServer(GRPC_STATUS_UNIMPLEMENTED, "xyz", {})
54       .RecvCloseOnServer(client_close);
55   Expect(102, true);
56   Expect(1, true);
57   Step();
58   EXPECT_EQ(server_status.status(), GRPC_STATUS_UNIMPLEMENTED);
59   EXPECT_EQ(server_status.message(), "xyz");
60   EXPECT_EQ(s.method(), "/foo");
61   if (GetParam()->overridden_call_host != nullptr) {
62     EXPECT_EQ(GetParam()->overridden_call_host, s.host());
63   } else {
64     EXPECT_THAT(s.host(),
65                 AnyOf(StartsWith("localhost"), StartsWith("127.0.0.1"),
66                       StartsWith("[::1]"), StartsWith("grpc_fullstack_test."),
67                       StartsWith("tmp%2Fgrpc_fullstack_test."),
68                       StartsWith("C:%2Ftmp%2Fgrpc_fullstack_test.")));
69   }
70   EXPECT_FALSE(client_close.was_cancelled());
71 }
72 
73 }  // namespace
74 }  // namespace grpc_core
75