kingfisher/tests/smoke_update.rs

52 lines
1.5 KiB
Rust
Raw Normal View History

2025-06-24 20:17:40 -07:00
use kingfisher::{cli::global::GlobalArgs, update::check_for_update};
use tokio;
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
};
2025-06-24 17:17:16 -07:00
2025-06-24 20:17:40 -07:00
#[tokio::test]
async fn no_update_when_flag_set() {
let args = GlobalArgs { no_update_check: true, ..Default::default() };
let status = check_for_update(&args, None);
assert_eq!(status.check_status.as_str(), "disabled");
assert!(status.latest_version.is_none());
2025-06-24 20:17:40 -07:00
}
2025-06-24 17:17:16 -07:00
2025-06-24 20:17:40 -07:00
#[tokio::test]
async fn detects_new_release() {
let server = MockServer::start().await;
2025-06-24 17:17:16 -07:00
2025-06-24 20:17:40 -07:00
let body = serde_json::json!({
"tag_name": "v99.999.0",
2025-06-24 20:17:40 -07:00
"created_at": "2025-01-01T00:00:00Z",
"name": "Kingfisher 99.999.0",
2025-06-24 20:17:40 -07:00
"body": "",
"assets": [{"url": "http://example.com/bin", "name": "bin"}]
});
2025-06-24 17:17:16 -07:00
2025-06-24 20:17:40 -07:00
// Stub HEAD *and* GET
for m in ["HEAD", "GET"] {
Mock::given(method(m))
.and(path("/repos/mongodb/kingfisher/releases/latest"))
.respond_with(ResponseTemplate::new(200).set_body_json(&body))
.mount(&server)
.await;
}
2025-06-24 17:17:16 -07:00
2025-06-24 20:17:40 -07:00
// run the update checker on a blocking thread
let status = tokio::task::spawn_blocking({
2025-06-24 20:17:40 -07:00
let uri = server.uri(); // move into closure
let args = GlobalArgs::default();
move || check_for_update(&args, Some(&uri))
})
.await
.expect("blocking task panicked");
2025-06-24 17:17:16 -07:00
assert!(status.is_outdated);
2025-11-24 11:08:31 -08:00
assert!(status
.message
.as_deref()
.expect("update check should return a message")
.contains("99.999.0"));
2025-06-24 20:17:40 -07:00
}