Skip to content

Commit

Permalink
Swap dev-dependency tempdir with tempfile as it is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoPonzi committed Nov 3, 2024
1 parent eb3eca7 commit f9154f5
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 1,504 deletions.
96 changes: 6 additions & 90 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions horust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ shellexpand = "~3.1"
anyhow = "~1.0"
thiserror = "~1.0"
bytefmt = "0.1.7"
horust-commands-lib = {path = "../commands"}
horust-commands-lib = { path = "../commands" }

[features]
default = ["http-healthcheck"]
Expand All @@ -38,5 +38,5 @@ http-healthcheck = ["reqwest"]
[dev-dependencies]
assert_cmd = "~2.0"
predicates = "~3.1"
tempdir = "~0.3"
tempfile = "~3"
rand = "~0.8"
3 changes: 2 additions & 1 deletion horust/src/horust/formats/horust_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ impl HorustConfig {
#[cfg(test)]
mod test {
use anyhow::Result;
use tempfile::TempDir;

use crate::horust::HorustConfig;
#[test]
fn test_load_and_merge() -> Result<()> {
let tempdir = tempdir::TempDir::new("load-and-merge")?;
let tempdir = TempDir::with_prefix("load-and-merge")?;
let config_path = tempdir.path().join("config.toml");
std::fs::write(&config_path, "Not a toml file :( ")?;
let config = HorustConfig {
Expand Down
4 changes: 2 additions & 2 deletions horust/src/horust/healthcheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ mod test {
use std::time::Duration;

use anyhow::Result;
use tempdir::TempDir;
use tempfile::TempDir;

use crate::horust::formats::{Healthiness, HealthinessStatus};
use crate::horust::healthcheck::check_health;

#[test]
fn test_healthiness_check_file() -> Result<()> {
let tempdir = TempDir::new("health")?;
let tempdir = TempDir::with_prefix("health")?;
let file_path = tempdir.path().join("file.txt");
let healthiness = Healthiness {
file_path: Some(file_path.clone()),
Expand Down
8 changes: 4 additions & 4 deletions horust/src/horust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod test {
use std::path::{Path, PathBuf};

use crate::Horust;
use tempdir::TempDir;
use tempfile::TempDir;

use crate::horust::fetch_services;
use crate::horust::formats::Service;
Expand All @@ -182,7 +182,7 @@ mod test {
}

fn create_test_dir() -> io::Result<TempDir> {
let ret = TempDir::new("horust").unwrap();
let ret = TempDir::with_prefix("horust").unwrap();
let a = Service::from_name("a");
let b = Service::start_after("b", vec!["a"]);
let a_str = toml::to_string(&a).unwrap();
Expand All @@ -194,7 +194,7 @@ mod test {

#[test]
fn test_fetch_services() -> io::Result<()> {
let tempdir = TempDir::new("horust").unwrap();
let tempdir = TempDir::with_prefix("horust").unwrap();
// Empty service directory will print a log but it's not an error.
assert_eq!(fetch_services(tempdir.path()).unwrap().len(), 0);
let not_toml_file = tempdir.path().join("not_a_toml.toml");
Expand Down Expand Up @@ -223,7 +223,7 @@ mod test {

#[test]
fn test_list_files() -> io::Result<()> {
let tempdir = TempDir::new("horust").unwrap();
let tempdir = TempDir::with_prefix("horust").unwrap();
let files = vec!["a", "b", "c"];
let files: Vec<PathBuf> = files.into_iter().map(|f| tempdir.path().join(f)).collect();

Expand Down
4 changes: 2 additions & 2 deletions horust/tests/section_general.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use assert_cmd::prelude::*;
use predicates::str::{contains, is_empty};
use tempdir::TempDir;
use tempfile::TempDir;

mod utils;
use nix::sys::signal::{kill, Signal};
Expand Down Expand Up @@ -132,7 +132,7 @@ fn test_search_path_found() {
#[test]
fn test_cwd() {
let (mut cmd, temp_dir) = get_cli();
let another_dir = TempDir::new("another").unwrap();
let another_dir = TempDir::with_prefix("another").unwrap();
let displ = another_dir.path().display().to_string();
let service = format!(r#"working-directory = "{}""#, displ);
let script = r#"#!/usr/bin/env bash
Expand Down
8 changes: 4 additions & 4 deletions horust/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::process::Command;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use tempdir::TempDir;
use tempfile::TempDir;

/// Create a random name
pub fn create_random_name() -> String {
Expand Down Expand Up @@ -56,8 +56,8 @@ pub fn store_service_script(

#[allow(dead_code)]
pub fn get_cli_multiple() -> (Command, TempDir, TempDir) {
let temp_dir = TempDir::new("horust").unwrap();
let temp_dir_2 = TempDir::new("horust_2").unwrap();
let temp_dir = TempDir::with_prefix("horust").unwrap();
let temp_dir_2 = TempDir::with_prefix("horust_2").unwrap();
let mut cmd = Command::cargo_bin("horust").unwrap();
cmd.current_dir(&temp_dir).args(vec![
"--uds-folder-path",
Expand All @@ -72,7 +72,7 @@ pub fn get_cli_multiple() -> (Command, TempDir, TempDir) {
}

pub fn get_cli() -> (Command, TempDir) {
let temp_dir = TempDir::new("horust").expect("Tmp dir");
let temp_dir = TempDir::with_prefix("horust").expect("Tmp dir");
let mut cmd = Command::cargo_bin("horust").expect("Cargo bin");
cmd.current_dir(&temp_dir).args(vec![
"--uds-folder-path",
Expand Down
Loading

0 comments on commit f9154f5

Please sign in to comment.