mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
feat: convert linehaul tests to use snapshots (#2923)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Closes #2564 ## Test Plan 1. Changed existing linehaul tests to leverage insta. 2. Ran tests in various linux distros (Debian, Ubuntu, Centos, Fedora, Alpine) to ensure they also pass locally again. --------- Co-authored-by: konstin <konstin@mailbox.org>
This commit is contained in:
parent
c85c52d4ce
commit
7c7f06f62b
3 changed files with 128 additions and 45 deletions
|
@ -51,5 +51,5 @@ anyhow = { workspace = true }
|
|||
http-body-util = { version = "0.1.0" }
|
||||
hyper = { version = "1.2.0", features = ["server", "http1"] }
|
||||
hyper-util = { version = "0.1.3", features = ["tokio"] }
|
||||
insta = { version = "1.36.1" }
|
||||
insta = { version = "1.36.1" , features = ["filters", "json", "redactions"] }
|
||||
tokio = { workspace = true, features = ["fs", "macros"] }
|
||||
|
|
|
@ -7,10 +7,10 @@ use hyper::server::conn::http1;
|
|||
use hyper::service::service_fn;
|
||||
use hyper::{Request, Response};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use insta::{assert_json_snapshot, assert_snapshot, with_settings};
|
||||
use pep508_rs::{MarkerEnvironment, StringVersion};
|
||||
use platform_tags::{Arch, Os, Platform};
|
||||
use tokio::net::TcpListener;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::LineHaul;
|
||||
use uv_client::RegistryClientBuilder;
|
||||
|
@ -179,52 +179,82 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
|
|||
// Deserializing Linehaul
|
||||
let linehaul: LineHaul = serde_json::from_str(uv_linehaul)?;
|
||||
|
||||
// Assert uv version
|
||||
assert_eq!(uv_version, format!("uv/{}", version()));
|
||||
|
||||
// Assert linehaul
|
||||
let installer_info = linehaul.installer.unwrap();
|
||||
let system_info = linehaul.system.unwrap();
|
||||
let impl_info = linehaul.implementation.unwrap();
|
||||
|
||||
assert_eq!(installer_info.name.as_deref(), Some("uv"));
|
||||
assert_eq!(installer_info.version.as_deref(), Some(version()));
|
||||
|
||||
assert_eq!(system_info.name, Some(markers.platform_system));
|
||||
assert_eq!(system_info.release, Some(markers.platform_release));
|
||||
|
||||
assert_eq!(impl_info.name, Some(markers.platform_python_implementation));
|
||||
assert_eq!(
|
||||
impl_info.version,
|
||||
Some(markers.python_full_version.version.to_string())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
linehaul.python,
|
||||
Some(markers.python_full_version.version.to_string())
|
||||
);
|
||||
assert_eq!(linehaul.cpu, Some(markers.platform_machine));
|
||||
|
||||
assert_eq!(linehaul.openssl_version, None);
|
||||
assert_eq!(linehaul.setuptools_version, None);
|
||||
assert_eq!(linehaul.rustc_version, None);
|
||||
// Assert linehaul user agent
|
||||
let filters = vec![(version(), "[VERSION]")];
|
||||
with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
// Assert uv version
|
||||
assert_snapshot!(uv_version, @"uv/[VERSION]");
|
||||
// Assert linehaul json
|
||||
assert_json_snapshot!(&linehaul, {
|
||||
".distro" => "[distro]",
|
||||
".ci" => "[ci]"
|
||||
}, @r###"
|
||||
{
|
||||
"installer": {
|
||||
"name": "uv",
|
||||
"version": "[VERSION]"
|
||||
},
|
||||
"python": "3.12.2",
|
||||
"implementation": {
|
||||
"name": "CPython",
|
||||
"version": "3.12.2"
|
||||
},
|
||||
"distro": "[distro]",
|
||||
"system": {
|
||||
"name": "Linux",
|
||||
"release": "6.5.0-1016-azure"
|
||||
},
|
||||
"cpu": "x86_64",
|
||||
"openssl_version": null,
|
||||
"setuptools_version": null,
|
||||
"rustc_version": null,
|
||||
"ci": "[ci]"
|
||||
}
|
||||
"###);
|
||||
});
|
||||
|
||||
// Assert distro
|
||||
if cfg!(windows) {
|
||||
assert_eq!(linehaul.distro, None);
|
||||
assert_json_snapshot!(&linehaul.distro, @"null");
|
||||
} else if cfg!(target_os = "linux") {
|
||||
let Some(distro_info) = linehaul.distro else {
|
||||
panic!("got no distro, but expected one in linehaul")
|
||||
};
|
||||
assert_eq!(distro_info.id.as_deref(), Some("jammy"));
|
||||
assert_eq!(distro_info.name.as_deref(), Some("Ubuntu"));
|
||||
assert_eq!(distro_info.version.as_deref(), Some("22.04"));
|
||||
assert!(distro_info.libc.is_some());
|
||||
assert_json_snapshot!(&linehaul.distro, {
|
||||
".id" => "[distro.id]",
|
||||
".name" => "[distro.name]",
|
||||
".version" => "[distro.version]"
|
||||
// We mock the libc version already
|
||||
}, @r###"
|
||||
{
|
||||
"name": "[distro.name]",
|
||||
"version": "[distro.version]",
|
||||
"id": "[distro.id]",
|
||||
"libc": {
|
||||
"lib": "glibc",
|
||||
"version": "2.38"
|
||||
}
|
||||
}"###
|
||||
);
|
||||
// Check dynamic values
|
||||
let distro_info = linehaul
|
||||
.distro
|
||||
.expect("got no distro, but expected one in linehaul");
|
||||
// Gather distribution info from /etc/os-release.
|
||||
let release_info = sys_info::linux_os_release()
|
||||
.expect("got no os release info, but expected one in linux");
|
||||
assert_eq!(distro_info.id, release_info.version_codename);
|
||||
assert_eq!(distro_info.name, release_info.name);
|
||||
assert_eq!(distro_info.version, release_info.version_id);
|
||||
} else if cfg!(target_os = "macos") {
|
||||
let distro_info = linehaul.distro.unwrap();
|
||||
assert_eq!(distro_info.id, None);
|
||||
assert_eq!(distro_info.name.as_deref(), Some("macOS"));
|
||||
assert_eq!(distro_info.version.as_deref(), Some("14.4"));
|
||||
assert_eq!(distro_info.libc, None);
|
||||
// We mock the macOS distro
|
||||
assert_json_snapshot!(&linehaul.distro, @r###"
|
||||
{
|
||||
"name": "macOS",
|
||||
"version": "14.4",
|
||||
"id": null,
|
||||
"libc": null
|
||||
}"###
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue