Skip to content

Commit c2ea084

Browse files
Opensearch
1 parent 3bcb124 commit c2ea084

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

docs/modules/opensearch.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# OpenSearch Module
2-
3-
[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.
1+
# OpenSearch
42

53
## Install
64

@@ -10,14 +8,28 @@ npm install @testcontainers/opensearch --save-dev
108

119
## Examples
1210

11+
These examples use the following libraries:
12+
13+
- [@opensearch-project/opensearch](https://www.npmjs.com/package/@opensearch-project/opensearch)
14+
15+
npm install @opensearch-project/opensearch
16+
17+
Choose an image from the [container registry](https://hub.docker.com/r/opensearchproject/opensearch) and substitute `IMAGE`.
18+
19+
### Create an index
20+
1321
<!--codeinclude-->
14-
[Create an index:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:createIndex
22+
[](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:opensearchCreateIndex
1523
<!--/codeinclude-->
1624

25+
### Index a document
26+
1727
<!--codeinclude-->
18-
[Index a document:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:indexDocument
28+
[](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:opensearchIndexDocument
1929
<!--/codeinclude-->
2030

31+
### With password
32+
2133
<!--codeinclude-->
22-
[Set a custom password:](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:customPassword
34+
[](../../packages/modules/opensearch/src/opensearch-container.test.ts) inside_block:opensearchCustomPassword
2335
<!--/codeinclude-->

packages/modules/opensearch/src/opensearch-container.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ const IMAGE = getImage(__dirname);
66
const images = ["opensearchproject/opensearch:2.19.2", IMAGE];
77

88
describe("OpenSearchContainer", { timeout: 180_000 }, () => {
9-
// createIndex {
109
it.each(images)("should create an index with %s", async (image) => {
10+
// opensearchCreateIndex {
1111
await using container = await new OpenSearchContainer(image).start();
12+
1213
const client = new Client({
1314
node: container.getHttpUrl(),
1415
auth: {
1516
username: container.getUsername(),
1617
password: container.getPassword(),
1718
},
1819
ssl: {
19-
// trust the self-signed cert
2020
rejectUnauthorized: false,
2121
},
2222
});
2323

2424
await client.indices.create({ index: "people" });
25-
const existsResponse = await client.indices.exists({ index: "people" });
26-
expect(existsResponse.body).toBe(true);
25+
26+
const { body } = await client.indices.exists({ index: "people" });
27+
expect(body).toBe(true);
28+
// }
2729
});
28-
// }
2930

30-
// indexDocument {
3131
it("should index a document", async () => {
32+
// opensearchIndexDocument {
3233
await using container = await new OpenSearchContainer(IMAGE).start();
34+
3335
const client = new Client({
3436
node: container.getHttpUrl(),
3537
auth: {
@@ -49,10 +51,10 @@ describe("OpenSearchContainer", { timeout: 180_000 }, () => {
4951
body: document,
5052
});
5153

52-
const getResponse = await client.get({ index: "people", id: document.id });
53-
expect(getResponse.body._source).toStrictEqual(document);
54+
const { body } = await client.get({ index: "people", id: document.id });
55+
expect(body._source).toEqual(document);
56+
// }
5457
});
55-
// }
5658

5759
it("should work with restarted container", async () => {
5860
await using container = await new OpenSearchContainer(IMAGE).start();
@@ -70,6 +72,7 @@ describe("OpenSearchContainer", { timeout: 180_000 }, () => {
7072
});
7173

7274
await client.indices.create({ index: "people" });
75+
7376
const existsResponse = await client.indices.exists({ index: "people" });
7477
expect(existsResponse.body).toBe(true);
7578
});
@@ -78,9 +81,10 @@ describe("OpenSearchContainer", { timeout: 180_000 }, () => {
7881
expect(() => new OpenSearchContainer(IMAGE).withPassword("weakpwd")).toThrowError(/Password "weakpwd" is too weak/);
7982
});
8083

81-
// customPassword {
8284
it("should set custom password", async () => {
85+
// opensearchCustomPassword {
8386
await using container = await new OpenSearchContainer(IMAGE).withPassword("Str0ng!Passw0rd2025").start();
87+
// }
8488

8589
const client = new Client({
8690
node: container.getHttpUrl(),
@@ -94,8 +98,8 @@ describe("OpenSearchContainer", { timeout: 180_000 }, () => {
9498
});
9599

96100
await client.indices.create({ index: "people" });
97-
const existsResponse = await client.indices.exists({ index: "people" });
98-
expect(existsResponse.body).toBe(true);
101+
102+
const { body } = await client.indices.exists({ index: "people" });
103+
expect(body).toBe(true);
99104
});
100-
// }
101105
});

0 commit comments

Comments
 (0)