Skip to content

feature/add-mocking#2

Merged
cedricve merged 9 commits intomainfrom
feature/add-mocking
Jan 4, 2026
Merged

feature/add-mocking#2
cedricve merged 9 commits intomainfrom
feature/add-mocking

Conversation

@cedricve
Copy link
Member

@cedricve cedricve commented Jan 4, 2026

Description

Motivation

The primary motivation behind this pull request is to enhance the testing capabilities of our project by introducing a mock implementation of the DatabaseInterface. This allows for more robust and isolated unit tests by simulating database interactions without the need for an actual database connection.

Improvements

  1. Isolation of Tests: By using mock implementations, we can isolate unit tests from the actual database, reducing dependencies and making tests more reliable and faster.
  2. Controlled Test Scenarios: The mock allows for precise control over the behavior of database operations, enabling the simulation of various scenarios, including error conditions, without the need to manipulate a real database.
  3. Enhanced Documentation: The README has been updated to include comprehensive instructions on using the mock for testing, providing clear guidance for developers.
  4. Increased Test Coverage: The changes include extensive test cases for the mock implementation, ensuring that the mock behaves as expected and increasing overall test coverage.
  5. Ease of Use: The mock implementation comes with various features like setting expectations, custom behaviors, and tracking call history, making it easy to use and integrate into existing tests.

This addition significantly improves the project's testing framework, making it easier to write, maintain, and run tests in isolation from the actual database environment.

Updated the DatabaseInterface and MongoClient Ping method to accept a context.Context parameter for better control over request timeouts and cancellation. Adjusted related code and tests to use the new signature, and made MongoClient.Options exported for consistency.
@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 73.58491% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/database/mongodb.go 35.71% 15 Missing and 3 partials ⚠️
pkg/database/mock.go 87.17% 9 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cedricve cedricve merged commit 894a64e into main Jan 4, 2026
6 checks passed
@cedricve cedricve deleted the feature/add-mocking branch January 4, 2026 20:09
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