put temp, test files in OUT_DIR (#1448)

This commit is contained in:
Rob Walker 2018-10-08 16:15:17 -07:00 committed by GitHub
parent 517149d325
commit a99d17c3ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 23 deletions

View File

@ -1755,7 +1755,7 @@ mod tests {
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
let path = format!("{}/tmp-ledger-{}-{}", out_dir, name, keypair.pubkey());
let path = format!("{}/tmp/ledger-{}-{}", out_dir, name, keypair.pubkey());
let mut writer = LedgerWriter::open(&path, true).unwrap();
let zero = Hash::default();

View File

@ -309,7 +309,7 @@ mod tests {
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
format!("{}/tmp-ledger-{}-{}", out_dir, name, keypair.pubkey())
format!("{}/tmp/ledger-{}-{}", out_dir, name, keypair.pubkey())
}
#[test]

View File

@ -547,9 +547,11 @@ pub fn next_entries(
#[cfg(test)]
pub fn tmp_ledger_path(name: &str) -> String {
use std::env;
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
format!("/tmp/tmp-ledger-{}-{}", name, keypair.pubkey())
format!("{}/tmp/ledger-{}-{}", out_dir, name, keypair.pubkey())
}
#[cfg(test)]

View File

@ -150,16 +150,16 @@ mod tests {
use crdt::Node;
use fullnode::Fullnode;
use hash::Hash;
use ledger::{genesis, read_ledger};
use ledger::{genesis, read_ledger, tmp_ledger_path};
use logger;
use replicator::sample_file;
use replicator::Replicator;
use signature::{Keypair, KeypairUtil};
use std::fs::File;
use std::fs::{remove_dir_all, remove_file};
use std::fs::{create_dir_all, remove_dir_all, remove_file};
use std::io::Write;
use std::mem::size_of;
use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread::sleep;
@ -170,7 +170,7 @@ mod tests {
logger::setup();
info!("starting replicator test");
let entry_height = 0;
let replicator_ledger_path = "replicator_test_replicator_ledger";
let replicator_ledger_path = &tmp_ledger_path("replicator_test_replicator_ledger");
let exit = Arc::new(AtomicBool::new(false));
let done = Arc::new(AtomicBool::new(false));
@ -247,21 +247,35 @@ mod tests {
let _ignored = remove_dir_all(&replicator_ledger_path);
}
fn tmp_file_path(name: &str) -> PathBuf {
use std::env;
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
let mut path = PathBuf::new();
path.push(out_dir);
path.push("tmp");
create_dir_all(&path).unwrap();
path.push(format!("{}-{}", name, keypair.pubkey()));
path
}
#[test]
fn test_sample_file() {
logger::setup();
let in_path = Path::new("test_sample_file_input.txt");
let in_path = tmp_file_path("test_sample_file_input.txt");
let num_strings = 4096;
let string = "12foobar";
{
let mut in_file = File::create(in_path).unwrap();
let mut in_file = File::create(&in_path).unwrap();
for _ in 0..num_strings {
in_file.write(string.as_bytes()).unwrap();
}
}
let num_samples = (string.len() * num_strings / size_of::<Hash>()) as u64;
let samples: Vec<_> = (0..num_samples).collect();
let res = sample_file(in_path, samples.as_slice());
let res = sample_file(&in_path, samples.as_slice());
assert!(res.is_ok());
let ref_hash: Hash = Hash::new(&[
173, 251, 182, 165, 10, 54, 33, 150, 133, 226, 106, 150, 99, 192, 179, 1, 230, 144,
@ -271,30 +285,30 @@ mod tests {
assert_eq!(res, ref_hash);
// Sample just past the end
assert!(sample_file(in_path, &[num_samples]).is_err());
remove_file(in_path).unwrap();
assert!(sample_file(&in_path, &[num_samples]).is_err());
remove_file(&in_path).unwrap();
}
#[test]
fn test_sample_file_invalid_offset() {
let in_path = Path::new("test_sample_file_invalid_offset_input.txt");
let in_path = tmp_file_path("test_sample_file_invalid_offset_input.txt");
{
let mut in_file = File::create(in_path).unwrap();
let mut in_file = File::create(&in_path).unwrap();
for _ in 0..4096 {
in_file.write("123456foobar".as_bytes()).unwrap();
}
}
let samples = [0, 200000];
let res = sample_file(in_path, &samples);
let res = sample_file(&in_path, &samples);
assert!(res.is_err());
remove_file(in_path).unwrap();
}
#[test]
fn test_sample_file_missing_file() {
let in_path = Path::new("test_sample_file_that_doesnt_exist.txt");
let in_path = tmp_file_path("test_sample_file_that_doesnt_exist.txt");
let samples = [0, 5];
let res = sample_file(in_path, &samples);
let res = sample_file(&in_path, &samples);
assert!(res.is_err());
}

View File

@ -438,7 +438,7 @@ mod tests {
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
let path = format!("{}/tmp-ledger-{}-{}", out_dir, name, keypair.pubkey());
let path = format!("{}/tmp/ledger-{}-{}", out_dir, name, keypair.pubkey());
let mut writer = LedgerWriter::open(&path, true).unwrap();
writer.write_entries(mint.create_entries()).unwrap();

View File

@ -628,7 +628,7 @@ mod tests {
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
let path = format!("{}/tmp-ledger-{}-{}", out_dir, name, keypair.pubkey());
let path = format!("{}/tmp/ledger-{}-{}", out_dir, name, keypair.pubkey());
let mut writer = LedgerWriter::open(&path, true).unwrap();
writer.write_entries(mint.create_entries()).unwrap();
@ -1051,20 +1051,28 @@ mod tests {
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}
fn tmp_file_path(name: &str) -> String {
use std::env;
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
let keypair = Keypair::new();
format!("{}/tmp/{}-{}", out_dir, name, keypair.pubkey()).to_string()
}
#[test]
fn test_wallet_gen_keypair_file() {
let outfile = "test_gen_keypair_file.json";
let outfile = tmp_file_path("test_gen_keypair_file.json");
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
assert!(Path::new(outfile).exists());
assert!(Path::new(&outfile).exists());
assert_eq!(keypair_vec, read_pkcs8(&outfile).unwrap());
assert!(read_keypair(&outfile).is_ok());
assert_eq!(
read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
mem::size_of::<Pubkey>()
);
fs::remove_file(outfile).unwrap();
assert!(!Path::new(outfile).exists());
fs::remove_file(&outfile).unwrap();
assert!(!Path::new(&outfile).exists());
}
#[test]
#[ignore]