MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / TEST

Function TEST

test/common/vfs_test.cpp:11–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using namespace lbug::common;
10
11TEST(VFSTests, VirtualFileSystemDeleteFiles) {
12 std::string homeDir = "/tmp/dbHome";
13 lbug::common::VirtualFileSystem vfs(homeDir);
14 std::filesystem::create_directories("/tmp/test1");
15
16 // Attempt to delete files not within the list of db files (should error)
17 try {
18 vfs.removeFileIfExists("/tmp/test1");
19 } catch (const lbug::common::IOException& e) {
20 // Expected behavior
21 EXPECT_STREQ(e.what(), "IO exception: Error: Path /tmp/test1 is not within the allowed "
22 "list of files to be removed.");
23 }
24 try {
25 vfs.removeFileIfExists("/tmp/dbHome");
26 } catch (const lbug::common::IOException& e) {
27 // Expected behavior
28 EXPECT_STREQ(e.what(), "IO exception: Error: Path /tmp/dbHome is not within the allowed "
29 "list of files to be removed.");
30 }
31
32 ASSERT_NO_THROW(vfs.removeFileIfExists("/tmp/dbHome.lock"));
33 ASSERT_NO_THROW(vfs.removeFileIfExists("/tmp/dbHome.shadow"));
34 ASSERT_NO_THROW(vfs.removeFileIfExists("/tmp/dbHome.wal"));
35 ASSERT_NO_THROW(vfs.removeFileIfExists("/tmp/dbHome.tmp"));
36
37 ASSERT_TRUE(std::filesystem::exists("/tmp/test1"));
38
39 // Cleanup: Remove directories after the test
40 std::filesystem::remove_all("/tmp/test1");
41}
42
43#ifndef __WASM__ // home directory is not available in WASM
44TEST(VFSTests, VirtualFileSystemDeleteFilesWithHome) {

Callers

nothing calls this directly

Calls 3

whatMethod · 0.80
removeFileIfExistsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected