Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use tempdir for tests
  • Loading branch information
Scott Piriou committed Apr 13, 2020
commit 43e48e1a41fe82f7d20bbb04caf51a3ebd24f2c6
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parity-util-mem = { version = "*", default-features = false, features = ["jemall
[dev-dependencies]
assert_cmd = "0.12"
nix = "0.17"
tempfile = "3.1.0"

[workspace]
members = [
Expand Down
4 changes: 3 additions & 1 deletion tests/invalid_order_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

use assert_cmd::cargo::cargo_bin;
use std::process::Command;
use tempfile::tempdir;

#[test]
#[cfg(unix)]
fn invalid_order_arguments() {
let base_path = "invalid_order_arguments";
let tmp = tempdir().expect("could not create temp dir");
let base_path = tmp.path().to_str().expect("path should consist of valid utf8 characters");

let status = Command::new(cargo_bin("polkadot"))
.args(&["--dev", "invalid_order_arguments", "-d", base_path, "-y"])
Expand Down
11 changes: 6 additions & 5 deletions tests/purge_chain_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, process::Command, thread, time::Duration, fs, path::PathBuf};
use std::{convert::TryInto, process::Command, thread, time::Duration};
use tempfile::tempdir;

mod common;

Expand All @@ -25,9 +26,9 @@ fn purge_chain_works() {
use nix::sys::signal::{kill, Signal::SIGINT};
use nix::unistd::Pid;

let base_path = "purge_chain_test";
let tmpdir = tempdir().expect("could not create temp dir");
let base_path = tmpdir.path().to_str().expect("path should consist of valid utf8 characters");

let _ = fs::remove_dir_all(base_path);
let mut cmd = Command::new(cargo_bin("polkadot"))
.args(&["--dev", "-d", base_path])
.spawn()
Expand All @@ -49,6 +50,6 @@ fn purge_chain_works() {
assert!(status.success());

// Make sure that the `dev` chain folder exists, but the `db` is deleted.
assert!(PathBuf::from(base_path).join("chains/dev/").exists());
assert!(!PathBuf::from(base_path).join("chains/dev/db").exists());
assert!(tmpdir.path().join("chains/dev/").exists());
assert!(!tmpdir.path().join("chains/dev/db").exists());
}
9 changes: 6 additions & 3 deletions tests/running_the_node_and_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, process::Command, thread, time::Duration, fs};
use std::{convert::TryInto, process::Command, thread, time::Duration};
use tempfile::tempdir;

mod common;

Expand All @@ -26,9 +27,11 @@ fn running_the_node_works_and_can_be_interrupted() {
use nix::unistd::Pid;

fn run_command_and_kill(signal: Signal) {
let _ = fs::remove_dir_all("interrupt_test");
let tmp = tempdir().expect("coult not create temp dir");
let base_path = tmp.path().to_str().expect("path should be valid utf8");

let mut cmd = Command::new(cargo_bin("polkadot"))
.args(&["--dev", "-d", "interrupt_test"])
.args(&["--dev", "-d", base_path])
.spawn()
.unwrap();

Expand Down