Crate test_assets_ureq

Crate test_assets_ureq 

Source
Expand description

Download test assets, managing them outside of git

This library downloads test assets using http(s), and ensures integrity by comparing those assets to a hash. By managing the download separately, you can keep them out of VCS and don’t make them bloat your repository.

Usage example:

#[test]
fn some_awesome_test() {
    let asset_defs = [
        TestAssetDef {
            filepath : format!("file_a.png"),
            hash : format!("<sha256 here>"),
            url : format!("https://url/to/a.png"),
        },
        TestAssetDef {
            filepath : format!("subdir/file_b.png"),
            hash : format!("<sha256 here>"),
            url : format!("https://url/to/b.png"),
        },
    ];
    test_assets::dl_test_files(&asset_defs, "test-assets").unwrap();
    // use your files here
    // with path under test-assets/file_a.png and test-assets/subdir/file_b.png
}

Optionally, a toml can also be used.

[test_assets.test_00]
filepath = "out.squashfs"
hash = "976c1638d8c1ba8014de6c64b196cbd70a5acf031be10a8e7f649536193c8e78"
url = "https://wcampbell.dev/squashfs/testing/test_00/out.squashfs"
use test_assets_ureq::{TestAsset, dl_test_files_backoff};
use std::fs;
use std::time::Duration;

let file_content = fs::read_to_string("test.toml").unwrap();
let parsed: TestAsset = toml::de::from_str(&file_content).unwrap();
let assets = parsed.values();
dl_test_files_backoff(&assets, "test-assets", Duration::from_secs(1)).unwrap();

If you have run the test once, it will re-use the files instead of re-downloading them.

Structs§

ProgressCallbacks
Callbacks for download progress and status updates
Sha256Hash
A type for a Sha256 hash value
TestAsset
TestAssetDef
Definition for a test file

Enums§

TaError

Functions§

dl_test_files
Download test files
dl_test_files_backoff
Download test files with backoff retries
dl_test_files_backoff_with_progress
Download test-assets with backoff retries and progress callbacks
dl_test_files_with_progress
Downloads the test files into the passed directory with progress callbacks.