Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ updates:
- "/packages/modules/nats"
- "/packages/modules/neo4j"
- "/packages/modules/ollama"
- "/packages/modules/opensearch"
- "/packages/modules/postgresql"
- "/packages/modules/qdrant"
- "/packages/modules/rabbitmq"
Expand Down
23 changes: 23 additions & 0 deletions docs/modules/opensearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenSearch Module

[OpenSearch](https://opensearch.org/) is a community-driven, open source search and analytics suite derived from Elasticsearch. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.

## Install

```bash
npm install @testcontainers/opensearch --save-dev
```

## Examples

<!--codeinclude-->
[Create an index:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:createIndex
<!--/codeinclude-->

<!--codeinclude-->
[Index a document:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:indexDocument
<!--/codeinclude-->

<!--codeinclude-->
[Set a custom password:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:customPassword
<!--/codeinclude-->
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ nav:
- Nats: modules/nats.md
- Neo4J: modules/neo4j.md
- Ollama: modules/ollama.md
- OpenSearch: modules/opensearch.md
- PostgreSQL: modules/postgresql.md
- Qdrant: modules/qdrant.md
- RabbitMQ: modules/rabbitmq.md
Expand Down
73 changes: 73 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/modules/opensearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM opensearchproject/opensearch:3.1.0
39 changes: 39 additions & 0 deletions packages/modules/opensearch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@testcontainers/opensearch",
"version": "11.2.1",
"license": "MIT",
"keywords": [
"opensearch",
"testing",
"docker",
"testcontainers"
],
"description": "OpenSearch module for Testcontainers",
"homepage": "https://github.com/testcontainers/testcontainers-node#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/testcontainers/testcontainers-node.git"
},
"bugs": {
"url": "https://github.com/testcontainers/testcontainers-node/issues"
},
"main": "build/index.js",
"files": [
"build"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
"build": "tsc --project tsconfig.build.json"
},
"devDependencies": {
"@opensearch-project/opensearch": "^3.5.1",
"@types/zxcvbn": "^4.4.5"
},
"dependencies": {
"testcontainers": "^11.2.1",
"zxcvbn": "^4.4.2"
}
}
1 change: 1 addition & 0 deletions packages/modules/opensearch/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { OpenSearchContainer, StartedOpenSearchContainer } from "./opensearch-container";
105 changes: 105 additions & 0 deletions packages/modules/opensearch/src/opensearch-container.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Client } from "@opensearch-project/opensearch";
import { getImage } from "../../../testcontainers/src/utils/test-helper";
import { OpenSearchContainer } from "./opensearch-container";

const IMAGE = getImage(__dirname);
const images = ["opensearchproject/opensearch:2.19.2", IMAGE];

describe("OpenSearchContainer", { timeout: 180_000 }, () => {
// createIndex {
it.each(images)("should create an index with %s", async (image) => {
const container = await new OpenSearchContainer(image).start();
const client = new Client({
node: container.getHttpUrl(),
auth: {
username: container.getUsername(),
password: container.getPassword(),
},
ssl: {
// trust the self-signed cert
rejectUnauthorized: false,
},
});

await client.indices.create({ index: "people" });
const existsResponse = await client.indices.exists({ index: "people" });
expect(existsResponse.body).toBe(true);
await container.stop();
});
// }

// indexDocument {
it("should index a document", async () => {
const container = await new OpenSearchContainer(IMAGE).start();
const client = new Client({
node: container.getHttpUrl(),
auth: {
username: container.getUsername(),
password: container.getPassword(),
},
ssl: {
rejectUnauthorized: false,
},
});

const document = { id: "1", name: "John Doe" };

await client.index({
index: "people",
id: document.id,
body: document,
});

const getResponse = await client.get({ index: "people", id: document.id });
expect(getResponse.body._source).toStrictEqual(document);
await container.stop();
});
// }

it("should work with restarted container", async () => {
const container = await new OpenSearchContainer(IMAGE).start();
await container.restart();

const client = new Client({
node: container.getHttpUrl(),
auth: {
username: container.getUsername(),
password: container.getPassword(),
},
ssl: {
rejectUnauthorized: false,
},
});

await client.indices.create({ index: "people" });
const existsResponse = await client.indices.exists({ index: "people" });
expect(existsResponse.body).toBe(true);
await container.stop();
});

it("should throw when given an invalid password", () => {
expect(() => new OpenSearchContainer(IMAGE).withPassword("weakpwd")).toThrowError(/Password "weakpwd" is too weak/);
});

// customPassword {
it("should set custom password", async () => {
const container = await new OpenSearchContainer(IMAGE).withPassword("Str0ng!Passw0rd2025").start();

const client = new Client({
node: container.getHttpUrl(),
auth: {
username: container.getUsername(),
password: container.getPassword(),
},
ssl: {
rejectUnauthorized: false,
},
});

await client.indices.create({ index: "people" });
const existsResponse = await client.indices.exists({ index: "people" });
expect(existsResponse.body).toBe(true);
await container.stop();
});
// }
});
Loading