tests: Replace tempdir crate with tempfile (#366)

This commit is contained in:
Carson McManus 2024-02-19 08:43:52 -05:00 committed by GitHub
parent 2629b0b715
commit 84da432b2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 71 deletions

64
Cargo.lock generated
View file

@ -924,12 +924,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]] [[package]]
name = "futf" name = "futf"
version = "0.1.5" version = "0.1.5"
@ -2209,19 +2203,6 @@ dependencies = [
"proc-macro2", "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]] [[package]]
name = "rand" name = "rand"
version = "0.7.3" version = "0.7.3"
@ -2267,21 +2248,6 @@ dependencies = [
"rand_core 0.6.4", "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]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.5.1" version = "0.5.1"
@ -2349,15 +2315,6 @@ dependencies = [
"num_cpus", "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]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.16" version = "0.2.16"
@ -2431,15 +2388,6 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" 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]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.18" version = "0.11.18"
@ -3111,7 +3059,7 @@ dependencies = [
"standback", "standback",
"stderrlog", "stderrlog",
"steamguard", "steamguard",
"tempdir", "tempfile",
"text_io", "text_io",
"thiserror", "thiserror",
"update-informer", "update-informer",
@ -3201,16 +3149,6 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.6.0" version = "3.6.0"

View file

@ -75,7 +75,7 @@ sha1 = "0.10.5"
rayon = "1.7.0" rayon = "1.7.0"
[dev-dependencies] [dev-dependencies]
tempdir = "0.3" tempfile = "3"
proptest = "1" proptest = "1"
[profile.release] [profile.release]

View file

@ -470,11 +470,11 @@ pub enum ManifestAccountImportError {
mod tests { mod tests {
use super::*; use super::*;
use steamguard::ExposeSecret; use steamguard::ExposeSecret;
use tempdir::TempDir; use tempfile::TempDir;
#[test] #[test]
fn test_should_save_new_manifest() { 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 manifest_path = tmp_dir.path().join("manifest.json");
let manager = AccountManager::new(manifest_path.as_path()); let manager = AccountManager::new(manifest_path.as_path());
assert!(manager.save().is_ok()); assert!(manager.save().is_ok());
@ -482,7 +482,7 @@ mod tests {
#[test] #[test]
fn test_should_save_and_load_manifest() -> anyhow::Result<()> { 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"); let manifest_path = tmp_dir.path().join("manifest.json");
println!("tempdir: {}", manifest_path.display()); println!("tempdir: {}", manifest_path.display());
let mut manager = AccountManager::new(manifest_path.as_path()); let mut manager = AccountManager::new(manifest_path.as_path());
@ -518,7 +518,7 @@ mod tests {
#[test] #[test]
fn test_should_save_and_load_manifest_encrypted() -> anyhow::Result<()> { fn test_should_save_and_load_manifest_encrypted() -> anyhow::Result<()> {
let passkey = Some(SecretString::new("password".into())); 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 manifest_path = tmp_dir.path().join("manifest.json");
let mut manager = AccountManager::new(manifest_path.as_path()); let mut manager = AccountManager::new(manifest_path.as_path());
let mut account = SteamGuardAccount::new(); let mut account = SteamGuardAccount::new();
@ -567,7 +567,7 @@ mod tests {
#[test] #[test]
fn test_should_save_and_load_manifest_encrypted_longer() -> anyhow::Result<()> { fn test_should_save_and_load_manifest_encrypted_longer() -> anyhow::Result<()> {
let passkey = Some(SecretString::new("password".into())); 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 manifest_path = tmp_dir.path().join("manifest.json");
let mut manager = AccountManager::new(manifest_path.as_path()); let mut manager = AccountManager::new(manifest_path.as_path());
let mut account = SteamGuardAccount::new(); let mut account = SteamGuardAccount::new();
@ -614,7 +614,7 @@ mod tests {
#[test] #[test]
fn test_should_import() -> anyhow::Result<()> { 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 manifest_path = tmp_dir.path().join("manifest.json");
let mut manager = AccountManager::new(manifest_path.as_path()); let mut manager = AccountManager::new(manifest_path.as_path());
let mut account = SteamGuardAccount::new(); let mut account = SteamGuardAccount::new();

View file

@ -319,6 +319,8 @@ impl From<ExternalAccount> for SteamGuardAccount {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use tempfile::TempDir;
use crate::{accountmanager::CURRENT_MANIFEST_VERSION, AccountManager}; use crate::{accountmanager::CURRENT_MANIFEST_VERSION, AccountManager};
use super::*; use super::*;
@ -477,7 +479,7 @@ mod tests {
]; ];
for case in cases { for case in cases {
eprintln!("testing: {:?}", case); eprintln!("testing: {:?}", case);
let temp = tempdir::TempDir::new("steamguard-cli-test")?; let temp = TempDir::new()?;
for file in std::fs::read_dir(case.dir)? { for file in std::fs::read_dir(case.dir)? {
let file = file?; let file = file?;
let path = file.path(); let path = file.path();