Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Jan 29, 2025
1 parent 335d5c2 commit ef4be42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
13 changes: 5 additions & 8 deletions crates/bestool/src/actions/tamanu/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use algae_cli::{
use chrono::Utc;
use clap::Parser;
use miette::{Context as _, IntoDiagnostic as _, Result};
use reqwest::Url;
use tokio::{
fs::{self, create_dir_all},
io::AsyncWriteExt as _,
Expand Down Expand Up @@ -277,16 +276,14 @@ async fn copy_via_io(output: &PathBuf, target_path: PathBuf) -> Result<(), miett
#[instrument(level = "debug")]
pub fn make_backup_filename(config: &TamanuConfig, ext: &str) -> String {
let output_date = now_time(&Utc).format("%Y-%m-%d_%H%M");
let output_name = config
.canonical_host_name
.as_ref()
.and_then(|url| url.host_str())
.unwrap_or_else(|| "localhost");

let canonical_host_name = Url::parse(&config.canonical_host_name).ok();
format!(
"{output_date}-{output_name}-{db}.{ext}",
// Extract the host section since "canonical_host_name" is a full URL, which is not
// suitable for a file name.
output_name = canonical_host_name
.as_ref()
.and_then(|url| url.host_str())
.unwrap_or(&config.canonical_host_name),
db = config.db.name,
)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/bestool/src/actions/tamanu/backup_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use algae_cli::keys::KeyArgs;
use chrono::Utc;
use clap::Parser;
use miette::{Context as _, IntoDiagnostic as _, Result};
use reqwest::Url;
use tracing::{debug, error, warn};
use walkdir::WalkDir;
use zip::{write::SimpleFileOptions, CompressionMethod, ZipWriter};
Expand Down Expand Up @@ -158,11 +157,11 @@ fn add_dir(

fn make_backup_filename(config: &TamanuConfig) -> PathBuf {
let output_date = now_time(&Utc).format("%Y-%m-%d_%H%M");
let canonical_host_name = Url::parse(&config.canonical_host_name).ok();
let output_name = canonical_host_name
let output_name = config
.canonical_host_name
.as_ref()
.and_then(|url| url.host_str())
.unwrap_or(&config.canonical_host_name);
.unwrap_or_else(|| "localhost");

format!("{output_date}-{output_name}.config.zip").into()
}
Expand Down
4 changes: 3 additions & 1 deletion crates/bestool/src/actions/tamanu/config/structure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use reqwest::Url;

#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TamanuConfig {
pub canonical_host_name: String,
pub canonical_host_name: Option<Url>,
pub db: Database,
pub mailgun: Mailgun,
}
Expand Down

0 comments on commit ef4be42

Please sign in to comment.