Skip to content
Closed
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
2 changes: 1 addition & 1 deletion docs/features/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ import {
} from "testcontainers";

class CustomContainer extends GenericContainer {
protected override async beforeContainerStarted(): Promise<void> {
protected override async beforeContainerCreated(): Promise<void> {
// ...
}

Expand Down
12 changes: 6 additions & 6 deletions src/generic-container/generic-container-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { GenericContainer, AbstractStartedContainer, StartedTestContainer, Inspe
describe("GenericContainer lifecycle", () => {
jest.setTimeout(180_000);

let beforeContainerStarted: jest.Func;
let beforeContainerCreated: jest.Func;
let containerCreated: jest.Func;
let containerStarting: jest.Func;
let containerStarted: jest.Func;
let containerStopping: jest.Func;
let containerStopped: jest.Func;

beforeEach(() => {
beforeContainerStarted = jest.fn();
beforeContainerCreated = jest.fn();
containerCreated = jest.fn();
containerStarting = jest.fn();
containerStarted = jest.fn();
Expand All @@ -24,7 +24,7 @@ describe("GenericContainer lifecycle", () => {
.withExposedPorts(8080)
.start();

expect(beforeContainerStarted).toHaveBeenCalled();
expect(beforeContainerCreated).toHaveBeenCalled();
expect(containerCreated).toHaveBeenCalledWith(container.getId());
expect(containerStarting).toHaveBeenCalledWith(false);
expect(containerStarted).toHaveBeenCalledWith(false);
Expand All @@ -45,7 +45,7 @@ describe("GenericContainer lifecycle", () => {
.start();

expect(container1.getId()).toEqual(container2.getId());
expect(beforeContainerStarted).toHaveBeenCalled();
expect(beforeContainerCreated).toHaveBeenCalled();
expect(containerCreated).not.toHaveBeenCalled();
expect(containerStarting).toHaveBeenCalledWith(true);
expect(containerStarted).toHaveBeenCalledWith(true);
Expand All @@ -54,8 +54,8 @@ describe("GenericContainer lifecycle", () => {
});

class CustomContainer extends GenericContainer {
protected override async beforeContainerStarted(): Promise<void> {
beforeContainerStarted();
protected override async beforeContainerCreated(): Promise<void> {
beforeContainerCreated();
}

protected override async containerCreated(containerId: string): Promise<void> {
Expand Down
26 changes: 3 additions & 23 deletions src/generic-container/generic-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ export class GenericContainer implements TestContainer {
this.opts = initCreateContainerOptions(imageName, imageName.isReaper());
}

/**
* @deprecated Since version 9.4.0. Will be removed in version 10.0.0. Use `beforeContainerStarted` instead.
*/
protected preStart?(): Promise<void>;

protected beforeContainerStarted?(): Promise<void>;
protected beforeContainerCreated?(): Promise<void>;

protected containerCreated?(containerId: string): Promise<void>;

Expand All @@ -83,10 +78,8 @@ export class GenericContainer implements TestContainer {
await ReaperInstance.getInstance();
}

if (this.beforeContainerStarted) {
await this.beforeContainerStarted();
} else if (this.preStart) {
await this.preStart();
if (this.beforeContainerCreated) {
await this.beforeContainerCreated();
}

if (!this.opts.imageName.isHelperContainer() && PortForwarderInstance.isRunning()) {
Expand Down Expand Up @@ -152,8 +145,6 @@ export class GenericContainer implements TestContainer {

if (this.containerStarted) {
await this.containerStarted(startedContainer, inspectResult, true);
} else if (this.postStart) {
await this.postStart(startedContainer, inspectResult, boundPorts);
}

return startedContainer;
Expand Down Expand Up @@ -226,22 +217,11 @@ export class GenericContainer implements TestContainer {

if (this.containerStarted) {
await this.containerStarted(startedContainer, inspectResult, false);
} else if (this.postStart) {
await this.postStart(startedContainer, inspectResult, boundPorts);
}

return startedContainer;
}

/**
* @deprecated Since version 9.4.0. Will be removed in version 10.0.0. Use `containerStarted` instead.
*/
protected postStart?(
container: StartedTestContainer,
inspectResult: InspectResult,
boundPorts: BoundPorts
): Promise<void>;

protected containerStarted?(
container: StartedTestContainer,
inspectResult: InspectResult,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/kafka/kafka-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class KafkaContainer extends GenericContainer {
return this;
}

protected override async beforeContainerStarted(): Promise<void> {
protected override async beforeContainerCreated(): Promise<void> {
const network = this.networkMode && this.networkAliases.length > 0 ? this.networkAliases[0] : "localhost";
this.withEnvironment({ KAFKA_ADVERTISED_LISTENERS: `BROKER://${network}:${KAFKA_BROKER_PORT}` });

Expand Down