/bin/node/cli/tests/temp_base_path_works.rs

https://github.com/paritytech/substrate · Rust · 72 lines · 43 code · 13 blank · 16 comment · 0 complexity · a6b414c71ce20604a22e69d7b802f378 MD5 · raw file

  1. // This file is part of Substrate.
  2. // Copyright (C) 2020 Parity Technologies (UK) Ltd.
  3. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. #![cfg(unix)]
  15. use assert_cmd::cargo::cargo_bin;
  16. use nix::sys::signal::{kill, Signal::SIGINT};
  17. use nix::unistd::Pid;
  18. use regex::Regex;
  19. use std::convert::TryInto;
  20. use std::io::Read;
  21. use std::path::PathBuf;
  22. use std::process::{Command, Stdio};
  23. use std::thread;
  24. use std::time::Duration;
  25. pub mod common;
  26. #[test]
  27. fn temp_base_path_works() {
  28. let mut cmd = Command::new(cargo_bin("substrate"));
  29. let mut cmd = cmd
  30. .args(&["--dev", "--tmp"])
  31. .stdout(Stdio::piped())
  32. .stderr(Stdio::piped())
  33. .spawn()
  34. .unwrap();
  35. // Let it produce some blocks.
  36. thread::sleep(Duration::from_secs(30));
  37. assert!(
  38. cmd.try_wait().unwrap().is_none(),
  39. "the process should still be running"
  40. );
  41. // Stop the process
  42. kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
  43. assert!(common::wait_for(&mut cmd, 40)
  44. .map(|x| x.success())
  45. .unwrap_or_default());
  46. // Ensure the database has been deleted
  47. let mut stderr = String::new();
  48. cmd.stderr.unwrap().read_to_string(&mut stderr).unwrap();
  49. let re = Regex::new(r"Database: .+ at (\S+)").unwrap();
  50. let db_path = PathBuf::from(
  51. re.captures(stderr.as_str())
  52. .unwrap()
  53. .get(1)
  54. .unwrap()
  55. .as_str()
  56. .to_string(),
  57. );
  58. assert!(!db_path.exists());
  59. }