Skip to content

Redpanda

Testcontainers can be used to automatically instantiate and manage Redpanda containers. More precisely Testcontainers uses the official Docker images for Redpanda

Note

This module uses features provided in docker.redpanda.com/redpandadata/redpanda.

Install

npm install @testcontainers/redpanda --save-dev

Example

it("should connect", async () => {
  const redpandaContainer = await new RedpandaContainer().start();
  await testPubSub(redpandaContainer);
  await redpandaContainer.stop();
});
it("should connect to schema registry", async () => {
  const redpandaContainer = await new RedpandaContainer().start();
  const schemaRegistryUrl = redpandaContainer.getSchemaRegistryAddress();

  const response = await fetch(`${schemaRegistryUrl}/subjects`, {
    method: "GET",
    headers: {
      "Content-Type": "application/vnd.schemaregistry.v1+json",
    },
  });

  expect(response.status).toBe(200);

  await redpandaContainer.stop();
});
it("should connect to admin", async () => {
  const redpandaContainer = await new RedpandaContainer().start();
  const adminUrl = `${redpandaContainer.getAdminAddress()}/v1`;

  const response = await fetch(adminUrl);

  expect(response.status).toBe(200);

  await redpandaContainer.stop();
});
it("should connect to rest proxy", async () => {
  const redpandaContainer = await new RedpandaContainer().start();
  const restProxyUrl = `${redpandaContainer.getRestProxyAddress()}/topics`;

  const response = await fetch(restProxyUrl);

  expect(response.status).toBe(200);

  await redpandaContainer.stop();
});