Testing is integral to smooth deployment. Kvarn is covered by many unit and integration tests. Using GitHub Actions, the whole codebase is linted and tested for every change.
It is available at crates.io.
Application testing
If you’re an author of an application powered by Kvarn and want to test it, you’ve come to the right place.
Below is an example of a production test. Unit tests are naturally also supported, and look exactly the same.
Cargo.toml
:
# add the following to the bottom (or add to you dev-dependencies if you already have that section)
[dev-dependencies]
tokio = { version = "1", features = ["net", "io-util", "macros"] }
# use the same version as the main Kvarn library
kvarn_testing = "0.4"
tests/byte_ranges.rs
:
use kvarn_testing::prelude::*;
static DATA: &str = "This is test data";
#[tokio::test]
async fn out_of_bounds() {
// Add an extension to the server
let server = ServerBuilder::default().with_extensions(|ext| {
ext.add_prepare_single(
"/index.html",
prepare!(_request, _host, _path, _addr, {
let bytes = Bytes::from_static(DATA.as_bytes());
FatResponse::cache(Response::new(bytes))
}),
);
});
// start the server (automatically chooses an available port)
let server = server.run().await;
// send GET request
let response = server
.get("/")
.header("range", "bytes=50-100")
.send()
.await
.unwrap();
assert_eq!(
response.status(),
reqwest::StatusCode::RANGE_NOT_SATISFIABLE
);
assert_eq!(
response.headers().get("reason").unwrap().to_str().unwrap(),
"Range start after end of body"
)
}
The documentation for the testing library can be found at doc.kvarn.org.