Files
imeai-aKode/akode-rs/cli/tests/update.rs

64 lines
1.8 KiB
Rust

use anyhow::Result;
use predicates::str::contains;
use std::path::Path;
use tempfile::TempDir;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
const LATEST_PATH: &str = "/api/v1/repos/andrea/imeai-aKode/releases/latest";
fn akode_update(akode_home: &Path, server: &MockServer) -> Result<assert_cmd::Command> {
let mut cmd = assert_cmd::Command::new(akode_utils_cargo_bin::cargo_bin("akode")?);
cmd.env("AKODE_HOME", akode_home).args([
"-c",
&format!("update.repo_url=\"{}/andrea/imeai-aKode\"", server.uri()),
"update",
]);
Ok(cmd)
}
#[tokio::test]
async fn update_without_published_release_reports_up_to_date() -> Result<()> {
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path(LATEST_PATH))
.respond_with(ResponseTemplate::new(404))
.expect(1)
.mount(&server)
.await;
let akode_home = TempDir::new()?;
akode_update(akode_home.path(), &server)?
.assert()
.success()
.stdout(contains("Nessuna release pubblicata"));
Ok(())
}
#[tokio::test]
async fn update_check_reports_newer_release_without_installing() -> Result<()> {
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path(LATEST_PATH))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"tag_name": "v999.0.0",
"assets": [],
})))
.expect(1)
.mount(&server)
.await;
let akode_home = TempDir::new()?;
akode_update(akode_home.path(), &server)?
.arg("--check")
.assert()
.success()
.stdout(contains("È disponibile aKode 999.0.0"));
Ok(())
}