Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Use tempdir for tests #993

Merged
merged 7 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
7 changes: 5 additions & 2 deletions tests/invalid_order_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

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 tmpdir = tempdir().expect("could not create temp dir");

let status = Command::new(cargo_bin("polkadot"))
pscott marked this conversation as resolved.
Show resolved Hide resolved
.args(&["--dev", "invalid_order_arguments", "-d", base_path, "-y"])
.args(&["--dev", "invalid_order_arguments", "-d"])
.arg(tmpdir.path())
.arg("-y")
.status()
.unwrap();
assert!(!status.success());
Expand Down
17 changes: 10 additions & 7 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,11 +26,11 @@ 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 _ = fs::remove_dir_all(base_path);
let mut cmd = Command::new(cargo_bin("polkadot"))
.args(&["--dev", "-d", base_path])
.args(&["--dev", "-d"])
.arg(tmpdir.path())
.spawn()
.unwrap();

Expand All @@ -43,12 +44,14 @@ fn purge_chain_works() {

// Purge chain
let status = Command::new(cargo_bin("polkadot"))
.args(&["purge-chain", "--dev", "-d", base_path, "-y"])
.args(&["purge-chain", "--dev", "-d"])
.arg(tmpdir.path())
.arg( "-y")
bkchr marked this conversation as resolved.
Show resolved Hide resolved
.status()
.unwrap();
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 tmpdir = tempdir().expect("coult not create temp dir");

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

Expand Down