From 84da432b2dfbbecc985747e8de3131836c097172 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 19 Feb 2024 08:43:52 -0500 Subject: [PATCH] tests: Replace `tempdir` crate with `tempfile` (#366) --- Cargo.lock | 64 +---------------------------------- Cargo.toml | 2 +- src/accountmanager.rs | 12 +++---- src/accountmanager/migrate.rs | 4 ++- 4 files changed, 11 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b33e57a..4dacf38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -924,12 +924,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futf" version = "0.1.5" @@ -2209,19 +2203,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -2267,21 +2248,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2349,15 +2315,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -2431,15 +2388,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "reqwest" version = "0.11.18" @@ -3111,7 +3059,7 @@ dependencies = [ "standback", "stderrlog", "steamguard", - "tempdir", + "tempfile", "text_io", "thiserror", "update-informer", @@ -3201,16 +3149,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempdir" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -dependencies = [ - "rand 0.4.6", - "remove_dir_all", -] - [[package]] name = "tempfile" version = "3.6.0" diff --git a/Cargo.toml b/Cargo.toml index da4fd89..b644d34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ sha1 = "0.10.5" rayon = "1.7.0" [dev-dependencies] -tempdir = "0.3" +tempfile = "3" proptest = "1" [profile.release] diff --git a/src/accountmanager.rs b/src/accountmanager.rs index bd95257..a5e7218 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -470,11 +470,11 @@ pub enum ManifestAccountImportError { mod tests { use super::*; use steamguard::ExposeSecret; - use tempdir::TempDir; + use tempfile::TempDir; #[test] fn test_should_save_new_manifest() { - let tmp_dir = TempDir::new("steamguard-cli-test").unwrap(); + let tmp_dir = TempDir::new().unwrap(); let manifest_path = tmp_dir.path().join("manifest.json"); let manager = AccountManager::new(manifest_path.as_path()); assert!(manager.save().is_ok()); @@ -482,7 +482,7 @@ mod tests { #[test] fn test_should_save_and_load_manifest() -> anyhow::Result<()> { - let tmp_dir = TempDir::new("steamguard-cli-test")?; + let tmp_dir = TempDir::new()?; let manifest_path = tmp_dir.path().join("manifest.json"); println!("tempdir: {}", manifest_path.display()); let mut manager = AccountManager::new(manifest_path.as_path()); @@ -518,7 +518,7 @@ mod tests { #[test] fn test_should_save_and_load_manifest_encrypted() -> anyhow::Result<()> { let passkey = Some(SecretString::new("password".into())); - let tmp_dir = TempDir::new("steamguard-cli-test")?; + let tmp_dir = TempDir::new()?; let manifest_path = tmp_dir.path().join("manifest.json"); let mut manager = AccountManager::new(manifest_path.as_path()); let mut account = SteamGuardAccount::new(); @@ -567,7 +567,7 @@ mod tests { #[test] fn test_should_save_and_load_manifest_encrypted_longer() -> anyhow::Result<()> { let passkey = Some(SecretString::new("password".into())); - let tmp_dir = TempDir::new("steamguard-cli-test")?; + let tmp_dir = TempDir::new()?; let manifest_path = tmp_dir.path().join("manifest.json"); let mut manager = AccountManager::new(manifest_path.as_path()); let mut account = SteamGuardAccount::new(); @@ -614,7 +614,7 @@ mod tests { #[test] fn test_should_import() -> anyhow::Result<()> { - let tmp_dir = TempDir::new("steamguard-cli-test")?; + let tmp_dir = TempDir::new()?; let manifest_path = tmp_dir.path().join("manifest.json"); let mut manager = AccountManager::new(manifest_path.as_path()); let mut account = SteamGuardAccount::new(); diff --git a/src/accountmanager/migrate.rs b/src/accountmanager/migrate.rs index 41c75b0..e07e9c9 100644 --- a/src/accountmanager/migrate.rs +++ b/src/accountmanager/migrate.rs @@ -319,6 +319,8 @@ impl From for SteamGuardAccount { #[cfg(test)] mod tests { + use tempfile::TempDir; + use crate::{accountmanager::CURRENT_MANIFEST_VERSION, AccountManager}; use super::*; @@ -477,7 +479,7 @@ mod tests { ]; for case in cases { eprintln!("testing: {:?}", case); - let temp = tempdir::TempDir::new("steamguard-cli-test")?; + let temp = TempDir::new()?; for file in std::fs::read_dir(case.dir)? { let file = file?; let path = file.path();