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:
parent
6a3429d759
commit
9d0afade98
3 changed files with 49 additions and 8 deletions
28
libimagstore/Cargo.lock
generated
28
libimagstore/Cargo.lock
generated
|
@ -3,9 +3,19 @@ name = "libimagstore"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"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)",
|
||||
]
|
||||
|
||||
[[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]]
|
||||
name = "fs2"
|
||||
version = "0.2.2"
|
||||
|
@ -30,11 +40,29 @@ name = "libc"
|
|||
version = "0.2.4"
|
||||
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]]
|
||||
name = "rustc-serialize"
|
||||
version = "0.3.16"
|
||||
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]]
|
||||
name = "toml"
|
||||
version = "0.1.25"
|
||||
|
|
|
@ -83,25 +83,37 @@ mod test {
|
|||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use tempdir::TempDir;
|
||||
|
||||
fn get_dir() -> TempDir {
|
||||
TempDir::new("test-image").unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
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);
|
||||
|
||||
write!(lf.create_file().unwrap(), "Hello World").unwrap();
|
||||
dir.close().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy_file_with_file() {
|
||||
let path = PathBuf::from("/tmp/test2");
|
||||
let mut lf = LazyFile::new_with_file(File::create(path).unwrap());
|
||||
let mut file = lf.get_file_mut().unwrap();
|
||||
let dir = get_dir();
|
||||
let mut path = PathBuf::from(dir.path());
|
||||
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();
|
||||
let mut s = String::new();
|
||||
file.read_to_string(&mut s).unwrap();
|
||||
assert_eq!(s, "Hello World");
|
||||
let mut s = Vec::new();
|
||||
file.read_to_end(&mut s).unwrap();
|
||||
assert_eq!(s, "Hello World".to_string().into_bytes());
|
||||
|
||||
dir.close().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
extern crate fs2;
|
||||
extern crate toml;
|
||||
extern crate tempdir;
|
||||
|
||||
pub mod content;
|
||||
pub mod entry;
|
||||
|
|
Loading…
Reference in a new issue