Skip to content

Commit 20bde37

Browse files
CosmosDB
1 parent ba296aa commit 20bde37

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

docs/modules/arangodb.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ This example uses the following libraries:
1818

1919
Choose an image from [Docker Hub](https://hub.docker.com/_/arangodb) and substitute `IMAGE`.
2020

21+
### Execute a query
22+
2123
<!--codeinclude-->
22-
[Creating an ArangoDB container](../../packages/modules/arangodb/src/arangodb-container.test.ts) inside_block:example
24+
[](../../packages/modules/arangodb/src/arangodb-container.test.ts) inside_block:example
2325
<!--/codeinclude-->

docs/modules/chromadb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_# ChromaDB
1+
# ChromaDB
22

33
## Install
44

docs/modules/cosmosdb.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# Cosmos DB Emulator Module (Linux-based)
1+
# CosmosDB
22

3-
[Azure Cosmos DB](https://azure.microsoft.com/en-GB/products/cosmos-db) is a globally distributed, multi-model database service provided by Microsoft.
3+
!!!info
4+
This module uses the **Linux-based** version of the CosmosDB emulator. In general, it:
5+
6+
- Provides better compatibility on a variety of systems.
7+
- Consumes significantly less resources.
8+
- Comes with much faster startup times.
9+
10+
However, not all features of a full CosmosDB are implemented yet. Refer to [this overview](https://learn.microsoft.com/en-us/azure/cosmos-db/emulator-linux#feature-support) for a detailed list.
411

512
## Install
613

@@ -9,24 +16,25 @@ npm install @testcontainers/azurecosmosdb --save-dev
916
```
1017

1118
## Examples
12-
<!--codeinclude-->
13-
[Connect to emulator and create a database:](../../packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts) inside_block:httpCreateDB
14-
<!--/codeinclude-->
1519

16-
<!--codeinclude-->
17-
[Using HTTPS:](../../packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts) inside_block:httpsCreateDB
18-
<!--/codeinclude-->
20+
These examples use the following libraries:
21+
22+
- [@azure/cosmos](https://www.npmjs.com/package/@azure/cosmos)
23+
24+
npm install @azure/cosmos
25+
26+
---
27+
28+
Choose an image from [Microsoft Artifact Registry](https://mcr.microsoft.com/) and substitute `IMAGE`. For example, `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview`.
29+
30+
### Execute a query
1931

2032
<!--codeinclude-->
21-
[Create and read items:](../../packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts) inside_block:createAndRead
33+
[](../../packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts) inside_block:createAndRead
2234
<!--/codeinclude-->
2335

24-
## Caveats
25-
### Compatibility
26-
This testcontainer uses the [linux-based](https://learn.microsoft.com/en-us/azure/cosmos-db/emulator-linux) version. In general, it:
36+
### With HTTPS
2737

28-
- Provides better compatibility on a variety of systems
29-
- Consumes significantly less resources
30-
- Comes with much faster startup times
31-
32-
However, not all features of a full CosmosDB are implemented yet - please refer to [this overview](https://learn.microsoft.com/en-us/azure/cosmos-db/emulator-linux#feature-support) for a detailed list.
38+
<!--codeinclude-->
39+
[](../../packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts) inside_block:httpsCreateDB
40+
<!--/codeinclude-->

packages/modules/azurecosmosdb/src/azure-cosmosdb-emulator-container.test.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
3737
});
3838
// }
3939

40-
// httpsCreateDB {
4140
it("should be able to create a database using https", async () => {
41+
// httpsCreateDB {
4242
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
43+
4344
const cosmosClient = new CosmosClient({
4445
endpoint: container.getEndpoint(),
4546
key: container.getKey(),
4647
agent: new https.Agent({
47-
rejectUnauthorized: false, //allows insecure TLS; import * as https from "node:https";
48+
rejectUnauthorized: false,
4849
}),
4950
});
51+
// }
5052

5153
const dbName = "testdb";
5254
const createResponse = await cosmosClient.databases.createIfNotExists({
@@ -57,23 +59,22 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
5759
const db = await cosmosClient.database(dbName).read();
5860
expect(db.database.id).toBe(dbName);
5961
});
60-
// }
6162

62-
// createAndRead {
6363
it("should be able to create a container and store and retrieve items", async () => {
64+
// createAndRead {
65+
const dbName = "testdb";
66+
const containerName = "testcontainer";
67+
6468
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
69+
6570
const cosmosClient = new CosmosClient({
6671
endpoint: container.getEndpoint(),
6772
key: container.getKey(),
6873
});
6974

70-
const dbName = "testdb";
71-
await cosmosClient.databases.createIfNotExists({
72-
id: dbName,
73-
});
74-
const dbClient = cosmosClient.database(dbName);
75+
await cosmosClient.databases.createIfNotExists({ id: dbName });
7576

76-
const containerName = "testcontainer";
77+
const dbClient = cosmosClient.database(dbName);
7778
await dbClient.containers.createIfNotExists({
7879
id: containerName,
7980
partitionKey: {
@@ -83,12 +84,10 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
8384
});
8485

8586
const containerClient = dbClient.container(containerName);
86-
const createResponse = await containerClient.items.create({
87-
foo: "bar",
88-
});
87+
const createResponse = await containerClient.items.create({ foo: "bar" });
8988

9089
const readItem = await containerClient.item(createResponse.item.id, "bar").read();
9190
expect(readItem.resource.foo).toEqual("bar");
91+
// }
9292
});
93-
// }
9493
});

0 commit comments

Comments
 (0)