pub struct TestContext { /* private fields */ }
Implementationsยง
Sourceยงimpl TestContext
impl TestContext
Sourcepub fn allow_http1(self, yes: bool) -> Self
pub fn allow_http1(self, yes: bool) -> Self
Allows HTTP/1 connections to be used. By disabling this, the ephermeral TCP listener wonโt know what to do unless HTTP/2 connections are allowed.
Sourcepub fn allows_both(&self) -> bool
pub fn allows_both(&self) -> bool
Checks whenever if the ephermeral TCP listener should allow both HTTP/1 and HTTP/2 connections.
Sourcepub fn server_addr(&self) -> Option<&SocketAddr>
pub fn server_addr(&self) -> Option<&SocketAddr>
Returns a optional reference to a socket address if TestContext::serve
was called
after this call.
ยงExample
let mut ctx = TestContext::default();
assert!(ctx.server_addr().is_none());
ctx.serve(axum::Router::new()).await;
assert!(ctx.server_addr().is_some());
Sourcepub fn request<U: AsRef<str> + 'static, B: Into<Option<Bytes>>, F: Fn(&mut Request<Full<Bytes>>)>(
&self,
uri: U,
method: Method,
body: B,
build: F,
) -> ResponseFuture
pub fn request<U: AsRef<str> + 'static, B: Into<Option<Bytes>>, F: Fn(&mut Request<Full<Bytes>>)>( &self, uri: U, method: Method, body: B, build: F, ) -> ResponseFuture
Sends a request to the ephemeral server and returns a ResponseFuture
.
ยงExample
async fn handler() -> &'static str {
"Hello, world!"
}
let mut ctx = TestContext::default();
ctx.serve(axum::Router::new().route("/", routing::get(handler))).await;
let res = ctx
.request("/", Method::GET, None, charted_testkit::noop_request)
.await
.expect("was unable to send request to ephermeral server");
charted_testkit::assert_successful!(res);
assert_eq!(charted_testkit::consume_body!(res), Bytes::from_static(b"Hello, world!"));
Trait Implementationsยง
Sourceยงimpl Debug for TestContext
impl Debug for TestContext
Auto Trait Implementationsยง
impl Freeze for TestContext
impl !RefUnwindSafe for TestContext
impl Send for TestContext
impl Sync for TestContext
impl Unpin for TestContext
impl !UnwindSafe for TestContext
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more