axum_test/transport.rs
1use std::net::IpAddr;
2
3/// Transport is for setting which transport mode for the `TestServer`
4/// to use when making requests.
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
6pub enum Transport {
7 /// With this transport mode, `TestRequest` will use a mock HTTP
8 /// transport.
9 ///
10 /// This is the Default Transport type.
11 MockHttp,
12
13 /// With this transport mode, a real web server will be spun up
14 /// running on a random port. Requests made using the `TestRequest`
15 /// will be made over the network stack.
16 HttpRandomPort,
17
18 /// With this transport mode, a real web server will be spun up.
19 /// Where you can pick which IP and Port to use for this to bind to.
20 ///
21 /// Setting both `ip` and `port` to `None`, is the equivalent of
22 /// using `Transport::HttpRandomPort`.
23 HttpIpPort {
24 /// Set the IP to use for the server.
25 ///
26 /// **Defaults** to `127.0.0.1`.
27 ip: Option<IpAddr>,
28
29 /// Set the port number to use for the server.
30 ///
31 /// **Defaults** to a _random_ port.
32 port: Option<u16>,
33 },
34}
35
36impl Default for Transport {
37 fn default() -> Self {
38 Self::MockHttp
39 }
40}