pub struct TestServerConfig {
pub transport: Option<Transport>,
pub save_cookies: bool,
pub expect_success_by_default: bool,
pub restrict_requests_with_http_schema: bool,
pub default_content_type: Option<String>,
pub default_scheme: Option<String>,
}
Expand description
This is for customising the TestServer
on construction.
It implements Default
to ease building.
use axum_test::TestServerConfig;
let config = TestServerConfig {
save_cookies: true,
..TestServerConfig::default()
};
These can be passed to TestServer::new_with_config
:
use axum::Router;
use axum_test::TestServer;
use axum_test::TestServerConfig;
let my_app = Router::new();
let config = TestServerConfig {
save_cookies: true,
..TestServerConfig::default()
};
// Build the Test Server
let server = TestServer::new_with_config(my_app, config)?;
Fields§
§transport: Option<Transport>
Which transport mode to use to process requests.
For setting if the server should use mocked http (which uses tower::util::Oneshot
),
or if it should run on a named or random IP address.
The default is to use mocking, apart from services built using axum::extract::connect_info::IntoMakeServiceWithConnectInfo
(this is because it needs a real TCP stream).
Set for the server to save cookies that are returned, for use in future requests.
This is useful for automatically saving session cookies (and similar) like a browser would do.
Defaults to false (being turned off).
expect_success_by_default: bool
Asserts that requests made to the test server, will by default, return a status code in the 2xx range.
This can be overridden on a per request basis using
TestRequest::expect_failure()
.
This is useful when making multiple requests at a start of test which you presume should always work.
Defaults to false (being turned off).
restrict_requests_with_http_schema: bool
If you make a request with a ‘http://’ schema, then it will ignore the Test Server’s address.
For example if the test server is running at http://localhost:1234
,
and you make a request to http://google.com
.
Then the request will go to http://google.com
.
Ignoring the localhost:1234
part.
Turning this setting on will change this behaviour.
After turning this on, the same request will go to
http://localhost:1234/http://google.com
.
Defaults to false (being turned off).
default_content_type: Option<String>
Set the default content type for all requests created by the TestServer
.
This overrides the default ‘best efforts’ approach of requests.
default_scheme: Option<String>
Set the default scheme to use for all requests created by the TestServer
.
This overrides the default ‘http’.
Implementations§
Source§impl TestServerConfig
impl TestServerConfig
Sourcepub fn build<A>(self, app: A) -> Result<TestServer>where
A: IntoTransportLayer,
pub fn build<A>(self, app: A) -> Result<TestServer>where
A: IntoTransportLayer,
This is shorthand for calling crate::TestServer::new_with_config
,
and passing this config.
use axum::Router;
use axum_test::TestServer;
use axum_test::TestServerConfig;
let app = Router::new();
let config = TestServerConfig {
save_cookies: true,
default_content_type: Some("application/json".to_string()),
..Default::default()
};
let server = TestServer::new_with_config(app, config)?;
Trait Implementations§
Source§impl Clone for TestServerConfig
impl Clone for TestServerConfig
Source§fn clone(&self) -> TestServerConfig
fn clone(&self) -> TestServerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TestServerConfig
impl Debug for TestServerConfig
Source§impl Default for TestServerConfig
impl Default for TestServerConfig
Source§impl From<TestServerBuilder> for TestServerConfig
impl From<TestServerBuilder> for TestServerConfig
Source§fn from(builder: TestServerBuilder) -> Self
fn from(builder: TestServerBuilder) -> Self
Source§impl From<TestServerConfig> for TestServerBuilder
impl From<TestServerConfig> for TestServerBuilder
Source§fn from(config: TestServerConfig) -> Self
fn from(config: TestServerConfig) -> Self
Source§impl PartialEq for TestServerConfig
impl PartialEq for TestServerConfig
impl Eq for TestServerConfig
impl StructuralPartialEq for TestServerConfig
Auto Trait Implementations§
impl Freeze for TestServerConfig
impl RefUnwindSafe for TestServerConfig
impl Send for TestServerConfig
impl Sync for TestServerConfig
impl Unpin for TestServerConfig
impl UnwindSafe for TestServerConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);