Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for graph::Manifest conversion from tracking::Manifest #1014

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 100 additions & 1 deletion crates/spfs/src/graph/entry_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rstest::rstest;
use super::EntryBuf;
use crate::encoding::{self};
use crate::fixtures::*;
use crate::tracking::EntryKind;
use crate::tracking::{self, EntryKind};

#[rstest(entry, digest,
case(
Expand Down Expand Up @@ -41,3 +41,102 @@ fn test_entry_encoding_compat(entry: EntryBuf, digest: encoding::Digest) {
"expected encoding to match existing result"
);
}

#[rstest]
fn test_entry_blobs_compare_name() {
let a = EntryBuf::build(
"a",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let b = EntryBuf::build(
"b",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(a.as_entry() < b.as_entry());
assert!(b.as_entry() > a.as_entry());
}

#[rstest]
fn test_entry_trees_compare_name() {
let a = EntryBuf::build(
"a",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let b = EntryBuf::build(
"b",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(a.as_entry() < b.as_entry());
assert!(b.as_entry() > a.as_entry());
}

#[rstest]
fn test_entry_mask_compare_name() {
let a = EntryBuf::build(
"a",
tracking::EntryKind::Mask,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let b = EntryBuf::build(
"b",
tracking::EntryKind::Mask,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(a.as_entry() < b.as_entry());
assert!(b.as_entry() > a.as_entry());
}

#[rstest]
fn test_entry_compare_kind() {
let blob = EntryBuf::build(
"a",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let tree = EntryBuf::build(
"b",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(tree.as_entry() > blob.as_entry());
assert!(blob.as_entry() < tree.as_entry());
}

#[rstest]
fn test_entry_compare() {
let root_file = EntryBuf::build(
"file",
tracking::EntryKind::Blob,
0,
0,
&encoding::NULL_DIGEST.into(),
);
let root_dir = EntryBuf::build(
"xdir",
tracking::EntryKind::Tree,
0,
0,
&encoding::NULL_DIGEST.into(),
);
assert!(root_dir.as_entry() > root_file.as_entry());
}
101 changes: 26 additions & 75 deletions crates/spfs/src/graph/manifest_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,35 @@

use rstest::rstest;

use crate::graph::entry::EntryBuf;
use crate::{encoding, tracking};
use super::Manifest;
use crate::tracking::{self, EntryKind};

#[rstest]
fn test_entry_blobs_compare_name() {
let a = EntryBuf::build(
"a",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let b = EntryBuf::build(
"b",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(a.as_entry() < b.as_entry());
assert!(b.as_entry() > a.as_entry());
}
fn test_manifest_from_tracking_manifest() {
// Test a situation where the first entry in a tracking manifest
// is a mask, the second entry is blob, the mask and blob do not
// have the same name, and the manifest is converted to a graph
// manifest. The manifest should not lose the blob in the
// conversion.

#[rstest]
fn test_entry_trees_compare_name() {
let a = EntryBuf::build(
"a",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let b = EntryBuf::build(
"b",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(a.as_entry() < b.as_entry());
assert!(b.as_entry() > a.as_entry());
}
// Set up the manifest with a mask and file with different names.
let mut p = tracking::Manifest::<()>::default();
let node = p.mkfile("pip-21.2.3.dist-info").unwrap();
node.kind = EntryKind::Mask;

#[rstest]
fn test_entry_compare_kind() {
let blob = EntryBuf::build(
"a",
tracking::EntryKind::Blob,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
let tree = EntryBuf::build(
"b",
tracking::EntryKind::Tree,
0,
0,
&encoding::EMPTY_DIGEST.into(),
);
assert!(tree.as_entry() > blob.as_entry());
assert!(blob.as_entry() < tree.as_entry());
}
let mut t = tracking::Manifest::<()>::default();
t.mkfile("typing_extensions.py").unwrap();

#[rstest]
fn test_entry_compare() {
let root_file = EntryBuf::build(
"file",
tracking::EntryKind::Blob,
0,
0,
&encoding::NULL_DIGEST.into(),
);
let root_dir = EntryBuf::build(
"xdir",
tracking::EntryKind::Tree,
0,
0,
&encoding::NULL_DIGEST.into(),
);
assert!(root_dir.as_entry() > root_file.as_entry());
let mut tm = tracking::Manifest::<()>::default();
tm.update(&p);
tm.update(&t);

// Test convert to a graphing manifest, and back
println!("tm: {:?}", tm);
let gm: Manifest = tm.to_graph_manifest();
println!("gm: {:?}", gm);
let gm2tm = gm.to_tracking_manifest();
println!("gm2tm: {:?}", gm2tm);

assert!(tm == gm2tm);
}
Loading