@@ -19,6 +19,8 @@ using testing::NiceMock;
19
19
using testing::Return;
20
20
using testing::ReturnRef;
21
21
22
+ using Envoy::Protobuf::util::MessageDifferencer;
23
+
22
24
namespace Envoy {
23
25
namespace Extensions {
24
26
namespace HttpFilters {
@@ -501,9 +503,7 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, OKResponse) {
501
503
{" content-type" , " application/grpc" }};
502
504
EXPECT_EQ (Http::FilterHeadersStatus::StopIteration, filter_.decodeHeaders (req_headers, false ));
503
505
504
- std::string book_str = " {\" id\" :123,\" author\" :\" John Doe\" ,\" title\" :\" A Book\" }" ;
505
- Buffer::OwnedImpl buffer;
506
- buffer.add (book_str);
506
+ Buffer::OwnedImpl buffer{" {\" id\" :123,\" author\" :\" John Doe\" ,\" title\" :\" A Book\" }" };
507
507
508
508
Http::TestResponseTrailerMapImpl trailers;
509
509
EXPECT_CALL (encoder_callbacks_, addEncodedTrailers ()).WillOnce (ReturnRef (trailers));
@@ -514,12 +514,20 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, OKResponse) {
514
514
EXPECT_EQ (Http::FilterHeadersStatus::Continue, filter_.encodeHeaders (res_headers, false ));
515
515
516
516
EXPECT_EQ (Http::FilterDataStatus::Continue, filter_.encodeData (buffer, true ));
517
+
518
+ bookstore::Book expected_book;
519
+ expected_book.set_id (123 );
520
+ expected_book.set_author (" John Doe" );
521
+ expected_book.set_title (" A Book" );
522
+
523
+ Grpc::Decoder decoder;
524
+ std::vector<Grpc::Frame> frames;
525
+ std::ignore = decoder.decode (buffer, frames);
526
+
517
527
bookstore::Book book;
518
- book.set_id (123 );
519
- book.set_author (" John Doe" );
520
- book.set_title (" A Book" );
521
- auto book_buffer = Grpc::Common::serializeToGrpcFrame (book);
522
- EXPECT_EQ (buffer.toString (), book_buffer.get ()->toString ());
528
+ book.ParseFromString (frames[0 ].data_ ->toString ());
529
+
530
+ EXPECT_TRUE (MessageDifferencer::Equals (expected_book, book));
523
531
EXPECT_EQ (trailers.getGrpcStatusValue (), " 0" ); // OK
524
532
}
525
533
@@ -530,18 +538,23 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, OKResponseWithTrailer) {
530
538
{" content-type" , " application/grpc" }};
531
539
EXPECT_EQ (Http::FilterHeadersStatus::StopIteration, filter_.decodeHeaders (req_headers, false ));
532
540
533
- std::string book_str = " {\" id\" :123,\" author\" :\" John Doe\" ,\" title\" :\" A Book\" }" ;
534
- Buffer::OwnedImpl buffer;
535
- buffer.add (book_str);
541
+ Buffer::OwnedImpl buffer{" {\" id\" :123,\" author\" :\" John Doe\" ,\" title\" :\" A Book\" }" };
536
542
537
543
EXPECT_CALL (encoder_callbacks_, addEncodedData (_, _))
538
544
.WillOnce (Invoke ([](Buffer::Instance& data, bool ) {
545
+ bookstore::Book expected_book;
546
+ expected_book.set_id (123 );
547
+ expected_book.set_author (" John Doe" );
548
+ expected_book.set_title (" A Book" );
549
+
550
+ Grpc::Decoder decoder;
551
+ std::vector<Grpc::Frame> frames;
552
+ std::ignore = decoder.decode (data, frames);
553
+
539
554
bookstore::Book book;
540
- book.set_id (123 );
541
- book.set_author (" John Doe" );
542
- book.set_title (" A Book" );
543
- auto book_buffer = Grpc::Common::serializeToGrpcFrame (book);
544
- EXPECT_EQ (data.toString (), book_buffer.get ()->toString ());
555
+ book.ParseFromString (frames[0 ].data_ ->toString ());
556
+
557
+ EXPECT_TRUE (MessageDifferencer::Equals (expected_book, book));
545
558
}));
546
559
547
560
Http::TestResponseHeaderMapImpl res_headers{{" :status" , " 200" },
@@ -576,11 +589,18 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, OKHttpBodyResponse) {
576
589
577
590
EXPECT_EQ (Http::FilterDataStatus::Continue, filter_.encodeData (buffer, true ));
578
591
592
+ google::api::HttpBody expected_body;
593
+ expected_body.set_content_type (" application/json" );
594
+ expected_body.set_data (book_str);
595
+
596
+ Grpc::Decoder decoder;
597
+ std::vector<Grpc::Frame> frames;
598
+ std::ignore = decoder.decode (buffer, frames);
599
+
579
600
google::api::HttpBody body;
580
- body.set_content_type (" application/json" );
581
- body.set_data (book_str);
582
- auto body_buffer = Grpc::Common::serializeToGrpcFrame (body);
583
- EXPECT_EQ (buffer.toString (), body_buffer.get ()->toString ());
601
+ body.ParseFromString (frames[0 ].data_ ->toString ());
602
+
603
+ EXPECT_TRUE (MessageDifferencer::Equals (expected_body, body));
584
604
EXPECT_EQ (trailers.getGrpcStatusValue (), " 0" );
585
605
}
586
606
@@ -619,11 +639,18 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, OKHttpBodyResponseWithTrailer) {
619
639
620
640
EXPECT_CALL (encoder_callbacks_, addEncodedData (_, _))
621
641
.WillOnce (Invoke ([&book_str](Buffer::Instance& data, bool ) {
642
+ google::api::HttpBody expected_body;
643
+ expected_body.set_content_type (" application/json" );
644
+ expected_body.set_data (book_str);
645
+
646
+ Grpc::Decoder decoder;
647
+ std::vector<Grpc::Frame> frames;
648
+ std::ignore = decoder.decode (data, frames);
649
+
622
650
google::api::HttpBody body;
623
- body.set_content_type (" application/json" );
624
- body.set_data (book_str);
625
- auto body_buffer = Grpc::Common::serializeToGrpcFrame (body);
626
- EXPECT_EQ (data.toString (), body_buffer.get ()->toString ());
651
+ body.ParseFromString (frames[0 ].data_ ->toString ());
652
+
653
+ EXPECT_TRUE (MessageDifferencer::Equals (expected_body, body));
627
654
}));
628
655
629
656
Http::TestResponseHeaderMapImpl res_headers{{" :status" , " 200" },
@@ -715,7 +742,7 @@ TEST_F(GrpcJsonReverseTranscoderFilterTest, MiscEncodingAndDecoding) {
715
742
TEST_F (GrpcJsonReverseTranscoderFilterTest, ParseInvalidConfig) {
716
743
envoy::extensions::filters::http::grpc_json_reverse_transcoder::v3::GrpcJsonReverseTranscoder
717
744
config;
718
- config.set_descriptor_path (" test/proto/bookstore.proto" );
745
+ config.set_descriptor_path (TestEnvironment::runfilesPath ( " test/proto/bookstore.proto" ) );
719
746
EXPECT_THROW_WITH_MESSAGE (GrpcJsonReverseTranscoderConfig (config, *api_), EnvoyException,
720
747
" Unable to parse proto descriptor" );
721
748
}
0 commit comments