tokio-rs / tokio-service

The core `Service` trait in Tokio and support
Apache License 2.0
82 stars 19 forks source link

Add example for testing #20

Closed sholsapp closed 7 years ago

sholsapp commented 7 years ago

Hey there, I'm curious what pattern I should employ to write unit tests for services and cannot find any examples here or elsewhere. Can someone point me at an example?

carllerche commented 7 years ago

You can call the service in a unit test. It returns a future, and you can probably call wait on the future. I'm not sure what specifically you are asking :)

sholsapp commented 7 years ago

In my brain, I was thinking I would write a unit test that has something like:

    info!("Serving on {}...", addr);
    TcpServer::new(Http, addr)
        .serve(move || Ok(server::MyService {}));

This starts an entire TCP server though. You're saying within a unit test, just instantiate the service and test that directly, yea? That makes sense, duh.

Either way, one or two unit tests would've make this even more bone head. :)