Skip to content

test(catalog): add 7 new unit tests#38

Merged
poyrazK merged 2 commits intomainfrom
feat/catalog-tests
Apr 15, 2026
Merged

test(catalog): add 7 new unit tests#38
poyrazK merged 2 commits intomainfrom
feat/catalog-tests

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented Apr 15, 2026

Summary

Add 7 new unit tests for Catalog to tests/catalog_coverage_tests.cpp.

New Tests

  1. CreateAndGetTable - create table and retrieve by ID
  2. CreateAndGetTableByName - create table and retrieve by name
  3. GetAllTables - verify get_all_tables returns created tables
  4. GetTableIndexes - verify get_table_indexes returns created indexes
  5. SaveAndLoad - verify catalog save/load cycle works
  6. VersionIncrement - verify version increments after operations
  7. PrintDoesNotCrash - verify print() doesn't crash

Test plan

  • Build passes
  • All 10 tests pass (3 existing + 7 new)

Summary by CodeRabbit

  • Tests
    • Expanded test suite with comprehensive coverage for catalog operations, including table creation and retrieval by numeric identifier and table name, complete table enumeration, index count validation, and version increment tracking after operations.
    • Added robustness and reliability tests verifying data persistence workflows and print operations execute without errors or unexpected behavior.

- CreateAndGetTable: create table and retrieve by ID
- CreateAndGetTableByName: create table and retrieve by name
- GetAllTables: verify get_all_tables returns created tables
- GetTableIndexes: verify get_table_indexes returns created indexes
- SaveAndLoad: verify catalog save/load cycle works
- VersionIncrement: verify version increments after operations
- PrintDoesNotCrash: verify print() doesn't crash
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

New unit tests added to CatalogCoverageTests covering catalog operations: table creation and retrieval by ID and name, retrieving all tables, checking table indexes, save/load persistence, print robustness, and version increment behavior.

Changes

Cohort / File(s) Summary
Catalog Coverage Tests
tests/catalog_coverage_tests.cpp
Added seven new unit test cases: create_table and get_table for numeric table ID retrieval, get_table_by_name for name-based retrieval, get_all_tables for verifying all created tables are returned, get_table_indexes for index count validation, SaveAndLoad for persistence operations, PrintDoesNotCrash for robustness, and VersionIncrement for version tracking after catalog operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hopping through tests with glee,
Tables created, retrieved with care,
Indexes checked and versions share,
Persistence tested, prints run free,
Catalog's covered, as it should be! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test(catalog): add 7 new unit tests' directly and clearly summarizes the main change—adding 7 new unit tests to the catalog test suite.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/catalog-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/catalog_coverage_tests.cpp (1)

219-223: Assert index creation success before validating index count.

If create_index fails, the current check only reports a size mismatch, which obscures the root cause. Add explicit ASSERT_NE(..., 0) for each creation.

Proposed fix
-    catalog->create_index("idx1", tid, {0}, IndexType::BTree, false);
-    catalog->create_index("idx2", tid, {0}, IndexType::Hash, true);
+    oid_t idx1 = catalog->create_index("idx1", tid, {0}, IndexType::BTree, false);
+    oid_t idx2 = catalog->create_index("idx2", tid, {0}, IndexType::Hash, true);
+    ASSERT_NE(idx1, 0);
+    ASSERT_NE(idx2, 0);

     auto indexes = catalog->get_table_indexes(tid);
     EXPECT_EQ(indexes.size(), 2);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/catalog_coverage_tests.cpp` around lines 219 - 223, The test currently
calls catalog->create_index("idx1", ...) and catalog->create_index("idx2", ...)
but then only checks indexes.size(), which hides failures to create an index;
change the test to assert each create_index call succeeded (e.g., capture their
return values and use ASSERT_NE(returned_id, 0) or equivalent) immediately after
each create_index call (referencing create_index("idx1", ...),
create_index("idx2", ...)), then proceed to call get_table_indexes(tid) and
EXPECT_EQ(indexes.size(), 2).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/catalog_coverage_tests.cpp`:
- Around line 233-250: The test TEST(CatalogCoverageTests, SaveAndLoad) uses a
fixed path "/tmp/test_catalog.bin" for catalog->save and loaded_catalog->load
which can collide in parallel runs; replace the hard-coded filename with a
unique temporary path (e.g., use std::filesystem::temp_directory_path() combined
with std::filesystem::unique_path("test_catalog_%%%%-%%%%.bin") to produce a
unique filename), store it in a local variable (temp_path.string()), use that
variable in catalog->save and loaded_catalog->load, and call
std::filesystem::remove(temp_path) for cleanup; ensure you add the necessary
`#include` <filesystem> and use std::filesystem::path for the temp file handling.
- Line 249: The test uses std::remove but doesn't include the C stdio header
directly; add a direct `#include` <cstdio> at the top of the test file so
std::remove is provided explicitly (ensure the include is placed with other
standard headers and before usage of std::remove to avoid relying on transitive
includes from common/value.hpp).

