Skip to content

Commit fa2bf2e

Browse files
committed
[tests] Check erase throws if unable to move file
1 parent 3db173b commit fa2bf2e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_base_snapshot.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "common.h"
1919
#include "file_operations.h"
20+
#include "mock_file_ops.h"
2021
#include "mock_virtual_machine.h"
2122
#include "path.h"
2223

@@ -594,4 +595,18 @@ TEST_F(TestBaseSnapshot, eraseRemovesFile)
594595
EXPECT_FALSE(QFileInfo{expected_filename}.exists());
595596
}
596597

598+
TEST_F(TestBaseSnapshot, eraseThrowsIfUnableToRenameFile)
599+
{
600+
MockBaseSnapshot snapshot{"voodoo-sword", "Cursed Cutlass of Kaflu", nullptr, specs, vm};
601+
snapshot.capture();
602+
603+
auto [mock_file_ops, guard] = mpt::MockFileOps::inject();
604+
const auto expected_filename = derive_persisted_snapshot_filename(snapshot.get_index());
605+
EXPECT_CALL(*mock_file_ops, rename(Property(&QFile::fileName, Eq(expected_filename)), _)).WillOnce(Return(false));
606+
607+
MP_EXPECT_THROW_THAT(snapshot.erase(),
608+
std::runtime_error,
609+
mpt::match_what(HasSubstr("Failed to move snapshot file")));
610+
}
611+
597612
} // namespace

0 commit comments

Comments
 (0)