iQIcBAABCgAGBQJWnR7yAAoJEN1O030MrHbien4P/2ixFj7HRpWLZDARUTOy1f0I

E/WY5FhCD5Nx2EAu1urJhZORwAeOyJurQVjoSC8FfcayK87Co3Hw9bt9CDB5uIxt
 aQlkA5YkamSlL1FQlOmcEqBUBISGmRtXB89zWeDWscRTrHb9pAPFZmrKpnklfa5r
 Lye3dAT7yrpTsPp2HxY2ojw5qHRb5Ojp57SKvAX27bYyEjk8PIREC2ZIgk08Mw1h
 kmx2QsIvWKGGTkOoBj/Lw+rL1aW+b6E6VdVngeZ04l9qU+3JOtHUkFyfvaiJvf7V
 0HDiQIEHDjLCeZwvjVgzxBxQE/pANpMtno6y3LF99FdgfQtQy6hswaUpMilk2N9X
 Mq+kZ1bWaz6Q2Oo3GSFhWeAOgM/en1MHuxRQhjUMZVxp1tsqLo3piq5Ywi1kg/yR
 Dsxvw/AmQbkV8S77RhbIN+aRbSg6kBs6QmaAy4fVB4f+fnp6WKHIZ4yselZMtwUI
 AHVsXCvlQwmDm4BG4khJfKEd36x9hJAWnpKkNCprGhedN8QRgV7GmHZ4b3LBtODB
 UI338SX6ZyZmnYQV3mNgJ5mvzffnjZF0xup5rMLOg3SyNjKoirjYdlbb2SH7tNLp
 +EwBIJGCaFbiVFRoh1iHTvxtbKj218NPjP6ZU+UowBM5mlysRpVtCAYVGPprl+u7
 aOtLp8WQDjnf8ysBL5pk
 =ZLhc
 -----END PGP SIGNATURE-----

Use tempdir in tests
This commit is contained in:
Marcel Müller 2016-01-18 18:20:50 +01:00
parent 6a3429d759
commit 9d0afade98
3 changed files with 49 additions and 8 deletions

View file

@ -3,9 +3,19 @@ name = "libimagstore"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"fs2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "advapi32-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "fs2" name = "fs2"
version = "0.2.2" version = "0.2.2"
@ -30,11 +40,29 @@ name = "libc"
version = "0.2.4" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-serialize" name = "rustc-serialize"
version = "0.3.16" version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tempdir"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.1.25" version = "0.1.25"

View file

@ -83,25 +83,37 @@ mod test {
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::PathBuf; use std::path::PathBuf;
use std::fs::File; use std::fs::File;
use tempdir::TempDir;
fn get_dir() -> TempDir {
TempDir::new("test-image").unwrap()
}
#[test] #[test]
fn lazy_file() { fn lazy_file() {
let path = PathBuf::from("/tmp/test"); let dir = get_dir();
let mut path = PathBuf::from(dir.path());
path.set_file_name("test1");
let mut lf = LazyFile::new(path); let mut lf = LazyFile::new(path);
write!(lf.create_file().unwrap(), "Hello World").unwrap(); write!(lf.create_file().unwrap(), "Hello World").unwrap();
dir.close().unwrap();
} }
#[test] #[test]
fn lazy_file_with_file() { fn lazy_file_with_file() {
let path = PathBuf::from("/tmp/test2"); let dir = get_dir();
let mut lf = LazyFile::new_with_file(File::create(path).unwrap()); let mut path = PathBuf::from(dir.path());
let mut file = lf.get_file_mut().unwrap(); path.set_file_name("test2");
let mut lf = LazyFile::new(path);
let mut file = lf.create_file().unwrap();
write!(file, "Hello World").unwrap(); file.write(b"Hello World").unwrap();
file.sync_all().unwrap(); file.sync_all().unwrap();
let mut s = String::new(); let mut s = Vec::new();
file.read_to_string(&mut s).unwrap(); file.read_to_end(&mut s).unwrap();
assert_eq!(s, "Hello World"); assert_eq!(s, "Hello World".to_string().into_bytes());
dir.close().unwrap();
} }
} }

View file

@ -1,5 +1,6 @@
extern crate fs2; extern crate fs2;
extern crate toml; extern crate toml;
extern crate tempdir;
pub mod content; pub mod content;
pub mod entry; pub mod entry;