Skip to content

Add interface mocks for SDK using mockery #746

Merged
ElyarSadig merged 11 commits into
mainfrom
feat/mocks
Feb 3, 2026
Merged

Add interface mocks for SDK using mockery #746
ElyarSadig merged 11 commits into
mainfrom
feat/mocks

Conversation

@ja7ad
Copy link
Copy Markdown
Collaborator

@ja7ad ja7ad commented Jan 30, 2026

Pull Request

Related issue

Fixes #745

What does this PR do?

  • This PR add generated mocks for interfaces using mockery to improve test workflows in production applications,

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • Documentation

    • Added "Using mocks for testing" docs with examples and guidance to regenerate mocks and a contributing note to run the mock generator when interfaces change.
  • Chores

    • Added mock generation configuration, updated make targets to install/run the generator, added mocks to coverage ignore, and added an indirect test dependency.
  • Tests

    • Added many autogenerated test mocks to support isolated, context-aware unit testing.

@ja7ad ja7ad added the maintenance Anything related to maintenance (CI, tests, refactoring...) label Jan 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Adds mock-generation configuration, a Makefile target, docs, codecov and go.mod updates, and 15+ autogenerated testify/mock files under mocks/. No production runtime logic changed; this patch provides test doubles and developer tooling for generating/using mocks.

Changes

Cohort / File(s) Summary
Mockery config
\.mockery\.yml
Adds mockery configuration (testify template, filename/structname/pkgname rules, recursive generation, packages.config entry for meilisearch-go).
Build & Make
Makefile
Adds .PHONY mock target, installs mockery in requirements, and target to generate mocks into mocks/.
Docs — contributing
CONTRIBUTING.md
New "Generate Mocks for new features" guidance and example make mock command.
Docs — readme
README.md
Adds "Using Mocks for Testing" section, example test snippet, and list of available mocks.
Coverage config
codecov.yml
Adds mocks to coverage ignore list.
Dependencies
go.mod
Adds indirect dependency github.com/stretchr/objx v0.5.2.
Mocks — Chat
mocks/meilisearch_chat_manager_mock.go, mocks/meilisearch_chat_reader_mock.go
Generated mocks for chat interfaces including streaming and context-aware method variants plus Expecter/Call helpers.
Mocks — Decoder
mocks/meilisearch_decoder_mock.go
Generated mock for Decoder (Close, Err, Event, Next) with call helper types.
Mocks — Document / Index / Search
mocks/meilisearch_document_reader_mock.go, mocks/meilisearch_index_reader_mock.go, mocks/meilisearch_search_reader_mock.go
Generated reader mocks (GetDocument(s), FetchInfo, Search, etc.) with context variants and Run/Return helpers.
Mocks — Settings
mocks/meilisearch_settings_reader_mock.go
Large generated mock for SettingsReader with full set of Get* methods and context-aware variants.
Mocks — Key reader/manager
mocks/meilisearch_key_reader_mock.go, mocks/meilisearch_key_manager_mock.go
Generated mocks for key reader/manager APIs (GetKey(s), Create/Update/Delete key) with context variants and call builders.
Mocks — Service
mocks/meilisearch_service_reader_mock.go
Comprehensive ServiceReader mock covering many service-level methods (index, stats, multi-search, version, etc.).
Mocks — Task reader/manager
mocks/meilisearch_task_reader_mock.go, mocks/meilisearch_task_manager_mock.go
Generated mocks for task-related APIs (GetTask(s), WaitForTask, Cancel/Delete tasks) with context-aware variants.
Mocks — Webhook reader/manager
mocks/meilisearch_webhook_reader_mock.go, mocks/meilisearch_webhook_manager_mock.go
Generated mocks for webhook APIs (Get/List/Add/Update/Delete) with context variants and Expecter/Call helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • curquiza

Poem

🐰 Hopping through code with a whisker and grin,
I stitched up mocks so tests may begin.
Streams and readers, managers in tow,
With tidy Expecters, the assertions grow.
Run, Return, and clean—now hop, tests, go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: adding generated mocks for SDK interfaces using the mockery tool.
Linked Issues check ✅ Passed The PR fully addresses issue #745 by identifying SDK interfaces and generating comprehensive mocks using mockery, with all related infrastructure (config files, documentation, build targets) properly added.
Out of Scope Changes check ✅ Passed All changes directly support the mock generation objective: mockery configuration, documentation, build targets, and codecov updates are all necessary and on-scope.
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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/mocks

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds generated interface mocks using mockery to facilitate unit testing for SDK consumers and contributors. The mocks are generated using the testify/mock framework and provide a comprehensive set of test doubles for all public interfaces in the SDK.

