apache / apache/opendal

Feature request: provide mock capability for operator

Open
#6,145 2 comments 3 reactions 0 assignees View on GitHub
enhancement releases-note/feat rust
Dominant language
Rust
Stars
5.4k
Forks
825
Avg merge
1d 14m
Merged PRs (30d)
127

Description

### Feature Description

Hi team, I'm now heavily use opendal in my work, I'm wondering if it's possible to provide a mock `Operator`, so I could easily mock in my unit test for error testing?

I did some searches in the codebase, I find we do use mock-based unit tests for retry test:
https://github.com/apache/opendal/blob/faf12983a0f46a5c75641d1a0b0eaa5d0600b972/core/src/layers/retry.rs#L807-L1026

But that seems awkward and bespoke, I'm wondering if we could use [`mockall`](https://docs.rs/mockall/latest/mockall/) to decorate the trait, which unblocks full control for mock.

### Problem and Solution

```rust
use mockall::*;
use mockall::predicate::*;
#[automock]
trait Operator {
/// interface functions
}
```

### Additional Context

_No response_

### Are you willing to contribute to the development of this feature?

- [ ] Yes, I am willing to contribute to the development of this feature.

Contributor guide

Open the contributing guide

Research direction

Start by locating the Operator trait and reading the mock-based retry tests in core/src/layers/retry.rs, especially the cited test range; compare that approach with mockall's documented #[automock] support. Done means the project has a supported way to create and configure a mock Operator for unit tests, including controlled error cases, with tests covering the capability.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.