Crate xtest_data

Source
Expand description

Fetch test data in packaged crate tests.

§For crate authors

Drop these lines into your integration tests (due to a limitation in cargo this will only work in integration tests right now¹). Note that this requires your repository—through the URL contained in Cargo.toml—to be readable by the environment where you wish to test the packaged crate.

use std::path::PathBuf;

// or any other file you want to use.
let mut datazip = PathBuf::from("tests/data.zip");
xtest_data::setup!().rewrite([&mut datazip]).build();

// … and the crate works its magic to make this succeed.
assert!(datazip.exists(), "{}", datazip.display());

¹The crate uses a directory to store a shallow clone of the source repository. Only integration tests have the environment variable that cargo uses to communicate a temporary directory within its target folder. That temporary directory is required for our choice.

Configure meta data in your Cargo.toml according to the guide to inform packagers where they will find the test data. See the Readme in the sources for an example. When you’re ready to deploy, let the xtest-data binary pack all necessary data files from your source tree:

cargo xtest-data pack

Make sure to upload the archive according to your published configuration!

§For packagers

cargo install xtest-data --features=bin-xtask

Any .crate file you have downloaded is a .tar.gz in disguise. When you unpack it for your local build steps etc., you may verify that this package contains Cargo.toml.orig as well as a .cargo_vcs_info.json file; and that the latter file has git commit information.

The binary orchestrates fetching a shallow pack of the requested data sources from the upstream repository, or consuming one from your local filesystem if you rather do the networking yourself. The basic structure you want is:

cargo xtest-data test-crate /path/to/your.crate [--pack-artifact /path/to/pack-artifact]

Modules§

readme
Find the Readme and further documentation here, only present in the docs build. Fetch auxiliary test data when testing published crates.

Macros§

setup
Create a builder to configure local test data.

Structs§

Files
A file or tree that was registered from Setup.
FsData
The product of Setup, ensuring local file system accessible test resources.
Setup
A builder to configure desired test data paths.