Changes:

  • Added mockery configuration file (.mockery.yml) to define mock generation settings
  • Updated Makefile with a new mock target for regenerating mocks
  • Added comprehensive documentation in README.md with usage examples
  • Updated CONTRIBUTING.md with instructions for generating mocks when modifying interfaces
  • Generated 19 mock files covering all major SDK interfaces (ServiceManager, IndexManager, DocumentManager, etc.)

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.mockery.yml Configuration file defining mockery settings for generating mocks from SDK interfaces
makefile Added mock target and mockery installation in requirements
README.md Added "Using Mocks for Testing" section with practical examples and available mocks list
CONTRIBUTING.md Added instructions for regenerating mocks when modifying interfaces
mocks/*.go Generated mock implementations for all SDK interfaces using testify/mock

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .mockery.yml Outdated
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

🤖 Fix all issues with AI agents
In `@README.md`:
- Around line 308-347: The README code blocks use hard tabs which markdownlint
flags (MD010); replace all hard tab characters with spaces in the fenced Go
examples so indentation is spaces-only—update the CreateMyIndex example and the
unit test example (symbols: CreateMyIndex, TestCreateMyIndex, mockClient,
expectedConfig) to use spaces for indentation and align code blocks consistently
to remove tabs.
- Around line 43-44: The TOC nested list is over-indented; update the
indentation of the nested items so they use 2-space nesting: adjust the lines
for "Using mocks for testing" and its child "Available Mocks" to the correct
2-space indent level (reduce the current extra spaces) so the Markdown TOC
conforms to MD007.
🧹 Nitpick comments (1)
makefile (1)

3-7: Pin the mockery binary used by make mock to avoid version drift.

mockery on PATH could be v2 and incompatible with .mockery.yml v3 options. Consider invoking the pinned version directly (or ensure PATH resolves to v3.6.1).

Proposed fix (use pinned version)
 mock:
 	`@echo` "Generating mocks..."
 	`@mkdir` -p mocks
-	`@mockery`
+	`@go` run github.com/vektra/mockery/[email protected]
 	`@echo` "✓ Mock generation complete"

If you keep go install [email protected], make sure the PATH resolves to that exact binary when make mock runs.

Also applies to: 15-15

Comment thread README.md
Comment thread README.md
@ja7ad
Copy link
Copy Markdown
Collaborator Author

ja7ad commented Jan 30, 2026

image

@curquiza @ElyarSadig We are experiencing an issue with TestExport. In this test, we add example data for the movies and comics indices (50 documents each). Although the data is sent to Meilisearch, the "add or update documents" task remains stuck at enqueued and does not transition to success in the latest Enterprise version.

func TestExport(t *testing.T) {
c := setup(t, "")
t.Cleanup(cleanup(c))
movieIndexUID := "movies"
comicsIndexUID := "comics"
setupMovieIndex(t, c, movieIndexUID)
setupComicIndex(t, c, comicsIndexUID)
tests := []struct {
name string
params *meilisearch.ExportParams
}{
{
name: "ExportWithoutIndexes",
params: &meilisearch.ExportParams{
URL: getDefaultHost(),
PayloadSize: "1MB",
Indexes: nil,
},
},
{
name: "ExportWithOneIndex",
params: &meilisearch.ExportParams{
URL: getDefaultHost(),
PayloadSize: "10MB",
Indexes: map[string]meilisearch.IndexExportOptions{
movieIndexUID: {
Filter: "id > 50",
OverrideSettings: true,
},
},
},
},
{
name: "ExportWithMultipleIndexes",
params: &meilisearch.ExportParams{
URL: getDefaultHost(),
PayloadSize: "10MB",
Indexes: map[string]meilisearch.IndexExportOptions{
movieIndexUID: {
Filter: "id > 86",
OverrideSettings: true,
},
comicsIndexUID: {
Filter: "genres = 'Mystery'",
OverrideSettings: false,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := c.Export(tt.params)
require.NoError(t, err)
require.NotZero(t, result.TaskUID)
require.Equal(t, meilisearch.TaskStatusEnqueued, result.Status)
require.Equal(t, meilisearch.TaskTypeExport, result.Type)
require.NotZero(t, result.EnqueuedAt)
})
}
}

@ElyarSadig
Copy link
Copy Markdown
Collaborator

@ja7ad
Yesterday it was working fine. Could it be because of the new enterprise version (bug or something)?
How about we decrease the data in the export integration test so export may not cause other tests to get stuck?

@ja7ad
Copy link
Copy Markdown
Collaborator Author

ja7ad commented Feb 2, 2026

@ja7ad Yesterday it was working fine. Could it be because of the new enterprise version (bug or something)? How about we decrease the data in the export integration test so export may not cause other tests to get stuck?

I don’t think this issue is caused by the test data, as these tests used to passed without any problems.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (32f492b) to head (c8d5ca1).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #746   +/-   ##
=======================================
  Coverage   88.53%   88.53%           
=======================================
  Files          22       22           
  Lines        3262     3262           
=======================================
  Hits         2888     2888           
  Misses        216      216           
  Partials      158      158           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@curquiza
Copy link
Copy Markdown
Member

curquiza commented Feb 3, 2026

@ja7ad and @ElyarSadig
Thanks for pinging! Do you still have the problem?
If you have can you send a reproducible to the meilisearch repo?

@ja7ad
Copy link
Copy Markdown
Collaborator Author

ja7ad commented Feb 3, 2026

@ja7ad and @ElyarSadig
Thanks for pinging! Do you still have the problem?
If you have can you send a reproducible to the meilisearch repo?

Yw, No fixed issue by PR #750.

Thank you @Strift

@ja7ad ja7ad enabled auto-merge February 3, 2026 10:36
@ja7ad ja7ad disabled auto-merge February 3, 2026 10:36
@ja7ad
Copy link
Copy Markdown
Collaborator Author

ja7ad commented Feb 3, 2026

@ElyarSadig Please review

@ElyarSadig ElyarSadig added this pull request to the merge queue Feb 3, 2026
Merged via the queue into main with commit 4267102 Feb 3, 2026
6 checks passed
@ElyarSadig ElyarSadig deleted the feat/mocks branch February 3, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Anything related to maintenance (CI, tests, refactoring...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate interface mocks for SDK using mockery

4 participants