mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 03:18:01 +00:00
Use tempdir for tests (#993)
* Use tempdir for tests * Rename tmp to tempdir * Update Cargo.lock * Update expect error message in run_command_and_kill * Call with .path() rather than creating an string slice * Call tempdir with arg instead of args * Update tests/purge_chain_works.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Generated
+1
@@ -4037,6 +4037,7 @@ dependencies = [
|
||||
"parity-util-mem",
|
||||
"polkadot-cli",
|
||||
"polkadot-service",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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"))
|
||||
.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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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")
|
||||
.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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user