-
Notifications
You must be signed in to change notification settings - Fork 4.9k
docs: Add mock server tests documentation for connectors #68667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
docs: Add mock server tests documentation for connectors #68667
Conversation
Original prompt from [email protected] |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. Helpful Resources
PR Slash CommandsAirbyte Maintainers (that's you!) can execute the following slash commands on your PR:
|
|
|
||
| Organize mock server tests in a dedicated directory structure: | ||
|
|
||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
| Tests should only configure values that are necessary for the specific scenario being tested. Avoid setting unnecessary fields or using complete API responses when a minimal response suffices. | ||
|
|
||
| **Good Example** (minimal): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| ``` | ||
|
|
||
| **Bad Example** (excessive configuration): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| Tests should explicitly show values that affect the test outcome. If a test depends on a specific field value, set it in the test context rather than relying on values in template files. | ||
|
|
||
| **Good Example** (expressive): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| ``` | ||
|
|
||
| **Bad Example** (implicit dependencies): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| - Lookback window behavior | ||
|
|
||
| **Error Handling Tests**: | ||
| - Rate limiting (429) with retry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Rate limiting (429) with ret..."]
| - Client errors (400) with appropriate failure type | ||
|
|
||
| **Example Test Suite Structure**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| Here's a complete example demonstrating best practices: | ||
|
|
||
| **config.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| ``` | ||
|
|
||
| **request_builder.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| ``` | ||
|
|
||
| **test_events.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint] reported by reviewdog 🐶
MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```python"]
| @@ -0,0 +1,646 @@ | |||
| # Mock Server Tests for Connectors | |||
|
|
|||
| Mock server tests provide a fast, reliable way to test connector behavior without making actual API calls. These tests use the Airbyte Python CDK's mock HTTP framework to simulate API responses and verify connector logic. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [vale] reported by reviewdog 🐶
[Vale.Spelling] Did you really mean 'CDK's'?
|
|
||
| ## Why Use Mock Server Tests | ||
|
|
||
| Mock server tests offer several advantages over integration tests: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[write-good.Weasel] 'several' is a weasel word!
|
|
||
| ### Core Components | ||
|
|
||
| **HttpMocker**: Context manager and decorator that intercepts HTTP requests and returns mocked responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': C' should be in lowercase.
| # Run connector code | ||
| ``` | ||
|
|
||
| **HttpRequest**: Represents an HTTP request with URL, query parameters, headers, and body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': R' should be in lowercase.
| ) | ||
| ``` | ||
|
|
||
| **HttpResponse**: Represents an HTTP response with body, status code, and headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': R' should be in lowercase.
|
|
||
| ### Test Utilities | ||
|
|
||
| **EntrypointWrapper**: Executes connector operations (read, check, discover) and captures output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': E' should be in lowercase.
| assert len(output.records) == 10 | ||
| ``` | ||
|
|
||
| **CatalogBuilder**: Constructs configured catalogs for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': C' should be in lowercase.
| catalog = CatalogBuilder().with_stream("users", SyncMode.incremental).build() | ||
| ``` | ||
|
|
||
| **StateBuilder**: Constructs state messages for incremental sync testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.Colons] ': C' should be in lowercase.
|
|
||
| ### 4. Avoid Fragile Tests | ||
|
|
||
| Tests should not fail when the API provider adds new fields to responses. Only validate fields that are important for the connector's functionality (filtering, transformation, cursor tracking, etc.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google.WordList] Use 'capability' or 'feature' instead of 'functionality'.
| - Subsequent sync with state | ||
| - State message generation | ||
| - Cursor field handling | ||
| - Lookback window behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [vale] reported by reviewdog 🐶
[Vale.Spelling] Did you really mean 'Lookback'?
| Tests should only configure values that are necessary for the specific scenario being tested. Avoid setting unnecessary fields or using complete API responses when a minimal response suffices. | ||
|
|
||
| **Good Example** (minimal): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| ``` | ||
|
|
||
| **Bad Example** (excessive configuration): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| Tests should explicitly show values that affect the test outcome. If a test depends on a specific field value, set it in the test context rather than relying on values in template files. | ||
|
|
||
| **Good Example** (expressive): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| ``` | ||
|
|
||
| **Bad Example** (implicit dependencies): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| Mock server tests should execute quickly. Disable any sleep or delay mechanisms using monkey patching. | ||
|
|
||
| **Good Example** (fast): | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| - Lookback window behavior | ||
|
|
||
| **Error Handling Tests**: | ||
| - Rate limiting (429) with retry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| - Rate limiting (429) with retry | |
| - Rate limiting (429) with retry |
| - Client errors (400) with appropriate failure type | ||
|
|
||
| **Example Test Suite Structure**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| Here's a complete example demonstrating best practices: | ||
|
|
||
| **config.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| ``` | ||
|
|
||
| **request_builder.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
| ``` | ||
|
|
||
| **test_events.py**: | ||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[markdownlint-fix] reported by reviewdog 🐶
| ```python | |
| ```python |
|
Deploy preview for airbyte-docs ready! ✅ Preview Built with commit e706e42. |
What
Adds comprehensive documentation for mock server tests in Airbyte connectors. This documentation describes the testing framework available in airbyte-python-cdk and provides best practices for writing effective mock server tests.
Requested by [email protected] ([email protected]) via Slack.
Link to Devin run: https://app.devin.ai/sessions/4db973c08aa34c24afd09a5efa20aa7f
How
Created a new documentation file at
docs/platform/connector-development/connector-mock-server-tests.mdfollowing the format ofconnector-breaking-changes.md. The documentation includes:Review Guide
User Impact
Connector developers will have comprehensive documentation on how to write effective mock server tests. This will:
Note: I encountered pnpm install errors when attempting to verify the local documentation build. The documentation should be reviewed in the Vercel preview to ensure it renders correctly.
Can this PR be safely reverted and rolled back?
This is documentation-only with no code changes.