add path_info tests
This commit is contained in:
parent
7285c29e88
commit
878e096494
4 changed files with 70 additions and 2 deletions
|
@ -5,7 +5,7 @@ use clap::{Args, Parser, Subcommand};
|
||||||
mod bindings;
|
mod bindings;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod make_nar;
|
mod make_nar;
|
||||||
mod path_info;
|
pub mod path_info;
|
||||||
pub mod push;
|
pub mod push;
|
||||||
pub mod store;
|
pub mod store;
|
||||||
mod uploader;
|
mod uploader;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result, anyhow};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use nix_compat::nixbase32;
|
use nix_compat::nixbase32;
|
||||||
use nix_compat::store_path::StorePath;
|
use nix_compat::store_path::StorePath;
|
||||||
|
@ -41,6 +41,12 @@ impl PathInfo {
|
||||||
let derivation = String::from_utf8_lossy(derivation);
|
let derivation = String::from_utf8_lossy(derivation);
|
||||||
debug!("derivation: {derivation}");
|
debug!("derivation: {derivation}");
|
||||||
|
|
||||||
|
if derivation.is_empty() {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"nix path-info did not return a derivation for {path:#?}"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let store_path = StorePath::from_absolute_path(derivation.trim().as_bytes())
|
let store_path = StorePath::from_absolute_path(derivation.trim().as_bytes())
|
||||||
.context("storepath from derivation")?;
|
.context("storepath from derivation")?;
|
||||||
store
|
store
|
||||||
|
|
16
tests/common/mod.rs
Normal file
16
tests/common/mod.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use nixcp::store::Store;
|
||||||
|
|
||||||
|
pub struct Context {
|
||||||
|
pub store: Store,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Context {
|
||||||
|
fn new() -> Self {
|
||||||
|
let store = Store::connect().expect("connect to nix store");
|
||||||
|
Self { store }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn context() -> Context {
|
||||||
|
Context::new()
|
||||||
|
}
|
46
tests/path_info.rs
Normal file
46
tests/path_info.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
use nixcp::path_info::PathInfo;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
const HELLO: &str = "github:nixos/nixpkgs?ref=f771eb401a46846c1aebd20552521b233dd7e18b#hello";
|
||||||
|
const HELLO_DRV: &str = "iqbwkm8mjjjlmw6x6ry9rhzin2cp9372-hello-2.12.1.drv";
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn path_info_from_package() {
|
||||||
|
let ctx = common::context();
|
||||||
|
let path = PathBuf::from(HELLO);
|
||||||
|
let path_info = PathInfo::from_path(&path, &ctx.store)
|
||||||
|
.await
|
||||||
|
.expect("get pathinfo from package");
|
||||||
|
assert_eq!(path_info.path.to_string(), HELLO_DRV);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn path_info_from_path() {
|
||||||
|
// the path must be in the store
|
||||||
|
Command::new("nix")
|
||||||
|
.arg("build")
|
||||||
|
.arg("--no-link")
|
||||||
|
.arg(HELLO)
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
let ctx = common::context();
|
||||||
|
let path = PathBuf::from("/nix/store/9bwryidal9q3g91cjm6xschfn4ikd82q-hello-2.12.1");
|
||||||
|
let path_info = PathInfo::from_path(&path, &ctx.store)
|
||||||
|
.await
|
||||||
|
.expect("get pathinfo from package");
|
||||||
|
assert_eq!(path_info.path.to_string(), HELLO_DRV);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn closure() {
|
||||||
|
let ctx = common::context();
|
||||||
|
let path = PathBuf::from(HELLO);
|
||||||
|
let path_info = PathInfo::from_path(&path, &ctx.store)
|
||||||
|
.await
|
||||||
|
.expect("get pathinfo from package");
|
||||||
|
let closure = path_info.get_closure(&ctx.store).await.unwrap();
|
||||||
|
assert_eq!(closure.len(), 466);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue