Skip to content

Commit

Permalink
[tests] Check erase throws if unable to move file
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Nov 23, 2023
1 parent 3db173b commit fa2bf2e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_base_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "common.h"
#include "file_operations.h"
#include "mock_file_ops.h"
#include "mock_virtual_machine.h"
#include "path.h"

Expand Down Expand Up @@ -594,4 +595,18 @@ TEST_F(TestBaseSnapshot, eraseRemovesFile)
EXPECT_FALSE(QFileInfo{expected_filename}.exists());
}

TEST_F(TestBaseSnapshot, eraseThrowsIfUnableToRenameFile)
{
MockBaseSnapshot snapshot{"voodoo-sword", "Cursed Cutlass of Kaflu", nullptr, specs, vm};
snapshot.capture();

auto [mock_file_ops, guard] = mpt::MockFileOps::inject();
const auto expected_filename = derive_persisted_snapshot_filename(snapshot.get_index());
EXPECT_CALL(*mock_file_ops, rename(Property(&QFile::fileName, Eq(expected_filename)), _)).WillOnce(Return(false));

MP_EXPECT_THROW_THAT(snapshot.erase(),
std::runtime_error,
mpt::match_what(HasSubstr("Failed to move snapshot file")));
}

} // namespace

0 comments on commit fa2bf2e

Please sign in to comment.