in focus/operations/src/testing/sync.rs [205:332]
fn sync_layer_manipulation_internal(sync_mode: SyncMode) -> Result<()> {
let snapshot_label =
SnapshotLabel::new(format!("sync_layer_manipulation_internal_{:?}", sync_mode));
init_logging();
let fixture = RepoPairFixture::with_sync_mode(sync_mode)?;
fixture.perform_clone()?;
let selected_project_names = || -> Result<HashSet<String>> {
Ok(fixture
.sparse_repo()?
.selection_manager()?
.computed_selection()?
.projects
.iter()
.filter_map(|project| {
if project.mandatory {
None
} else {
Some(project.name.to_owned())
}
})
.collect::<HashSet<String>>())
};
let project_a_label = String::from("team_banzai/project_a");
let project_b_label = String::from("team_zissou/project_b");
let path = fixture.sparse_repo_path.clone();
let library_a_dir = path.join("library_a");
let project_a_dir = path.join("project_a");
let library_b_dir = path.join("library_b");
let project_b_dir = path.join("project_b");
let profile_path = path.join(".git").join("info").join("sparse-checkout");
{
let selected_names = selected_project_names()?;
assert_eq!(selected_names, hashset! {});
}
insta::assert_snapshot!(
snapshot_label.next(),
std::fs::read_to_string(&profile_path)?
);
assert!(!library_b_dir.is_dir());
assert!(!project_b_dir.is_dir());
crate::selection::add(
&path,
true,
vec![project_b_label.clone()],
false,
fixture.app.clone(),
)?;
{
let selected_names = selected_project_names()?;
assert_eq!(selected_names, hashset! { project_b_label.clone() })
}
insta::assert_snapshot!(
snapshot_label.next(),
std::fs::read_to_string(&profile_path)?
);
assert!(library_b_dir.is_dir());
assert!(project_b_dir.is_dir());
assert!(!library_a_dir.is_dir());
assert!(!project_a_dir.is_dir());
crate::selection::add(
&path,
true,
vec![project_a_label.clone()],
false,
fixture.app.clone(),
)?;
{
let selected_names = selected_project_names()?;
assert_eq!(
selected_names,
hashset! { project_a_label.clone(), project_b_label.clone() }
)
}
insta::assert_snapshot!(
snapshot_label.next(),
std::fs::read_to_string(&profile_path)?
);
assert!(library_a_dir.is_dir());
assert!(project_a_dir.is_dir());
crate::selection::remove(
&path,
true,
vec![project_a_label],
false,
fixture.app.clone(),
)?;
{
let selected_names = selected_project_names()?;
assert_eq!(selected_names, hashset! { project_b_label.clone() })
}
insta::assert_snapshot!(
snapshot_label.next(),
std::fs::read_to_string(&profile_path)?
);
assert!(!library_a_dir.is_dir());
assert!(!project_a_dir.is_dir());
crate::selection::remove(
&path,
true,
vec![project_b_label],
false,
fixture.app.clone(),
)?;
{
let selected_names = selected_project_names()?;
assert_eq!(selected_names, hashset! {});
}
insta::assert_snapshot!(
snapshot_label.next(),
std::fs::read_to_string(&profile_path)?
);
assert!(!library_b_dir.is_dir());
assert!(!project_b_dir.is_dir());
Ok(())
}