rust-afterburn/0001-providers-packet-use-stored-client-for-boot-checkin.patch
2023-03-20 20:46:22 -04:00

80 lines
2.4 KiB
Diff

From f6799a3852ab6145a7bb62b2ec8bc8cd657623b1 Mon Sep 17 00:00:00 2001
From: Benjamin Gilbert <bgilbert@redhat.com>
Date: Mon, 20 Mar 2023 01:08:04 -0400
Subject: [PATCH 1/6] providers/packet: use stored client for boot checkin
Store the retry::Client on the PacketProvider and use it for boot checkin
to ease testing.
---
src/providers/packet/mock_tests.rs | 7 +++++--
src/providers/packet/mod.rs | 6 +++---
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/providers/packet/mock_tests.rs b/src/providers/packet/mock_tests.rs
index d22543ceda92..ef26be4c7759 100644
--- a/src/providers/packet/mock_tests.rs
+++ b/src/providers/packet/mock_tests.rs
@@ -3,6 +3,7 @@ use mockito::{self, Matcher};
#[test]
fn test_boot_checkin() {
+ let client = crate::retry::Client::try_new().unwrap().max_retries(0);
let data = packet::PacketData {
id: String::new(),
hostname: String::new(),
@@ -19,7 +20,10 @@ fn test_boot_checkin() {
error: None,
phone_home_url: mockito::server_url(),
};
- let provider = packet::PacketProvider { data };
+ let provider = packet::PacketProvider {
+ client: client.clone(),
+ data,
+ };
let mock = mockito::mock("POST", "/")
.match_header(
@@ -37,7 +41,6 @@ fn test_boot_checkin() {
mockito::reset();
// Check error logic, but fail fast without re-trying.
- let client = crate::retry::Client::try_new().unwrap().max_retries(0);
packet::PacketProvider::fetch_content(Some(client)).unwrap_err();
}
diff --git a/src/providers/packet/mod.rs b/src/providers/packet/mod.rs
index be180a546583..98a4018581b4 100644
--- a/src/providers/packet/mod.rs
+++ b/src/providers/packet/mod.rs
@@ -90,6 +90,7 @@ struct PacketAddressInfo {
#[derive(Clone, Debug)]
pub struct PacketProvider {
+ client: retry::Client,
data: PacketData,
}
@@ -113,7 +114,7 @@ impl PacketProvider {
.send()?
.ok_or_else(|| anyhow!("metadata endpoint unreachable"))?;
- Ok(Self { data })
+ Ok(Self { client, data })
}
#[cfg(test)]
@@ -386,9 +387,8 @@ impl MetadataProvider for PacketProvider {
}
fn boot_checkin(&self) -> Result<()> {
- let client = retry::Client::try_new()?;
let url = self.data.phone_home_url.clone();
- client.post(retry::Json, url, None).dispatch_post()?;
+ self.client.post(retry::Json, url, None).dispatch_post()?;
Ok(())
}
}
--
2.39.2