use std::time::Duration;
pub(crate) const BACKUP_PATH: &str = "/data/api/v1/backup";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackupType {
Roaming,
All,
}
impl BackupType {
pub fn wire(self) -> &'static str {
match self {
Self::Roaming => "roaming",
Self::All => "all",
}
}
}
impl Default for BackupType {
fn default() -> Self {
Self::Roaming
}
}
pub(crate) fn backup_download_path(backup_type: BackupType) -> String {
format!("{BACKUP_PATH}?type={}", backup_type.wire())
}
pub(crate) const BACKUP_ACCEPT: &str = "application/octet-stream";
pub const BACKUP_TIMEOUT: Duration = Duration::from_secs(300);
pub(crate) fn restore_query() -> [(String, String); 4] {
[
("restoreDisabled".to_string(), "false".to_string()),
("disableTempProjectBackup".to_string(), "false".to_string()),
("renameEnabled".to_string(), "false".to_string()),
("restoreLocal".to_string(), "false".to_string()),
]
}
#[cfg(test)]
mod tests {
use std::time::Duration;
use super::{BACKUP_TIMEOUT, BackupType, backup_download_path, restore_query};
#[test]
fn backup_timeout_is_the_300s_class() {
assert_eq!(BACKUP_TIMEOUT, Duration::from_secs(300));
}
#[test]
fn download_path_carries_the_type_query() {
assert_eq!(
backup_download_path(BackupType::default()),
"/data/api/v1/backup?type=roaming",
"roaming remains the DEFAULT query"
);
assert_eq!(
backup_download_path(BackupType::Roaming),
"/data/api/v1/backup?type=roaming"
);
assert_eq!(
backup_download_path(BackupType::All),
"/data/api/v1/backup?type=all"
);
}
#[test]
fn restore_query_is_four_explicit_falses() {
let pairs = restore_query();
assert_eq!(pairs.len(), 4);
for (_, value) in &pairs {
assert_eq!(value, "false", "every scope param is explicit false");
}
let names: Vec<&str> = pairs.iter().map(|(name, _)| name.as_str()).collect();
assert_eq!(
names,
[
"restoreDisabled",
"disableTempProjectBackup",
"renameEnabled",
"restoreLocal"
],
"the postman param set, no newName (renameEnabled=false)"
);
}
}