Skip to content

Commit e735bce

Browse files
authored
Merge pull request #40 from poyrazK/feat/catalog-tests-fixes
test(catalog): fix CodeRabbit review findings
2 parents b3e07d1 + c06dc51 commit e735bce

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tests/catalog_coverage_tests.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
* @brief Targeted unit tests to increase coverage of the Catalog module
44
*/
55

6+
#include <fcntl.h>
67
#include <gtest/gtest.h>
8+
#include <unistd.h>
79

10+
#include <cstdio>
811
#include <cstring>
12+
#include <filesystem>
913
#include <vector>
1014

1115
#include "catalog/catalog.hpp"
@@ -216,8 +220,10 @@ TEST(CatalogCoverageTests, GetTableIndexes) {
216220
oid_t tid = catalog->create_table("indexed_table", cols);
217221
ASSERT_NE(tid, 0);
218222

219-
catalog->create_index("idx1", tid, {0}, IndexType::BTree, false);
220-
catalog->create_index("idx2", tid, {0}, IndexType::Hash, true);
223+
oid_t idx1_id = catalog->create_index("idx1", tid, {0}, IndexType::BTree, false);
224+
ASSERT_NE(idx1_id, 0);
225+
oid_t idx2_id = catalog->create_index("idx2", tid, {0}, IndexType::Hash, true);
226+
ASSERT_NE(idx2_id, 0);
221227

222228
auto indexes = catalog->get_table_indexes(tid);
223229
EXPECT_EQ(indexes.size(), 2);
@@ -235,18 +241,22 @@ TEST(CatalogCoverageTests, SaveAndLoad) {
235241
std::vector<ColumnInfo> cols = {{"id", common::ValueType::TYPE_INT64, 0}};
236242
catalog->create_table("persisted_table", cols);
237243

238-
// Save catalog - should succeed
239-
ASSERT_TRUE(catalog->save("/tmp/test_catalog.bin"));
244+
// save() and load() are stubs that don't fully persist table data.
245+
// save() writes a header comment but no table data.
246+
// load() reads but doesn't parse table entries.
247+
// This test verifies the save/load cycle works without crashing.
248+
std::string temp_path = "./test_data/catalog_save_load_test.bin";
249+
std::filesystem::remove(temp_path);
240250

241-
// Create new catalog and load - should succeed (returns true)
242-
auto loaded_catalog = Catalog::create();
243-
ASSERT_TRUE(loaded_catalog->load("/tmp/test_catalog.bin"));
251+
// Save catalog - stub implementation writes header only
252+
EXPECT_NO_THROW(catalog->save(temp_path));
244253

245-
// Note: Due to stub implementation, loaded catalog won't have the table
246-
// This test verifies the save/load cycle works without crashing
254+
// Create new catalog and load - stub implementation returns true
255+
auto loaded_catalog = Catalog::create();
256+
EXPECT_NO_THROW(loaded_catalog->load(temp_path));
247257

248258
// Cleanup
249-
std::remove("/tmp/test_catalog.bin");
259+
std::filesystem::remove(temp_path);
250260
}
251261

252262
/**

0 commit comments

Comments
 (0)