diff options
Diffstat (limited to 'tests/unix.rs')
| -rw-r--r-- | tests/unix.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unix.rs b/tests/unix.rs new file mode 100644 index 0000000..bfa5a69 --- /dev/null +++ b/tests/unix.rs | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #[tokio::test] | ||
| 2 | async fn test_hello_service() { | ||
| 3 | #[urpc::service] | ||
| 4 | trait Hello { | ||
| 5 | type Error = (); | ||
| 6 | |||
| 7 | async fn hello(name: String) -> String; | ||
| 8 | } | ||
| 9 | |||
| 10 | struct HelloServer; | ||
| 11 | |||
| 12 | impl Hello for HelloServer { | ||
| 13 | async fn hello(&self, _ctx: urpc::Context, name: String) -> Result<String, ()> { | ||
| 14 | Ok(format!("Hello, {name}!")) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | let listener = urpc::unix::bind("./hello.service").await.unwrap(); | ||
| 19 | |||
| 20 | // spawn the server | ||
| 21 | tokio::spawn(async move { | ||
| 22 | urpc::Server::default() | ||
| 23 | .with_listener(listener) | ||
| 24 | .with_service(HelloServer.into_service()) | ||
| 25 | .serve() | ||
| 26 | .await | ||
| 27 | }); | ||
| 28 | |||
| 29 | // create a client | ||
| 30 | let channel = urpc::ClientChannel::new(urpc::unix::connect("./hello.service").await.unwrap()); | ||
| 31 | let client = HelloClient::new(channel); | ||
| 32 | let greeting = client.hello("World".into()).await.unwrap(); | ||
| 33 | assert_eq!(greeting, "Hello, World!"); | ||
| 34 | } | ||
