Skip to content
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default [
"error",
{
caughtErrors: "none",
varsIgnorePattern: "^_",
},
],
"no-irregular-whitespace": "off",
Expand Down
4 changes: 1 addition & 3 deletions packages/modules/arangodb/src/arangodb-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IMAGE = getImage(__dirname);
describe("ArangoDB", { timeout: 180_000 }, () => {
// connect {
it("should connect and return a query result", async () => {
const container = await new ArangoDBContainer(IMAGE).start();
await using container = await new ArangoDBContainer(IMAGE).start();
const db = new Database({ url: container.getHttpUrl() });

db.database("_system");
Expand All @@ -20,8 +20,6 @@ describe("ArangoDB", { timeout: 180_000 }, () => {
});
const returnValue = await result.next();
expect(returnValue).toBe(value);

await container.stop();
});
// }
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ const IMAGE = getImage(__dirname);

describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {
it("should set https protocol", async () => {
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
const connectionUri = container.getConnectionUri();
expect(connectionUri).toContain("AccountEndpoint=https://");
await container.stop();
});

it("should set http protocol if no protocol is specified", async () => {
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).start();
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).start();
const connectionUri = container.getConnectionUri();
expect(connectionUri).toContain("AccountEndpoint=http://");
await container.stop();
});

// httpCreateDB {
it("should be able to create a database using http", async () => {
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
const cosmosClient = new CosmosClient({
endpoint: container.getEndpoint(),
key: container.getKey(),
Expand All @@ -35,14 +34,12 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {

const db = await cosmosClient.database(dbName).read();
expect(db.database.id).toBe(dbName);

await container.stop();
});
// }

// httpsCreateDB {
it("should be able to create a database using https", async () => {
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("https").start();
const cosmosClient = new CosmosClient({
endpoint: container.getEndpoint(),
key: container.getKey(),
Expand All @@ -59,14 +56,12 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {

const db = await cosmosClient.database(dbName).read();
expect(db.database.id).toBe(dbName);

await container.stop();
});
// }

// createAndRead {
it("should be able to create a container and store and retrieve items", async () => {
const container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
await using container = await new AzureCosmosDbEmulatorContainer(IMAGE).withProtocol("http").start();
const cosmosClient = new CosmosClient({
endpoint: container.getEndpoint(),
key: container.getKey(),
Expand Down Expand Up @@ -94,8 +89,6 @@ describe("AzureCosmosDbEmulatorContainer", { timeout: 180_000 }, async () => {

const readItem = await containerClient.item(createResponse.item.id, "bar").read();
expect(readItem.resource.foo).toEqual("bar");

await container.stop();
});
// }
});
25 changes: 9 additions & 16 deletions packages/modules/azurite/src/azurite-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const IMAGE = getImage(__dirname);
describe("Azurite", { timeout: 240_000 }, () => {
// uploadAndDownloadBlob {
it("should upload and download blob with default credentials", async () => {
const container = await new AzuriteContainer(IMAGE).start();
await using container = await new AzuriteContainer(IMAGE).start();

const connectionString = container.getConnectionString();
expect(connectionString).toBeTruthy();
Expand All @@ -34,14 +34,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
}

expect(data).toBe(content);

await container.stop();
});
// }

// sendAndReceiveQueue {
it("should add to queue with default credentials", async () => {
const container = await new AzuriteContainer(IMAGE).start();
await using container = await new AzuriteContainer(IMAGE).start();

const connectionString = container.getConnectionString();
expect(connectionString).toBeTruthy();
Expand All @@ -58,14 +56,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
const messages = await queueClient.receiveMessages();
expect(messages.receivedMessageItems).toHaveLength(1);
expect(messages.receivedMessageItems[0].messageText).toBe(message);

await container.stop();
});
// }

// createAndInsertOnTable {
it("should add to table with default credentials", async () => {
const container = await new AzuriteContainer(IMAGE).start();
await using container = await new AzuriteContainer(IMAGE).start();

const connectionString = container.getConnectionString();
expect(connectionString).toBeTruthy();
Expand All @@ -86,8 +82,6 @@ describe("Azurite", { timeout: 240_000 }, () => {
const e1 = await tableClient.listEntities().next();
expect(e1.value).toBeTruthy();
expect(e1.value.name).toBe(entity.name);

await container.stop();
});
// }

Expand All @@ -97,7 +91,10 @@ describe("Azurite", { timeout: 240_000 }, () => {
// Account key must be base64 encoded
const accountKey = Buffer.from("test-key").toString("base64");

const container = await new AzuriteContainer(IMAGE).withAccountName(accountName).withAccountKey(accountKey).start();
await using container = await new AzuriteContainer(IMAGE)
.withAccountName(accountName)
.withAccountKey(accountKey)
.start();

const credentials = new StorageSharedKeyCredential(accountName, accountKey);
const serviceClient = new BlobServiceClient(container.getBlobEndpoint(), credentials);
Expand All @@ -109,8 +106,6 @@ describe("Azurite", { timeout: 240_000 }, () => {
const blobContainer = await serviceClient.listContainers().next();
expect(blobContainer.value).toBeTruthy();
expect(blobContainer.value.name).toBe(blobContainerName);

await container.stop();
});
// }

Expand All @@ -119,7 +114,7 @@ describe("Azurite", { timeout: 240_000 }, () => {
const blobPort = 13000;
const queuePort = 14000;
const tablePort = 15000;
const container = await new AzuriteContainer(IMAGE)
await using container = await new AzuriteContainer(IMAGE)
.withBlobPort({ container: 10001, host: blobPort })
.withQueuePort({ container: 10002, host: queuePort })
.withTablePort({ container: 10003, host: tablePort })
Expand All @@ -137,14 +132,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
const serviceClient = BlobServiceClient.fromConnectionString(connectionString);
const containerClient = serviceClient.getContainerClient("test");
await containerClient.createIfNotExists();

await container.stop();
});
// }

// inMemoryPersistence {
it("should be able to use in-memory persistence", async () => {
const container = await new AzuriteContainer(IMAGE).withInMemoryPersistence().start();
await using container = await new AzuriteContainer(IMAGE).withInMemoryPersistence().start();
const blobName = "hello.txt";

{
Expand Down
18 changes: 8 additions & 10 deletions packages/modules/cassandra/src/cassandra-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const IMAGE = getImage(__dirname);
describe.sequential("Cassandra", { timeout: 240_000 }, () => {
// connectWithDefaultCredentials {
it("should connect and execute a query with default credentials", async () => {
const container = await new CassandraContainer(IMAGE).start();
await using container = await new CassandraContainer(IMAGE).start();

const client = new Client({
contactPoints: [container.getContactPoint()],
Expand All @@ -22,7 +22,6 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
expect(result.rows[0].release_version).toBe(ImageName.fromString(IMAGE).tag);

await client.shutdown();
await container.stop();
});
// }

Expand All @@ -31,7 +30,7 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
const username = "testUser";
const password = "testPassword";

const container = await new CassandraContainer(IMAGE).withUsername(username).withPassword(password).start();
await using container = await new CassandraContainer(IMAGE).withUsername(username).withPassword(password).start();

const client = new Client({
contactPoints: [container.getContactPoint()],
Expand All @@ -46,15 +45,17 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
expect(result.rows.length).toBeGreaterThan(0);

await client.shutdown();
await container.stop();
});
// }

// customDataCenterAndRack {
it("should set datacenter and rack", async () => {
const customDataCenter = "customDC";
const customRack = "customRack";
const container = await new CassandraContainer(IMAGE).withDatacenter(customDataCenter).withRack(customRack).start();
await using container = await new CassandraContainer(IMAGE)
.withDatacenter(customDataCenter)
.withRack(customRack)
.start();

const client = new Client({
contactPoints: [container.getContactPoint()],
Expand All @@ -67,13 +68,12 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
expect(result.rows[0].rack).toBe(customRack);

await client.shutdown();
await container.stop();
});
// }

// createAndFetchData {
it("should create keyspace, a table, insert data, and retrieve it", async () => {
const container = await new CassandraContainer(IMAGE).start();
await using container = await new CassandraContainer(IMAGE).start();

const client = new Client({
contactPoints: [container.getContactPoint()],
Expand Down Expand Up @@ -108,12 +108,11 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
expect(result.rows[0].name).toBe(username);

await client.shutdown();
await container.stop();
});
// }

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

const client = new Client({
Expand All @@ -128,6 +127,5 @@ describe.sequential("Cassandra", { timeout: 240_000 }, () => {
expect(result.rows[0].release_version).toBe(ImageName.fromString(IMAGE).tag);

await client.shutdown();
await container.stop();
});
});
14 changes: 5 additions & 9 deletions packages/modules/chromadb/src/chromadb-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const IMAGE = getImage(__dirname);
describe("ChromaDB", { timeout: 360_000 }, () => {
// startContainer {
it("should connect", async () => {
const container = await new ChromaDBContainer(IMAGE).start();
await using container = await new ChromaDBContainer(IMAGE).start();
const client = await connectTo(container);
expect(await client.heartbeat()).toBeDefined();
// Do something with the client
await container.stop();
});
// }

Expand All @@ -32,7 +31,7 @@ describe("ChromaDB", { timeout: 360_000 }, () => {

// createCollection {
it("should create collection and get data", async () => {
const container = await new ChromaDBContainer(IMAGE).start();
await using container = await new ChromaDBContainer(IMAGE).start();
const client = await connectTo(container);
const collection = await client.createCollection({ name: "test", metadata: { "hnsw:space": "cosine" } });
expect(collection.name).toBe("test");
Expand All @@ -44,13 +43,12 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
expect(getResults.documents[0]).toStrictEqual("my doc");
expect(getResults.metadatas).toBeDefined();
expect(getResults.metadatas?.[0]?.key).toStrictEqual("value");
await container.stop();
});
// }

// queryCollectionWithEmbeddingFunction {
it("should create collection and query", async () => {
const container = await new ChromaDBContainer(IMAGE).start();
await using container = await new ChromaDBContainer(IMAGE).start();
const ollama = await new GenericContainer("ollama/ollama").withExposedPorts(11434).start();
await ollama.exec(["ollama", "pull", "nomic-embed-text"]);
const client = await connectTo(container);
Expand All @@ -75,13 +73,12 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
expect(results).toBeDefined();
expect(results.ids[0]).toEqual(["1"]);
expect(results.ids[0][0]).toBe("1");
await container.stop();
});

// persistentData {
it("should reconnect with volume and persistence data", async () => {
const sourcePath = fs.mkdtempSync(path.join(os.tmpdir(), "chroma-temp"));
const container = await new ChromaDBContainer(IMAGE)
await using container = await new ChromaDBContainer(IMAGE)
.withBindMounts([{ source: sourcePath, target: "/data" }])
.start();
const client = await connectTo(container);
Expand All @@ -93,7 +90,6 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
const getResults = await collection.get({ ids: ["1"] });
expect(getResults.ids[0]).toBe("1");
expect(getResults.documents[0]).toStrictEqual("my doc");
await container.stop();
expect(fs.existsSync(`${sourcePath}/chroma.sqlite3`)).toBe(true);
try {
fs.rmSync(sourcePath, { force: true, recursive: true });
Expand All @@ -109,7 +105,7 @@ describe("ChromaDB", { timeout: 360_000 }, () => {
const tenant = "test-tenant";
const key = "test-key";
const database = "test-db";
const container = await new ChromaDBContainer(IMAGE)
await using container = await new ChromaDBContainer(IMAGE)
.withEnvironment({
CHROMA_SERVER_AUTHN_CREDENTIALS: key,
CHROMA_SERVER_AUTHN_PROVIDER: "chromadb.auth.token_authn.TokenAuthenticationServerProvider",
Expand Down
Loading