refactor(tvix/glue/fetchers): move store_path() tests here
Move the part asking a fetch for its store_path() to the place where this function is defined, and add some more test cases. Change-Id: I96f326d0d56aa5835f23274b8cd1b1afe3724153 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11789 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
e1d3fa240a
commit
6073ef9c6f
2 changed files with 39 additions and 41 deletions
|
@ -412,32 +412,46 @@ pub(crate) fn url_basename(s: &str) -> &str {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
mod fetch {
|
||||
use nix_compat::nixbase32;
|
||||
|
||||
use crate::fetchers::Fetch;
|
||||
|
||||
use super::super::*;
|
||||
use crate::fetchers::Fetch;
|
||||
use nix_compat::{nixbase32, nixhash};
|
||||
use rstest::rstest;
|
||||
|
||||
#[test]
|
||||
fn fetchurl_store_path() {
|
||||
let url = Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap();
|
||||
let exp_hash = NixHash::Sha256(
|
||||
nixbase32::decode_fixed("0nawkl04sj7psw6ikzay7kydj3dhd0fkwghcsf5rzaw4bmp4kbax")
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let fetch = Fetch::URL {
|
||||
url,
|
||||
exp_hash: Some(exp_hash),
|
||||
};
|
||||
#[rstest]
|
||||
#[case::url_no_hash(
|
||||
Fetch::URL{
|
||||
url: Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap(),
|
||||
exp_hash: None,
|
||||
},
|
||||
None,
|
||||
"notmuch-extract-patch"
|
||||
)]
|
||||
#[case::url_sha256(
|
||||
Fetch::URL{
|
||||
url: Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap(),
|
||||
exp_hash: Some(nixhash::from_sri_str("sha256-Xa1Jbl2Eq5+L0ww+Ph1osA3Z/Dxe/RkN1/dITQCdXFk=").unwrap()),
|
||||
},
|
||||
Some(StorePathRef::from_bytes(b"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch").unwrap()),
|
||||
"notmuch-extract-patch"
|
||||
)]
|
||||
#[case::url_custom_name(
|
||||
Fetch::URL{
|
||||
url: Url::parse("https://test.example/owo").unwrap(),
|
||||
exp_hash: Some(nixhash::from_sri_str("sha256-Xa1Jbl2Eq5+L0ww+Ph1osA3Z/Dxe/RkN1/dITQCdXFk=").unwrap()),
|
||||
},
|
||||
Some(StorePathRef::from_bytes(b"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch").unwrap()),
|
||||
"notmuch-extract-patch"
|
||||
)]
|
||||
fn fetchurl_store_path(
|
||||
#[case] fetch: Fetch,
|
||||
#[case] exp_path: Option<StorePathRef>,
|
||||
#[case] name: &str,
|
||||
) {
|
||||
assert_eq!(
|
||||
"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch",
|
||||
&fetch
|
||||
.store_path("notmuch-extract-patch")
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
)
|
||||
exp_path,
|
||||
fetch.store_path(name).expect("invalid name"),
|
||||
"unexpected calculated store path"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -133,7 +133,7 @@ impl KnownPaths {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use nix_compat::{derivation::Derivation, nixbase32, nixhash::NixHash, store_path::StorePath};
|
||||
use nix_compat::{derivation::Derivation, nixbase32, nixhash, store_path::StorePath};
|
||||
use url::Url;
|
||||
|
||||
use crate::fetchers::Fetch;
|
||||
|
@ -162,7 +162,7 @@ mod tests {
|
|||
|
||||
static ref FETCH_URL : Fetch = Fetch::URL{
|
||||
url: Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap(),
|
||||
exp_hash: Some(NixHash::Sha256(nixbase32::decode_fixed("0nawkl04sj7psw6ikzay7kydj3dhd0fkwghcsf5rzaw4bmp4kbax").unwrap()))
|
||||
exp_hash: Some(nixhash::from_sri_str("sha256-Xa1Jbl2Eq5+L0ww+Ph1osA3Z/Dxe/RkN1/dITQCdXFk=").unwrap())
|
||||
};
|
||||
static ref FETCH_URL_OUT_PATH: StorePath = StorePath::from_bytes(b"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch").unwrap();
|
||||
|
||||
|
@ -267,22 +267,6 @@ mod tests {
|
|||
.unwrap()
|
||||
.to_owned()
|
||||
);
|
||||
|
||||
// We should be able to get these fetches out, when asking for their out path.
|
||||
let (got_name, got_fetch) = known_paths
|
||||
.get_fetch_for_output_path(&FETCH_URL_OUT_PATH)
|
||||
.expect("must be some");
|
||||
|
||||
assert_eq!("notmuch-extract-patch", got_name);
|
||||
assert_eq!(FETCH_URL.clone(), got_fetch);
|
||||
|
||||
// … multiple times.
|
||||
let (got_name, got_fetch) = known_paths
|
||||
.get_fetch_for_output_path(&FETCH_URL_OUT_PATH)
|
||||
.expect("must be some");
|
||||
|
||||
assert_eq!("notmuch-extract-patch", got_name);
|
||||
assert_eq!(FETCH_URL.clone(), got_fetch);
|
||||
}
|
||||
|
||||
// TODO: add test panicking about missing digest
|
||||
|
|
Loading…
Reference in a new issue