Skip to content

Commit 8767ccf

Browse files
authored
Add s3mock module (#1170)
1 parent 8cd3c6a commit 8767ccf

File tree

10 files changed

+245
-10
lines changed

10 files changed

+245
-10
lines changed

docs/modules/s3mock.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# S3Mock
2+
3+
## Install
4+
5+
```bash
6+
npm install @testcontainers/s3mock --save-dev
7+
```
8+
9+
## Examples
10+
11+
These examples use the following libraries:
12+
13+
- [@aws-sdk/client-s3](https://www.npmjs.com/package/@aws-sdk/client-s3)
14+
15+
npm install @aws-sdk/client-s3
16+
17+
Choose an image from the [container registry](https://hub.docker.com/r/adobe/s3mock) and substitute `IMAGE`.
18+
19+
### Create a S3 bucket
20+
21+
<!--codeinclude-->
22+
[](../../packages/modules/s3mock/src/s3mock-container.test.ts) inside_block:s3mockCreateS3Bucket
23+
<!--/codeinclude-->

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ nav:
8585
- RabbitMQ: modules/rabbitmq.md
8686
- Redis: modules/redis.md
8787
- Redpanda: modules/redpanda.md
88+
- S3Mock: modules/s3mock.md
8889
- ScyllaDB: modules/scylladb.md
8990
- Selenium: modules/selenium.md
9091
- ToxiProxy: modules/toxiproxy.md

package-lock.json

Lines changed: 37 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modules/s3mock/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM adobe/s3mock:4.9.1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@testcontainers/s3mock",
3+
"version": "11.7.2",
4+
"license": "MIT",
5+
"keywords": [
6+
"s3mock",
7+
"aws",
8+
"testing",
9+
"docker",
10+
"testcontainers"
11+
],
12+
"description": "S3Mock module for Testcontainers",
13+
"homepage": "https://github.com/testcontainers/testcontainers-node#readme",
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/testcontainers/testcontainers-node.git"
17+
},
18+
"bugs": {
19+
"url": "https://github.com/testcontainers/testcontainers-node/issues"
20+
},
21+
"main": "build/index.js",
22+
"files": [
23+
"build"
24+
],
25+
"publishConfig": {
26+
"access": "public"
27+
},
28+
"scripts": {
29+
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
30+
"build": "tsc --project tsconfig.build.json"
31+
},
32+
"dependencies": {
33+
"testcontainers": "^11.7.2"
34+
},
35+
"devDependencies": {
36+
"@aws-sdk/client-s3": "^3.913.0"
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { S3MockContainer, StartedS3MockContainer } from "./s3mock-container";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { CreateBucketCommand, HeadBucketCommand, S3Client } from "@aws-sdk/client-s3";
2+
import { getImage } from "../../../testcontainers/src/utils/test-helper";
3+
import { S3MockContainer } from "./s3mock-container";
4+
5+
const IMAGE = getImage(__dirname);
6+
7+
describe("S3MockContainer", { timeout: 180_000 }, () => {
8+
it("should create a S3 bucket", async () => {
9+
// s3mockCreateS3Bucket {
10+
await using container = await new S3MockContainer(IMAGE).start();
11+
12+
const client = new S3Client({
13+
endpoint: container.getHttpConnectionUrl(),
14+
forcePathStyle: true,
15+
region: "auto",
16+
credentials: {
17+
secretAccessKey: container.getSecretAccessKey(),
18+
accessKeyId: container.getAccessKeyId(),
19+
},
20+
});
21+
22+
const input = { Bucket: "testcontainers" };
23+
const command = new CreateBucketCommand(input);
24+
25+
expect((await client.send(command)).$metadata.httpStatusCode).toEqual(200);
26+
expect((await client.send(new HeadBucketCommand(input))).$metadata.httpStatusCode).toEqual(200);
27+
// }
28+
});
29+
});

0 commit comments

Comments
 (0)