aur-rs 0.1.1

Library for interacting with the Arch User Repository's RPC interface
Documentation
use std::fs;
use std::path::PathBuf;

// Common test utilities
use httpmock::prelude::*;

/// TestKit is a collection of common test utilities.
// Yes yes i'll get to adding fail cases soon!
pub struct TestKit {
    pub mock_server: MockServer,
    pub valid_search_json: String,
    pub valid_info_json: String,
    pub valid_suggest_json: String,
    pub valid_multi_info_json: String,
    pub valid_provides_json: String,
    pub valid_maintainer_json: String,
}

pub fn setup() -> TestKit {
    let server = MockServer::start();

    let resources_dir = format!("{}/resources/test", env!("CARGO_MANIFEST_DIR"));

    // Load JSON files that will be used to mock the server.  Currently
    // these are just static files, but in the future we may want to
    // generate them dynamically.
    //
    // Also the current two files are both valid.  I want to have a
    // solid positive foundation before i start trying to break things. :)
    let search_json = fs::read_to_string(PathBuf::from(format!(
        "{}/single_yay_bin_search.json",
        resources_dir
    )))
    .expect("Failed to read search JSON file");

    let info_json = fs::read_to_string(PathBuf::from(format!(
        "{}/single_yay_bin_info.json",
        resources_dir
    )))
    .expect("Failed to read info JSON file");

    let valid_suggest_json =
        fs::read_to_string(PathBuf::from(format!("{}/yay_suggest.json", resources_dir)))
            .expect("Failed to read info JSON file");

    let valid_multi_info_json = fs::read_to_string(PathBuf::from(format!(
        "{}/multi_yay_yay_bin.json",
        resources_dir
    )))
    .expect("Failed to read info JSON file");

    let valid_provides_json = fs::read_to_string(PathBuf::from(format!(
        "{}/search_provides_yay.json",
        resources_dir
    )))
    .expect("Failed to read info JSON file");

    let valid_maintainer_json = fs::read_to_string(PathBuf::from(format!(
        "{}/search_maintainer.json",
        resources_dir
    )))
    .expect("Failed to read info JSON file");

    TestKit {
        mock_server: server,
        valid_search_json: search_json,
        valid_info_json: info_json,
        valid_suggest_json: valid_suggest_json,
        valid_multi_info_json: valid_multi_info_json,
        valid_provides_json: valid_provides_json,
        valid_maintainer_json: valid_maintainer_json,
    }
}