From 3426c8e7d1a0fd6c039fb83d2ecc2599b7f2b5c4 Mon Sep 17 00:00:00 2001 From: "Thomas Witte (LDC)" Date: Mon, 28 Oct 2024 15:42:26 +0100 Subject: [PATCH 1/2] chore(deps): update dependencies chore(deps): use httpmock 0.7.0 chore(deps) bump reqwest to 0.12 chore(deps): update rust crate strum to 0.27 fix(deps): update rust crate httpmock to 0.8.0 --- hawkbit/Cargo.toml | 19 +++++++++---------- hawkbit/src/ddi/deployment_base.rs | 23 ++++++++++++----------- hawkbit_mock/Cargo.toml | 2 +- hawkbit_mock/src/ddi.rs | 18 +++++++++--------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/hawkbit/Cargo.toml b/hawkbit/Cargo.toml index 6dcc370..9aa7aea 100644 --- a/hawkbit/Cargo.toml +++ b/hawkbit/Cargo.toml @@ -11,19 +11,18 @@ repository = "https://github.com/collabora/hawkbit-rs" documentation = "https://docs.rs/hawkbit_mock/" [dependencies] -reqwest = { version = "0.11", features = ["json", "stream"] } +reqwest = { version = "0.12", features = ["json", "stream"] } tokio = { version = "1.1", features = ["time", "fs"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -thiserror = "1.0" +thiserror = "2.0" url = "2.2" -strum = { version = "0.21", features = ["derive"] } +strum = { version = "0.27", features = ["derive"] } cfg-if = "1.0" -digest = { version = "0.9", optional = true } -md-5 = { version = "0.9", optional = true } -sha-1 = { version = "0.9", optional = true } -sha2 = { version = "0.9", optional = true } -generic-array = {version = "0.14", optional = true } +digest = { version = "0.10", optional = true } +md-5 = { version = "0.10", optional = true } +sha-1 = { version = "0.10", optional = true } +sha2 = { version = "0.10", optional = true } futures = "0.3" bytes = "1.0" @@ -32,12 +31,12 @@ hawkbit_mock = { path = "../hawkbit_mock/" } structopt = "0.3" anyhow = "1.0" log = "0.4" -env_logger = "0.8" +env_logger = "0.11" tempdir = "0.3" assert_matches = "1.4" [features] -hash-digest= ["digest", "generic-array"] +hash-digest= ["digest"] hash-md5 = ["md-5", "hash-digest"] hash-sha1 = ["sha-1", "hash-digest"] hash-sha256 = ["sha2", "hash-digest"] diff --git a/hawkbit/src/ddi/deployment_base.rs b/hawkbit/src/ddi/deployment_base.rs index f8922db..497e36a 100644 --- a/hawkbit/src/ddi/deployment_base.rs +++ b/hawkbit/src/ddi/deployment_base.rs @@ -538,8 +538,8 @@ cfg_if::cfg_if! { struct DownloadHasher where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: digest::generic_array::ArrayLength { hasher: T, expected: String, @@ -549,8 +549,8 @@ cfg_if::cfg_if! { impl DownloadHasher where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: digest::generic_array::ArrayLength { fn update(&mut self, data: impl AsRef<[u8]>) { self.hasher.update(data); @@ -603,8 +603,8 @@ cfg_if::cfg_if! { struct DownloadStreamHash where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: digest::generic_array::ArrayLength { stream: Box> + Unpin + Send + Sync>, hasher: DownloadHasher, @@ -613,8 +613,8 @@ cfg_if::cfg_if! { impl Stream for DownloadStreamHash where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: digest::generic_array::ArrayLength, T: Unpin, T: Clone, { @@ -661,9 +661,10 @@ impl<'a> DownloadedArtifact { #[cfg(feature = "hash-digest")] async fn hash(&self, mut hasher: DownloadHasher) -> Result<(), Error> where - T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + T: digest::Digest, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: + digest::generic_array::ArrayLength, { use tokio::io::AsyncReadExt; diff --git a/hawkbit_mock/Cargo.toml b/hawkbit_mock/Cargo.toml index 554d53d..5cfb369 100644 --- a/hawkbit_mock/Cargo.toml +++ b/hawkbit_mock/Cargo.toml @@ -12,6 +12,6 @@ documentation = "https://docs.rs/hawkbit/" [dependencies] hawkbit = { version = "0.6.0", path = "../hawkbit/" } -httpmock = "0.5.4" +httpmock = "0.8.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/hawkbit_mock/src/ddi.rs b/hawkbit_mock/src/ddi.rs index 2a4392c..514257c 100644 --- a/hawkbit_mock/src/ddi.rs +++ b/hawkbit_mock/src/ddi.rs @@ -30,7 +30,7 @@ use std::{ use httpmock::{ Method::{GET, POST, PUT}, - MockRef, MockRefExt, MockServer, + Mock, MockExt, MockServer, }; use serde_json::{json, Map, Value}; @@ -178,7 +178,7 @@ impl Target { self.cancel_action.borrow().as_ref(), )); - let mut old = MockRef::new(old, &self.server); + let mut old = Mock::new(old, &self.server); old.delete(); } @@ -349,7 +349,7 @@ impl Target { finished: Finished, progress: Option, details: Vec<&str>, - ) -> MockRef<'_> { + ) -> Mock<'_> { self.server.mock(|when, then| { let expected = match progress { Some(progress) => json!({ @@ -471,7 +471,7 @@ impl Target { execution: Execution, finished: Finished, details: Vec<&str>, - ) -> MockRef<'_> { + ) -> Mock<'_> { self.server.mock(|when, then| { let expected = json!({ "id": cancel_id, @@ -499,14 +499,14 @@ impl Target { /// Return the number of times the poll API has been called by the client. pub fn poll_hits(&self) -> usize { - let mock = MockRef::new(self.poll.get(), &self.server); + let mock = Mock::new(self.poll.get(), &self.server); mock.hits() } /// Return the number of times the target configuration has been uploaded by the client. pub fn config_data_hits(&self) -> usize { self.config_data.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -514,7 +514,7 @@ impl Target { /// Return the number of times the deployment details have been fetched by the client. pub fn deployment_hits(&self) -> usize { self.deployment.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -522,7 +522,7 @@ impl Target { /// Return the number of times the cancel action URL has been fetched by the client. pub fn cancel_action_hits(&self) -> usize { self.cancel_action.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -536,7 +536,7 @@ struct PendingAction { impl Drop for PendingAction { fn drop(&mut self) { - let mut mock = MockRef::new(self.mock, &self.server); + let mut mock = Mock::new(self.mock, &self.server); mock.delete(); } } From 84fd42578be8ac6fd785961e62aa66b642b7265a Mon Sep 17 00:00:00 2001 From: "Thomas Witte (LDC)" Date: Thu, 16 Oct 2025 08:17:59 +0200 Subject: [PATCH 2/2] style: fix deprecation warnings httpmock 0.8 marks mock.hits() as deprecated and suggests mock.calls() instead. style: fix warnings during build style: fix clippy hidden lifetime warnings style: resolve clippy and fmt warnings --- .github/workflows/ci.yml | 4 ++-- hawkbit/src/ddi/cancel_action.rs | 1 + hawkbit/src/ddi/common.rs | 2 +- hawkbit/src/ddi/deployment_base.rs | 19 ++++++++++--------- hawkbit/tests/tests.rs | 12 ++++++------ hawkbit_mock/src/ddi.rs | 23 ++++++++++++----------- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00c3ddb..5edc55f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,10 +82,10 @@ jobs: command: test args: --all-features --no-fail-fast env: - RUSTFLAGS: "-Zinstrument-coverage" + RUSTFLAGS: "-C instrument-coverage" LLVM_PROFILE_FILE: "hawkbitrs-%p-%m.profraw" - name: Install grcov - run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi + run: cargo install grcov - name: Run grcov run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "hawkbit/examples/*" --ignore "*target*" -o coverage.lcov - name: Upload coverage to Codecov diff --git a/hawkbit/src/ddi/cancel_action.rs b/hawkbit/src/ddi/cancel_action.rs index 0cf7217..5ef3edd 100644 --- a/hawkbit/src/ddi/cancel_action.rs +++ b/hawkbit/src/ddi/cancel_action.rs @@ -63,6 +63,7 @@ impl CancelAction { } } +#[allow(dead_code)] #[derive(Debug, Deserialize)] struct CancelReply { id: String, diff --git a/hawkbit/src/ddi/common.rs b/hawkbit/src/ddi/common.rs index ff22ad1..71d3ffc 100644 --- a/hawkbit/src/ddi/common.rs +++ b/hawkbit/src/ddi/common.rs @@ -73,7 +73,7 @@ pub(crate) async fn send_feedback_internal( let details = details.iter().map(|m| m.to_string()).collect(); let feedback = Feedback::new(id, execution, finished, progress, details); - let reply = client.post(&url.to_string()).json(&feedback).send().await?; + let reply = client.post(url.to_string()).json(&feedback).send().await?; reply.error_for_status()?; Ok(()) diff --git a/hawkbit/src/ddi/deployment_base.rs b/hawkbit/src/ddi/deployment_base.rs index 497e36a..e6bfead 100644 --- a/hawkbit/src/ddi/deployment_base.rs +++ b/hawkbit/src/ddi/deployment_base.rs @@ -44,6 +44,7 @@ impl UpdatePreFetch { } #[derive(Debug, Deserialize)] +#[allow(dead_code)] struct Reply { id: String, deployment: Deployment, @@ -108,6 +109,7 @@ struct ArtifactInternal { } #[derive(Debug, Deserialize, Clone)] +#[allow(dead_code)] struct Hashes { sha1: String, md5: String, @@ -190,6 +192,7 @@ impl<'de> Deserialize<'de> for Links { } #[derive(Debug)] +#[allow(dead_code)] struct Download { content: Link, md5sum: Option, @@ -204,6 +207,7 @@ struct Links { } #[derive(Debug, Deserialize)] +#[allow(dead_code)] struct ActionHistory { status: String, #[serde(default)] @@ -239,7 +243,7 @@ impl Update { } /// An iterator on all the software chunks of the update. - pub fn chunks(&self) -> impl Iterator { + pub fn chunks(&self) -> impl Iterator> { let client = self.client.clone(); self.info @@ -336,7 +340,7 @@ impl<'a> Chunk<'a> { } /// An iterator on all the artifacts of the chunk. - pub fn artifacts(&self) -> impl Iterator { + pub fn artifacts(&self) -> impl Iterator> { let client = self.client.clone(); self.chunk @@ -396,14 +400,10 @@ impl<'a> Artifact<'a> { .links .https .as_ref() - .or_else(|| self.artifact.links.http.as_ref()) + .or(self.artifact.links.http.as_ref()) .expect("Missing content link in for artifact"); - let resp = self - .client - .get(&download.content.to_string()) - .send() - .await?; + let resp = self.client.get(download.content.to_string()).send().await?; resp.error_for_status_ref()?; Ok(resp) @@ -503,6 +503,7 @@ impl<'a> Artifact<'a> { } /// A downloaded file part of a [`Chunk`]. +#[allow(dead_code)] #[derive(Debug)] pub struct DownloadedArtifact { file: PathBuf, @@ -648,7 +649,7 @@ cfg_if::cfg_if! { } } -impl<'a> DownloadedArtifact { +impl DownloadedArtifact { fn new(file: PathBuf, hashes: Hashes) -> Self { Self { file, hashes } } diff --git a/hawkbit/tests/tests.rs b/hawkbit/tests/tests.rs index 0da7ab2..a698ad4 100644 --- a/hawkbit/tests/tests.rs +++ b/hawkbit/tests/tests.rs @@ -240,13 +240,13 @@ async fn send_deployment_feedback() { None, vec!["Downloading"], ); - assert_eq!(mock.hits(), 0); + assert_eq!(mock.calls(), 0); update .send_feedback(Execution::Proceeding, Finished::None, vec!["Downloading"]) .await .expect("Failed to send feedback"); - assert_eq!(mock.hits(), 1); + assert_eq!(mock.calls(), 1); mock.delete(); // Send feedback with progress @@ -257,7 +257,7 @@ async fn send_deployment_feedback() { Some(json!({"awesome": true})), vec!["Done"], ); - assert_eq!(mock.hits(), 0); + assert_eq!(mock.calls(), 0); #[derive(Serialize)] struct Progress { @@ -274,7 +274,7 @@ async fn send_deployment_feedback() { ) .await .expect("Failed to send feedback"); - assert_eq!(mock.hits(), 1); + assert_eq!(mock.calls(), 1); mock.delete(); } @@ -489,12 +489,12 @@ async fn cancel_action() { Finished::None, vec!["Cancelling"], ); - assert_eq!(mock.hits(), 0); + assert_eq!(mock.calls(), 0); cancel_action .send_feedback(Execution::Proceeding, Finished::None, vec!["Cancelling"]) .await .expect("Failed to send feedback"); - assert_eq!(mock.hits(), 1); + assert_eq!(mock.calls(), 1); mock.delete(); } diff --git a/hawkbit_mock/src/ddi.rs b/hawkbit_mock/src/ddi.rs index 514257c..629dbcb 100644 --- a/hawkbit_mock/src/ddi.rs +++ b/hawkbit_mock/src/ddi.rs @@ -124,6 +124,7 @@ impl Target { } } + #[allow(clippy::too_many_arguments)] fn create_poll( server: &MockServer, tenant: &str, @@ -157,7 +158,7 @@ impl Target { let mock = server.mock(|when, then| { when.method(GET) .path(format!("/{}/controller/v1/{}", tenant, name)) - .header("Authorization", &format!("TargetToken {}", key)); + .header("Authorization", format!("TargetToken {}", key)); then.status(200) .header("Content-Type", "application/json") @@ -221,7 +222,7 @@ impl Target { when.method(PUT) .path(format!("/DEFAULT/controller/v1/{}/configData", self.name)) .header("Content-Type", "application/json") - .header("Authorization", &format!("TargetToken {}", self.key)) + .header("Authorization", format!("TargetToken {}", self.key)) .json_body(expected_config_data); then.status(200); @@ -285,7 +286,7 @@ impl Target { "/DEFAULT/controller/v1/{}/deploymentBase/{}", self.name, deploy.id )) - .header("Authorization", &format!("TargetToken {}", self.key)); + .header("Authorization", format!("TargetToken {}", self.key)); then.status(200) .header("Content-Type", "application/json") @@ -301,7 +302,7 @@ impl Target { self.server.mock(|when, then| { when.method(GET) .path(path) - .header("Authorization", &format!("TargetToken {}", self.key)); + .header("Authorization", format!("TargetToken {}", self.key)); then.status(200).body_from_file(artifact.to_str().unwrap()); }); @@ -380,7 +381,7 @@ impl Target { "/{}/controller/v1/{}/deploymentBase/{}/feedback", self.tenant, self.name, deployment_id )) - .header("Authorization", &format!("TargetToken {}", self.key)) + .header("Authorization", format!("TargetToken {}", self.key)) .header("Content-Type", "application/json") .json_body(expected); @@ -423,7 +424,7 @@ impl Target { "/DEFAULT/controller/v1/{}/cancelAction/{}", self.name, id )) - .header("Authorization", &format!("TargetToken {}", self.key)); + .header("Authorization", format!("TargetToken {}", self.key)); then.status(200) .header("Content-Type", "application/json") @@ -489,7 +490,7 @@ impl Target { "/{}/controller/v1/{}/cancelAction/{}/feedback", self.tenant, self.name, cancel_id )) - .header("Authorization", &format!("TargetToken {}", self.key)) + .header("Authorization", format!("TargetToken {}", self.key)) .header("Content-Type", "application/json") .json_body(expected); @@ -500,14 +501,14 @@ impl Target { /// Return the number of times the poll API has been called by the client. pub fn poll_hits(&self) -> usize { let mock = Mock::new(self.poll.get(), &self.server); - mock.hits() + mock.calls() } /// Return the number of times the target configuration has been uploaded by the client. pub fn config_data_hits(&self) -> usize { self.config_data.borrow().as_ref().map_or(0, |m| { let mock = Mock::new(m.mock, &self.server); - mock.hits() + mock.calls() }) } @@ -515,7 +516,7 @@ impl Target { pub fn deployment_hits(&self) -> usize { self.deployment.borrow().as_ref().map_or(0, |m| { let mock = Mock::new(m.mock, &self.server); - mock.hits() + mock.calls() }) } @@ -523,7 +524,7 @@ impl Target { pub fn cancel_action_hits(&self) -> usize { self.cancel_action.borrow().as_ref().map_or(0, |m| { let mock = Mock::new(m.mock, &self.server); - mock.hits() + mock.calls() }) } }