Skip to content

Commit

Permalink
fix: default cli components
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc committed Nov 27, 2023
1 parent 95b2428 commit 75142af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
32 changes: 29 additions & 3 deletions maa-cli/src/config/cli/maa_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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 {
Expand Down Expand Up @@ -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",
);
Expand All @@ -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 },
);
}
}
}
3 changes: 2 additions & 1 deletion maa-cli/src/config/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions maa-cli/src/installer/maa_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ mod tests {
let version_json: VersionJSON<Details> =
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")
Expand Down

0 comments on commit 75142af

Please sign in to comment.