Skip to content

fix(database): harden insert contracts - #18

Merged
KilianBoute merged 1 commit into
mainfrom
fix/insert-contract-hardening
Aug 13, 2026
Merged

KilianBoute merged 1 commit into
mainfrom
fix/insert-contract-hardening

Conversation

@KilianBoute

@KilianBoute KilianBoute commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Description

This change hardens the database insert contracts by bringing InsertOne and InsertMany in line with the rest of the database abstraction layer.

Previously, insert operations ignored MongoDB-specific options and had limited support in the mock database implementation. That made insert behavior harder to validate in tests and increased the risk of production code diverging from test expectations.

This PR improves reliability in two key ways:

  • MongoClient.InsertOne and InsertMany now correctly retain and forward supported MongoDB insert options while safely ignoring unrelated wrapper options. This makes insert behavior consistent with other database methods and ensures callers can rely on validation, ordering, comments, and other driver-level configuration being applied correctly.
  • MockDatabase now fully supports insert expectations, queued responses, option tracking, and call inspection for both single and bulk inserts. This enables more precise tests around insert flows, sequential failures, retries, and option propagation.

The added test coverage validates both the option filtering logic and the new mock behaviors, reducing the likelihood of silent regressions in insert handling.

Forward MongoDB insert options and add configurable insert responses, queues, call tracking, reset support, and tests to MockDatabase.
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/database/mongodb.go 85.71% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@KilianBoute
KilianBoute merged commit 17cbbd8 into main Aug 13, 2026
6 checks passed
@KilianBoute
KilianBoute deleted the fix/insert-contract-hardening branch August 13, 2026 14:12
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