Skip to content

Commit 32a77ca

Browse files
committed
test: add unit test for snapshot (de)serialization
This is covered by rust intergration tests, but having a unit test that does the snapshot/restore roundtrip is nice, because I can run it on my laptop without needing sudo. Signed-off-by: Patrick Roy <[email protected]>
1 parent feb4bc1 commit 32a77ca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/vmm/src/snapshot/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,20 @@ impl<Data: Serialize> Snapshot<Data> {
187187

188188
#[cfg(test)]
189189
mod tests {
190+
use vmm_sys_util::tempfile::TempFile;
191+
190192
use super::*;
193+
use crate::persist::MicrovmState;
194+
195+
#[test]
196+
fn test_snapshot_restore() {
197+
let state = MicrovmState::default();
198+
let file = TempFile::new().unwrap();
199+
200+
Snapshot::new(state).save(&mut file.as_file()).unwrap();
201+
file.as_file().seek(SeekFrom::Start(0)).unwrap();
202+
Snapshot::<MicrovmState>::load(&mut file.as_file()).unwrap();
203+
}
191204

192205
#[test]
193206
fn test_parse_version_from_file() {

0 commit comments

Comments
 (0)