first integration test try
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
extern crate adduser;
|
||||
mod testfiles;
|
||||
|
||||
#[test]
|
||||
fn test_test() {
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
use std::{env, path::Path};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
struct Fixture {
|
||||
path: PathBuf,
|
||||
source: PathBuf,
|
||||
_tempdir: TempDir,
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
fn blank(fixture_filename: &str) -> Self {
|
||||
// First, figure out the right file in `tests/fixtures/`:
|
||||
let root_dir = &env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
|
||||
let mut source = PathBuf::from(root_dir);
|
||||
source.push("tests/fixtures");
|
||||
source.push(&fixture_filename);
|
||||
|
||||
// The "real" path of the file is going to be under a temporary directory:
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
let mut path = PathBuf::from(&tempdir.path());
|
||||
path.push(&fixture_filename);
|
||||
|
||||
Fixture {
|
||||
_tempdir: tempdir,
|
||||
source,
|
||||
path,
|
||||
}
|
||||
}
|
||||
fn copy(fixture_filename: &str) -> Self {
|
||||
let fixture = Fixture::blank(fixture_filename);
|
||||
fs::copy(&fixture.source, &fixture.path).unwrap();
|
||||
fixture
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Fixture {
|
||||
type Target = Path;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.path.deref()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user