1 // Copyright 2021 gRPC authors.
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 // http://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 <memory>
16
17 #include "gtest/gtest.h"
18
19 #include <grpc/event_engine/memory_allocator.h>
20 #include <grpc/status.h>
21
22 #include "src/core/lib/promise/poll.h"
23 #include "src/core/lib/promise/try_seq.h"
24 #include "src/core/lib/transport/metadata_batch.h"
25
26 namespace grpc_core {
27
28 struct TestMap : public MetadataMap<TestMap, GrpcStatusMetadata> {
29 using MetadataMap<TestMap, GrpcStatusMetadata>::MetadataMap;
30 };
31
TEST(PromiseTest,SucceedAndThenFail)32 TEST(PromiseTest, SucceedAndThenFail) {
33 Poll<TestMap> r = TrySeq(
34 [] {
35 TestMap m;
36 m.Set(GrpcStatusMetadata(), GRPC_STATUS_OK);
37 return m;
38 },
39 []() {
40 TestMap m;
41 m.Set(GrpcStatusMetadata(), GRPC_STATUS_UNAVAILABLE);
42 return m;
43 })();
44 EXPECT_EQ(r.value().get(GrpcStatusMetadata()), GRPC_STATUS_UNAVAILABLE);
45 }
46
47 } // namespace grpc_core
48
main(int argc,char ** argv)49 int main(int argc, char** argv) {
50 ::testing::InitGoogleTest(&argc, argv);
51 return RUN_ALL_TESTS();
52 }
53