Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Aug 20, 2025

Description

LCORE-574: Unit tests for PostgreSQL configuration + removed unused check

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-574

Summary by CodeRabbit

  • New Features

    • Added configurable PostgreSQL connection settings with sensible defaults (host, port, namespace).
    • Introduced default values for SSL mode and GSS encryption mode.
  • Bug Fixes

    • Refined PostgreSQL configuration validation: improved port checks and adjusted CA certificate path handling to apply only when provided.
  • Tests

    • Added unit tests covering PostgreSQL configuration defaults, port range validation, and CA certificate path behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

Walkthrough

Removed CA certificate path validation from PostgreSQL configuration in src/models/config.py. Added/updated unit tests in tests/unit/models/test_config.py that validate defaults, port constraints, and CA certificate file-path behavior, and reference new constants for default SSL/GSS enc modes.

Changes

Cohort / File(s) Summary
Config validation change
src/models/config.py
Deleted CA certificate existence check in PostgreSQLDatabaseConfiguration.check_postgres_configuration; now only validates port range and returns self. No public API declarations changed in this file per summary.
Unit tests for PostgreSQL config
tests/unit/models/test_config.py
Added tests for PostgreSQLDatabaseConfiguration defaults, port validation (>0 and <65536), and CA certificate path validation. Tests reference POSTGRES_DEFAULT_SSL_MODE and POSTGRES_DEFAULT_GSS_ENCMODE constants.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit taps keys with a gentle thump,
Snips out a cert check—hop, skip, jump.
Tests now peek at ports and paths,
SSL whispers, GSS laughs.
In burrows of config, neat and tight,
We nibble the code till it feels just right. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
tests/unit/models/test_config.py (2)

912-933: Parametrize CA cert path tests for clarity and to drop subtests dependency.

This reduces boilerplate and avoids relying on pytest-subtests.

-def test_postgresql_database_configuration_ca_cert_path(subtests) -> None:
-    """Test the PostgreSQLDatabaseConfiguration model."""
-    with subtests.test(msg="Path exists"):
-        c = PostgreSQLDatabaseConfiguration(
-            db="db",
-            user="user",
-            password="password",
-            port=1234,
-            ca_cert_path=Path("tests/configuration/server.crt"),
-        )
-        assert c.ca_cert_path == Path("tests/configuration/server.crt")
-
-    with subtests.test(msg="Path does not exist"):
-        with pytest.raises(ValidationError, match="Path does not point to a file"):
-            PostgreSQLDatabaseConfiguration(
-                db="db",
-                user="user",
-                password="password",
-                port=1234,
-                ca_cert_path=Path("not a file"),
-            )
+@pytest.mark.parametrize(
+    "ca_path,exc,pattern",
+    [
+        (Path("tests/configuration/server.crt"), None, None),
+        (Path("not a file"), ValidationError, "Path does not point to a file"),
+    ],
+)
+def test_postgresql_database_configuration_ca_cert_path(ca_path, exc, pattern) -> None:
+    """Test the PostgreSQLDatabaseConfiguration ca_cert_path validation."""
+    if exc is None:
+        c = PostgreSQLDatabaseConfiguration(
+            db="db", user="user", password="password", port=1234, ca_cert_path=ca_path
+        )
+        assert c.ca_cert_path == ca_path
+    else:
+        with pytest.raises(exc, match=pattern):
+            PostgreSQLDatabaseConfiguration(
+                db="db", user="user", password="password", port=1234, ca_cert_path=ca_path
+            )

If subtests must be kept, please ensure pytest-subtests is declared in your test dependencies (see the script in the previous comment).


890-910: pytest-subtests plugin is already declared; parametrize refactor is optional

The pytest-subtests dependency is present in pyproject.toml (line 95), so you don’t need to add it if you choose to keep using subtests. However, you may still opt for a more idiomatic pytest style by switching to @pytest.mark.parametrize.

• Dependency found:
– pyproject.toml, line 95: pytest-subtests>=0.14.2

• Optional refactor (no dependency change required):

- def test_postgresql_database_configuration_port_setting(subtests) -> None:
-     """Test the PostgreSQLDatabaseConfiguration model."""
-     with subtests.test(msg="Correct port value"):
-         c = PostgreSQLDatabaseConfiguration(db="db", user="user", password="password", port=1234)
-         assert c is not None
-         assert c.port == 1234
-
-     with subtests.test(msg="Negative port value"):
-         with pytest.raises(ValidationError, match="Input should be greater than 0"):
-             PostgreSQLDatabaseConfiguration(db="db", user="user", password="password", port=-1)
-
-     with subtests.test(msg="Too big port value"):
-         with pytest.raises(ValueError, match="Port value should be less than 65536"):
-             PostgreSQLDatabaseConfiguration(db="db", user="user", password="password", port=100000)
+ @pytest.mark.parametrize(
+     "port,exc,pattern",
+     [
+         (1234, None, None),
+         (-1, ValidationError, "Input should be greater than 0"),
+         (100000, ValueError, "Port value should be less than 65536"),
+     ],
+ )
+ def test_postgresql_database_configuration_port_setting(port, exc, pattern) -> None:
+     """Test the PostgreSQLDatabaseConfiguration port validation."""
+     if exc is None:
+         c = PostgreSQLDatabaseConfiguration(db="db", user="user", password="password", port=port)
+         assert c is not None
+         assert c.port == port
+     else:
+         with pytest.raises(exc, match=pattern):
+             PostgreSQLDatabaseConfiguration(db="db", user="user", password="password", port=port)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 19cc14d and 96c341c.

📒 Files selected for processing (2)
  • src/models/config.py (0 hunks)
  • tests/unit/models/test_config.py (3 hunks)
💤 Files with no reviewable changes (1)
  • src/models/config.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests
🔇 Additional comments (3)
tests/unit/models/test_config.py (3)

14-16: Good call using constants for Postgres defaults.

Referencing POSTGRES_DEFAULT_SSL_MODE and POSTGRES_DEFAULT_GSS_ENCMODE keeps tests resilient to value changes.


29-29: Import of PostgreSQLDatabaseConfiguration looks correct.

Consistent with other model imports from models.config.


875-888: Solid coverage of PostgreSQL defaults.

Asserts for host, port, namespace, and SSL/GSS encmode defaults are clear and aligned with expectations.

@tisnik tisnik merged commit 45eb299 into lightspeed-core:main Aug 20, 2025
18 checks 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