-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: base64 encode details header (#345)
- Loading branch information
1 parent
68d2ab3
commit e683ffe
Showing
7 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "integration-tests" | ||
version = "0.1.0" | ||
authors = ["Lucio Franco <[email protected]>"] | ||
edition = "2018" | ||
publish = false | ||
license = "MIT" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tonic = { path = "../../tonic" } | ||
prost = "0.6" | ||
futures-util = "0.3" | ||
bytes = "0.5" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "0.2", features = ["macros", "rt-core", "tcp"] } | ||
|
||
[build-dependencies] | ||
tonic-build = { path = "../../tonic-build" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
tonic_build::compile_protos("proto/test.proto").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
|
||
package test; | ||
|
||
service Test { | ||
rpc UnaryCall(Input) returns (Output); | ||
} | ||
|
||
message Input {} | ||
message Output {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod pb { | ||
tonic::include_proto!("test"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use bytes::Bytes; | ||
use futures_util::FutureExt; | ||
use integration_tests::pb::{test_client, test_server, Input, Output}; | ||
use std::time::Duration; | ||
use tokio::sync::oneshot; | ||
use tonic::{transport::Server, Code, Request, Response, Status}; | ||
|
||
#[tokio::test] | ||
async fn status_with_details() { | ||
struct Svc; | ||
|
||
#[tonic::async_trait] | ||
impl test_server::Test for Svc { | ||
async fn unary_call(&self, _: Request<Input>) -> Result<Response<Output>, Status> { | ||
Err(Status::with_details( | ||
Code::ResourceExhausted, | ||
"Too many requests", | ||
Bytes::from_static(&[1]), | ||
)) | ||
} | ||
} | ||
|
||
let svc = test_server::TestServer::new(Svc); | ||
|
||
let (tx, rx) = oneshot::channel::<()>(); | ||
|
||
let jh = tokio::spawn(async move { | ||
Server::builder() | ||
.add_service(svc) | ||
.serve_with_shutdown("127.0.0.1:1337".parse().unwrap(), rx.map(drop)) | ||
.await | ||
.unwrap(); | ||
}); | ||
|
||
tokio::time::delay_for(Duration::from_millis(100)).await; | ||
|
||
let mut channel = test_client::TestClient::connect("http://127.0.0.1:1337") | ||
.await | ||
.unwrap(); | ||
|
||
let err = channel | ||
.unary_call(Request::new(Input {})) | ||
.await | ||
.unwrap_err(); | ||
|
||
assert_eq!(err.message(), "Too many requests"); | ||
assert_eq!(err.details(), &[1]); | ||
|
||
tx.send(()).unwrap(); | ||
|
||
jh.await.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters