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