From 75142af035dd08cb8f1c45b1d51f8f3ce365fc3b Mon Sep 17 00:00:00 2001 From: Loong Date: Tue, 28 Nov 2023 05:05:03 +0800 Subject: [PATCH] fix: default cli components --- maa-cli/src/config/cli/maa_cli.rs | 32 ++++++++++++++++++++++++++++--- maa-cli/src/config/cli/mod.rs | 3 ++- maa-cli/src/installer/maa_core.rs | 10 ++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/maa-cli/src/config/cli/maa_cli.rs b/maa-cli/src/config/cli/maa_cli.rs index 2ec42499..0c421242 100644 --- a/maa-cli/src/config/cli/maa_cli.rs +++ b/maa-cli/src/config/cli/maa_cli.rs @@ -68,12 +68,18 @@ fn default_download_url() -> String { } #[cfg_attr(test, derive(Debug, PartialEq))] -#[derive(Deserialize, Default, Clone)] +#[derive(Deserialize, Clone)] pub struct CLIComponents { #[serde(default = "return_true")] pub binary: bool, } +impl Default for CLIComponents { + fn default() -> Self { + Self { binary: true } + } +} + #[cfg(test)] mod tests { use super::*; @@ -93,6 +99,11 @@ mod tests { self.download_url = download_url.to_string(); self } + + pub fn with_components(mut self, components: CLIComponents) -> Self { + self.components = components; + self + } } mod serde { @@ -172,7 +183,7 @@ mod tests { assert_eq!( Config::default() .with_channel(Channel::Alpha) - .with_api_url("https://foo.bar/cli/") + .set_api_url("https://foo.bar/cli/") .api_url(), "https://foo.bar/cli/alpha.json", ); @@ -187,10 +198,25 @@ mod tests { assert_eq!( Config::default() - .with_download_url("https://foo.bar/download/") + .set_download_url("https://foo.bar/download/") .download_url("v0.3.12", "maa_cli.zip"), "https://foo.bar/download/v0.3.12/maa_cli.zip", ); } + + #[test] + fn components() { + assert_eq!( + Config::default().components(), + &CLIComponents { binary: true }, + ); + + assert_eq!( + Config::default() + .with_components(CLIComponents { binary: false }) + .components(), + &CLIComponents { binary: false }, + ); + } } } diff --git a/maa-cli/src/config/cli/mod.rs b/maa-cli/src/config/cli/mod.rs index 4d729a6a..9d742cd5 100644 --- a/maa-cli/src/config/cli/mod.rs +++ b/maa-cli/src/config/cli/mod.rs @@ -165,7 +165,8 @@ mod tests { .with_api_url("https://cdn.jsdelivr.net/gh/MaaAssistantArknights/maa-cli@vversion/") .with_download_url( "https://github.com/MaaAssistantArknights/maa-cli/releases/download/", - ), + ) + .with_components(maa_cli::CLIComponents { binary: false }), }; assert_eq!(config, expect); diff --git a/maa-cli/src/installer/maa_core.rs b/maa-cli/src/installer/maa_core.rs index b8fb08d7..4a1fd42a 100644 --- a/maa-cli/src/installer/maa_core.rs +++ b/maa-cli/src/installer/maa_core.rs @@ -366,6 +366,16 @@ mod tests { let version_json: VersionJSON
= serde_json::from_str(json_str).expect("Failed to parse json"); + assert!(version_json + .can_update("MaaCore", &Version::parse("4.26.0").unwrap()) + .unwrap()); + assert!(version_json + .can_update("MaaCore", &Version::parse("4.26.1-beta.1").unwrap()) + .unwrap()); + assert!(!version_json + .can_update("MaaCore", &Version::parse("4.27.0").unwrap()) + .unwrap()); + assert_eq!( version_json.version(), &Version::parse("4.26.1").expect("Failed to parse version")