Skip to content

Commit 66de303

Browse files
committed
chore: update testing section
1 parent eb34641 commit 66de303

File tree

5 files changed

+14
-162
lines changed

5 files changed

+14
-162
lines changed

docs/features/idempotency.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,32 +945,20 @@ When testing your Lambda function locally, you can use a local DynamoDB instance
945945
--8<-- "examples/snippets/idempotency/workingWithLocalDynamoDB.ts"
946946
```
947947

948-
### Testing with local Cache
948+
### Testing with local cache
949949

950-
When testing your Lambda function locally, you can use a local Valkey or Redis instance to test the idempotency feature. You can use [Valkey](https://valkey.io/topics/installation/){target="_blank"} or [Redis OSS](https://redis.io/docs/latest/get-started/){target="_blank"} as a local server.
950+
Likewise, when using a cache database, you can use a local Valkey or Redis-OSS instance as a local server and replace the endpoint and port in the environment variables.
951951

952952
=== "valkeyHandler.test.ts"
953953

954-
```typescript hl_lines="19-24"
954+
```typescript hl_lines="5-8"
955955
--8<-- "examples/snippets/idempotency/workingWithLocalCacheValkey.test.ts"
956956
```
957957

958958
=== "valkeyHandler.ts"
959959

960960
```typescript
961-
--8<-- "examples/snippets/idempotency/workingWithLocalCacheValkey.ts"
962-
```
963-
964-
=== "redisHandler.test.ts"
965-
966-
```typescript hl_lines="19"
967-
--8<-- "examples/snippets/idempotency/workingWithLocalCacheRedis.test.ts"
968-
```
969-
970-
=== "redisHandler.ts"
971-
972-
```typescript
973-
--8<-- "examples/snippets/idempotency/workingWithLocalCacheRedis.ts"
961+
--8<-- "examples/snippets/idempotency/cachePersistenceLayerValkey.ts:5:"
974962
```
975963

976964
## Extra resources

examples/snippets/idempotency/workingWithLocalCacheRedis.test.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

examples/snippets/idempotency/workingWithLocalCacheRedis.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { makeIdempotent } from '@aws-lambda-powertools/idempotency';
2-
import { CachePersistenceLayer } from '@aws-lambda-powertools/idempotency/cache';
3-
import { GlideClient } from '@valkey/valkey-glide';
41
import type { Context } from 'aws-lambda';
5-
import { describe, expect, it } from 'vitest';
6-
import { handler } from './workingWithLocalDynamoDB.js';
2+
import { describe, expect, it, vi } from 'vitest';
3+
import { handler } from './cachePersistenceLayerValkey.js';
4+
5+
vi.hoisted(() => {
6+
process.env.CACHE_ENDPOINT = 'localhost';
7+
process.env.CACHE_PORT = '6379';
8+
});
79

810
const context = {
911
functionName: 'foo-bar-function',
@@ -14,30 +16,10 @@ const context = {
1416
getRemainingTimeInMillis: () => 1234,
1517
} as Context;
1618

17-
// Initialize the Glide client with local Glide server
18-
const client = await GlideClient.createClient({
19-
addresses: [
20-
{
21-
host: 'localhost',
22-
port: 6379,
23-
},
24-
],
25-
requestTimeout: 5000,
26-
});
27-
28-
const mockPersistenceStore = new CachePersistenceLayer({
29-
client,
30-
});
31-
3219
describe('Idempotent handler', () => {
3320
it('returns the same response', async () => {
34-
// Prepare
35-
const idempotentHandler = makeIdempotent(handler, {
36-
persistenceStore: mockPersistenceStore,
37-
});
38-
3921
// Act
40-
const response = await idempotentHandler(
22+
const response = await handler(
4123
{
4224
foo: 'bar',
4325
},
@@ -46,11 +28,9 @@ describe('Idempotent handler', () => {
4628

4729
// Assess
4830
expect(response).toEqual({
31+
paymentId: expect.any(String),
32+
message: 'success',
4933
statusCode: 200,
50-
body: JSON.stringify({
51-
paymentId: '123',
52-
message: 'Payment created',
53-
}),
5434
});
5535
});
5636
});

examples/snippets/idempotency/workingWithLocalCacheValkey.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)