-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
test: adding test configuration and tests for redis adapter #2470
test: adding test configuration and tests for redis adapter #2470
Conversation
📝 WalkthroughWalkthroughThe pull request introduces comprehensive testing for the Redis adapter package, adding Vitest as the testing framework. The changes include creating a new test suite for the Changes
Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/adapter-redis/__tests__/redis-adapter.test.ts (4)
38-38
: Simplify mock instance retrievalConsider extracting the mock instance retrieval logic to a helper function for better readability.
- mockRedis = (Redis as unknown as ReturnType<typeof vi.fn>).mock.results[0].value; + const getMockRedis = () => (Redis as unknown as ReturnType<typeof vi.fn>).mock.results[0].value; + mockRedis = getMockRedis();
57-62
: Add error type verificationConsider verifying the error object type to ensure proper error handling.
it('should log error on error event', () => { const error = new Error('Redis connection error'); const errorHandler = mockRedis.on.mock.calls.find(call => call[0] === 'error')[1]; errorHandler(error); expect(elizaLogger.error).toHaveBeenCalledWith('Redis error:', error); + expect(error).toBeInstanceOf(Error); });
65-69
: Add key format validation testConsider adding a test to verify the Redis key format follows the expected pattern.
+ it('should format Redis key correctly', () => { + expect(expectedRedisKey).toMatch(/^[\w-]+:[\w-]+$/); + });
101-161
: Add timeout handling testsConsider adding tests for Redis operation timeouts.
+ it('should handle timeout errors', async () => { + const timeoutError = new Error('Redis operation timed out'); + mockRedis.set.mockRejectedValueOnce(timeoutError); + const result = await client.setCache({ agentId, key, value }); + expect(result).toBe(false); + expect(elizaLogger.error).toHaveBeenCalledWith('Error setting cache:', timeoutError); + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/adapter-redis/__tests__/redis-adapter.test.ts
(1 hunks)packages/adapter-redis/package.json
(1 hunks)packages/adapter-redis/vitest.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/adapter-redis/vitest.config.ts
🔇 Additional comments (3)
packages/adapter-redis/__tests__/redis-adapter.test.ts (2)
1-28
: Well-structured test setup with comprehensive mocking!The mocks cover all necessary Redis operations and logger methods while preserving actual core module functionality.
163-183
: Clean and comprehensive disconnect tests!Good coverage of both success and error scenarios for Redis disconnection.
packages/adapter-redis/package.json (1)
27-28
: Clean package.json updates!The addition of Vitest and test scripts follows standard practices.
Also applies to: 33-35
Relates to
#2469
Risks
Low: adding tests and test configuration.
Background
What does this PR do?
#2469
What kind of change is this?
Features/Tests
#2469
Documentation changes needed?
None
Testing
Where should a reviewer start?
packages/adapter-redis
Detailed testing steps
pnpm install in root of the directory
navigate to desired directory to see tests
run pnpm test to run tests