From 2ff31b3662d34a3e86eb3670bcc935bb97d46f58 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Thu, 18 Jul 2024 19:26:24 +0200 Subject: [PATCH] test and update quick_xml update bucket deserialization --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/update.rs | 42 +++++++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4babbc8a..381d1251 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -858,9 +858,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.31.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +checksum = "4091e032efecb09d7b1f711f487b85ab925632a842627e3200fb088382cde32c" dependencies = [ "memchr", "serde", diff --git a/Cargo.toml b/Cargo.toml index 7315049f..a7b5562d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ url = "2" serde_repr = "0.1" webpki-roots = "0.26" ar = "0.9" -quick-xml = { version = "0.31", features = ["serialize"] } +quick-xml = { version = "0.36", features = ["serialize"] } semver = "1" futures-util = "0.3" self-replace = "1" diff --git a/src/update.rs b/src/update.rs index 3a89d0a5..3322fa66 100644 --- a/src/update.rs +++ b/src/update.rs @@ -75,7 +75,8 @@ async fn latest_release(client: &Client) -> Result { .contents .into_iter() .flat_map(Content::release) - .max() + .filter(|release| release.key.contains(effective_target())) + .max_by_key(|release| release.version.clone()) .ok_or(UpdateError::NoReleases) } @@ -93,7 +94,7 @@ struct ListBucket { contents: Vec, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "PascalCase")] struct Content { key: String, @@ -101,10 +102,7 @@ struct Content { impl Content { fn release(self) -> Option { - let (version, filename) = self.key.split_once('/')?; - if !filename.contains(effective_target()) { - return None; - } + let (version, _filename) = self.key.split_once('/')?; let version = version.strip_prefix('v')?; Some(Release { version: version.parse().ok()?, @@ -113,7 +111,7 @@ impl Content { } } -#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] +#[derive(Debug, Clone)] struct Release { version: Version, key: String, @@ -170,3 +168,33 @@ impl From for UpdateError { UpdateError::Timeout } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_list_bucket() { + let sample = r#" + + + fishnet-releases + + 74 + 1000 + false + + v2.6.10/fishnet-v2.6.10-aarch64-apple-darwin + 2023-05-01T16:27:52.000Z + "f7ed5e695e421adbf153ee35a4d46fca-6" + 30471464 + STANDARD + + "#; + + let bucket: ListBucket = quick_xml::de::from_str(sample).unwrap(); + let release = bucket.contents[0].clone().release().unwrap(); + assert_eq!(release.version, Version::new(2, 6, 10)); + assert_eq!(release.key, "v2.6.10/fishnet-v2.6.10-aarch64-apple-darwin"); + } +}