Archived
1
0
This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
migra/migra-cli/tests/common/mod.rs

32 lines
799 B
Rust
Raw Normal View History

2021-02-12 01:25:55 +03:00
pub use assert_cmd::prelude::*;
pub use predicates::str::contains;
pub use std::process::Command;
pub type TestResult = std::result::Result<(), Box<dyn std::error::Error>>;
pub const ROOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/");
pub fn path_to_file(file_name: &'static str) -> String {
ROOT_PATH.to_owned() + file_name
}
pub const DATABASE_URL_DEFAULT_ENV_NAME: &str = "DATABASE_URL";
pub const DATABASE_URL_ENV_VALUE: &str = "postgres://postgres:postgres@localhost:6000/migra_tests";
pub struct Env {
2021-02-13 23:47:35 +03:00
key: &'static str,
2021-02-12 01:25:55 +03:00
}
impl Env {
pub fn new(key: &'static str, value: &'static str) -> Self {
std::env::set_var(key, value);
Env { key }
}
}
impl Drop for Env {
fn drop(&mut self) {
std::env::remove_var(self.key);
}
}