use super::{requirement, single, source};
use crate::{
model::{
execution_workflow::ExecutionWorkflowRecord,
ic_request::IcManagementMethodRecord,
operation_plan::OperationPlanRecord,
restore_safety::{RestoreSafetyLaneRecord, RestoreSafetyRequirementRecord},
},
ops::persistence::{
BackupLayoutGuard, ExecutionStageGuard, create_operation_plan,
create_restore_safety_requirement,
},
};
use std::fs;
pub(super) struct RestoreFixture {
pub prepared: crate::tests::support::execution_workflow::PreparedStage,
pub source_layout: BackupLayoutGuard,
pub source: OperationPlanRecord,
pub requirement: RestoreSafetyRequirementRecord,
pub sequence: u64,
}
impl RestoreFixture {
pub fn new(
prefix: &str,
method: IcManagementMethodRecord,
lane: RestoreSafetyLaneRecord,
) -> Self {
let source = source();
let plan = single(method);
let sequence = plan.operations()[0].operation_sequence();
let workflow = ExecutionWorkflowRecord::new(plan.clone());
let prepared = crate::tests::support::execution_workflow::prepare_stage(
prefix,
&workflow,
sequence,
plan.clone(),
);
fs::create_dir(prepared.root.join("source")).unwrap();
let source_layout = BackupLayoutGuard::acquire(&prepared.root.join("source")).unwrap();
create_operation_plan(&source_layout, &source).unwrap();
let requirement = requirement(&plan, &source, lane);
Self {
prepared,
source_layout,
source,
requirement,
sequence,
}
}
pub fn stage(&self) -> ExecutionStageGuard<'_> {
let stage = self.prepared.open();
create_restore_safety_requirement(
stage.layout().unwrap(),
&self.source_layout,
stage.plan(),
&self.source,
&self.requirement,
)
.unwrap();
stage
}
}