---

Nitpick comments:
In `@tests/catalog_coverage_tests.cpp`:
- Around line 219-223: The test currently calls catalog->create_index("idx1",
...) and catalog->create_index("idx2", ...) but then only checks indexes.size(),
which hides failures to create an index; change the test to assert each
create_index call succeeded (e.g., capture their return values and use
ASSERT_NE(returned_id, 0) or equivalent) immediately after each create_index
call (referencing create_index("idx1", ...), create_index("idx2", ...)), then
proceed to call get_table_indexes(tid) and EXPECT_EQ(indexes.size(), 2).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90ca860c-b5d3-466c-b060-8f286a87f1ec

📥 Commits

Reviewing files that changed from the base of the PR and between 57fc3f8 and 92cccf9.

📒 Files selected for processing (1)
  • tests/catalog_coverage_tests.cpp

Comment on lines +233 to +250
TEST(CatalogCoverageTests, SaveAndLoad) {
auto catalog = Catalog::create();
std::vector<ColumnInfo> cols = {{"id", common::ValueType::TYPE_INT64, 0}};
catalog->create_table("persisted_table", cols);

// Save catalog - should succeed
ASSERT_TRUE(catalog->save("/tmp/test_catalog.bin"));

// Create new catalog and load - should succeed (returns true)
auto loaded_catalog = Catalog::create();
ASSERT_TRUE(loaded_catalog->load("/tmp/test_catalog.bin"));

// Note: Due to stub implementation, loaded catalog won't have the table
// This test verifies the save/load cycle works without crashing

// Cleanup
std::remove("/tmp/test_catalog.bin");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid fixed temp filename in SaveAndLoad to prevent test flakiness.

Using "/tmp/test_catalog.bin" on Line [239], Line [243], and Line [249] introduces cross-test collisions in parallel runs and is platform-fragile.

Proposed fix
+#include <chrono>
+#include <filesystem>
+
 TEST(CatalogCoverageTests, SaveAndLoad) {
     auto catalog = Catalog::create();
     std::vector<ColumnInfo> cols = {{"id", common::ValueType::TYPE_INT64, 0}};
     catalog->create_table("persisted_table", cols);

+    const auto unique_suffix =
+        std::to_string(std::chrono::steady_clock::now().time_since_epoch().count());
+    const auto test_file =
+        (std::filesystem::temp_directory_path() / ("test_catalog_" + unique_suffix + ".bin"))
+            .string();
+
     // Save catalog - should succeed
-    ASSERT_TRUE(catalog->save("/tmp/test_catalog.bin"));
+    ASSERT_TRUE(catalog->save(test_file));

     // Create new catalog and load - should succeed (returns true)
     auto loaded_catalog = Catalog::create();
-    ASSERT_TRUE(loaded_catalog->load("/tmp/test_catalog.bin"));
+    ASSERT_TRUE(loaded_catalog->load(test_file));

     // Note: Due to stub implementation, loaded catalog won't have the table
     // This test verifies the save/load cycle works without crashing

     // Cleanup
-    std::remove("/tmp/test_catalog.bin");
+    EXPECT_EQ(std::remove(test_file.c_str()), 0);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
TEST(CatalogCoverageTests, SaveAndLoad) {
auto catalog = Catalog::create();
std::vector<ColumnInfo> cols = {{"id", common::ValueType::TYPE_INT64, 0}};
catalog->create_table("persisted_table", cols);
// Save catalog - should succeed
ASSERT_TRUE(catalog->save("/tmp/test_catalog.bin"));
// Create new catalog and load - should succeed (returns true)
auto loaded_catalog = Catalog::create();
ASSERT_TRUE(loaded_catalog->load("/tmp/test_catalog.bin"));
// Note: Due to stub implementation, loaded catalog won't have the table
// This test verifies the save/load cycle works without crashing
// Cleanup
std::remove("/tmp/test_catalog.bin");
}
`#include` <chrono>
`#include` <filesystem>
TEST(CatalogCoverageTests, SaveAndLoad) {
auto catalog = Catalog::create();
std::vector<ColumnInfo> cols = {{"id", common::ValueType::TYPE_INT64, 0}};
catalog->create_table("persisted_table", cols);
const auto unique_suffix =
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count());
const auto test_file =
(std::filesystem::temp_directory_path() / ("test_catalog_" + unique_suffix + ".bin"))
.string();
// Save catalog - should succeed
ASSERT_TRUE(catalog->save(test_file));
// Create new catalog and load - should succeed (returns true)
auto loaded_catalog = Catalog::create();
ASSERT_TRUE(loaded_catalog->load(test_file));
// Note: Due to stub implementation, loaded catalog won't have the table
// This test verifies the save/load cycle works without crashing
// Cleanup
EXPECT_EQ(std::remove(test_file.c_str()), 0);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/catalog_coverage_tests.cpp` around lines 233 - 250, The test
TEST(CatalogCoverageTests, SaveAndLoad) uses a fixed path
"/tmp/test_catalog.bin" for catalog->save and loaded_catalog->load which can
collide in parallel runs; replace the hard-coded filename with a unique
temporary path (e.g., use std::filesystem::temp_directory_path() combined with
std::filesystem::unique_path("test_catalog_%%%%-%%%%.bin") to produce a unique
filename), store it in a local variable (temp_path.string()), use that variable
in catalog->save and loaded_catalog->load, and call
std::filesystem::remove(temp_path) for cleanup; ensure you add the necessary
`#include` <filesystem> and use std::filesystem::path for the temp file handling.

// This test verifies the save/load cycle works without crashing

// Cleanup
std::remove("/tmp/test_catalog.bin");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify std::remove usage and direct header presence in this test TU.
rg -n 'std::remove\(' tests/catalog_coverage_tests.cpp -C2
rg -n '^#include <cstdio>' tests/catalog_coverage_tests.cpp -C1

Repository: poyrazK/cloudSQL

Length of output: 140


🏁 Script executed:

rg -n '^#include' tests/catalog_coverage_tests.cpp

Repository: poyrazK/cloudSQL

Length of output: 233


🏁 Script executed:

rg -n '#include <cstdio>' catalog/catalog.hpp common/value.hpp distributed/raft_types.hpp

Repository: poyrazK/cloudSQL

Length of output: 243


🏁 Script executed:

fd -type f 'catalog\.hpp|value\.hpp|raft_types\.hpp' --max-one-result

Repository: poyrazK/cloudSQL

Length of output: 230


🏁 Script executed:

fd 'catalog\.hpp|value\.hpp|raft_types\.hpp'

Repository: poyrazK/cloudSQL

Length of output: 147


🏁 Script executed:

rg '#include <cstdio>' include/catalog/catalog.hpp include/common/value.hpp include/distributed/raft_types.hpp

Repository: poyrazK/cloudSQL

Length of output: 102


Add direct <cstdio> include for std::remove.

Line 249 calls std::remove; while the C standard library function is currently accessible through a transitive include from "common/value.hpp", relying on transitive includes is brittle and can break if that header's dependencies change. Adding an explicit #include <cstdio> makes the dependency clear and robust.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/catalog_coverage_tests.cpp` at line 249, The test uses std::remove but
doesn't include the C stdio header directly; add a direct `#include` <cstdio> at
the top of the test file so std::remove is provided explicitly (ensure the
include is placed with other standard headers and before usage of std::remove to
avoid relying on transitive includes from common/value.hpp).

Copy link
Copy Markdown
Owner Author

@poyrazK poyrazK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to add those new catalog unit services

@poyrazK poyrazK merged commit 5fba9c0 into main Apr 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant