add additional case in closure test and run nix-store against the

derivation
This commit is contained in:
cy 2025-05-04 13:01:36 -04:00
parent 6cfe67af0e
commit d9ca033a14
2 changed files with 36 additions and 13 deletions

View file

@ -6,8 +6,10 @@ use std::sync::Arc;
use nixcp::store::Store;
pub const HELLO: &str = "github:nixos/nixpkgs?ref=f771eb401a46846c1aebd20552521b233dd7e18b#hello";
pub const HELLO_DRV: &str = "iqbwkm8mjjjlmw6x6ry9rhzin2cp9372-hello-2.12.1.drv";
pub const HELLO_DRV: &str = "/nix/store/iqbwkm8mjjjlmw6x6ry9rhzin2cp9372-hello-2.12.1.drv";
pub const HELLO_PATH: &str = "/nix/store/9bwryidal9q3g91cjm6xschfn4ikd82q-hello-2.12.1";
pub const NIXCP_PKG: &str = "github:cything/nixcp?ref=6cfe67af0e8da502702b31f34a941753e64d9561";
pub const NIXCP_DRV: &str = "/nix/store/ldjvf9qjp980dyvka2hj99q4c0w6901x-nixcp-0.1.0.drv";
pub struct Context {
pub store: Arc<Store>,
@ -16,12 +18,7 @@ pub struct Context {
impl Context {
fn new() -> Self {
// hello must be in the store
Command::new("nix")
.arg("build")
.arg("--no-link")
.arg(HELLO)
.status()
.unwrap();
ensure_exists(HELLO);
let store = Arc::new(Store::connect().expect("connect to nix store"));
Self { store }
}
@ -30,3 +27,12 @@ impl Context {
pub fn context() -> Context {
Context::new()
}
pub fn ensure_exists(pkg: &str) {
Command::new("nix")
.arg("build")
.arg("--no-link")
.arg(pkg)
.status()
.unwrap();
}

View file

@ -3,7 +3,7 @@ use std::{collections::HashSet, path::PathBuf, process::Command};
use tempfile::TempDir;
use crate::common::{HELLO, HELLO_DRV, HELLO_PATH};
use crate::common::{HELLO, HELLO_DRV, HELLO_PATH, NIXCP_DRV, NIXCP_PKG};
mod common;
@ -14,7 +14,7 @@ async fn path_info_from_package() {
let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await
.expect("get pathinfo from package");
assert_eq!(path_info.path.to_string(), HELLO_DRV);
assert_eq!(path_info.path.to_absolute_path(), HELLO_DRV);
}
#[tokio::test]
@ -24,7 +24,7 @@ async fn path_info_from_path() {
let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await
.expect("get pathinfo from package");
assert_eq!(path_info.path.to_string(), HELLO_DRV);
assert_eq!(path_info.path.to_absolute_path(), HELLO_DRV);
}
#[tokio::test]
@ -41,7 +41,7 @@ async fn path_info_symlink() {
let path_info = PathInfo::from_derivation(&link_path, &ctx.store)
.await
.expect("get pathinfo from package");
assert_eq!(path_info.path.to_string(), HELLO_DRV);
assert_eq!(path_info.path.to_absolute_path(), HELLO_DRV);
}
#[tokio::test]
@ -53,7 +53,7 @@ async fn closure_includes_nix_store_requisites() {
.expect("get pathinfo from package");
// get what we think is the closure
let closure: HashSet<String> = path_info
let mut closure: HashSet<String> = path_info
.get_closure(&ctx.store)
.await
.unwrap()
@ -61,15 +61,32 @@ async fn closure_includes_nix_store_requisites() {
.map(|x| x.path.to_absolute_path())
.collect();
// for a somewhat more complicated case
common::ensure_exists(NIXCP_PKG);
let path = PathBuf::from(NIXCP_PKG);
let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await
.expect("get pathinfo from package");
closure.extend(
path_info
.get_closure(&ctx.store)
.await
.unwrap()
.iter()
.map(|x| x.path.to_absolute_path()),
);
// get output of `nix-store --query --requisites --include-outputs`
let nix_store_out = Command::new("nix-store")
.arg("--query")
.arg("--requisites")
.arg("--include-outputs")
.arg(HELLO_PATH)
.arg(HELLO_DRV)
.arg(NIXCP_DRV)
.output()
.unwrap()
.stdout;
assert!(!nix_store_out.is_empty());
let ref_closure = String::from_utf8_lossy(&nix_store_out);
let ref_closure = ref_closure.split_whitespace();