Skip to content

Commit

Permalink
tests: Replace tempdir crate with tempfile (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored Feb 19, 2024
1 parent 2629b0b commit 84da432
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 71 deletions.
64 changes: 1 addition & 63 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ sha1 = "0.10.5"
rayon = "1.7.0"

[dev-dependencies]
tempdir = "0.3"
tempfile = "3"
proptest = "1"

[profile.release]
Expand Down
12 changes: 6 additions & 6 deletions src/accountmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,19 @@ 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());
}

#[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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/accountmanager/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ impl From<ExternalAccount> for SteamGuardAccount {

#[cfg(test)]
mod tests {
use tempfile::TempDir;

use crate::{accountmanager::CURRENT_MANIFEST_VERSION, AccountManager};

use super::*;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 84da432

Please sign in to comment.