Skip to content

Commit 9a725ae

Browse files
Add exposed port helper for Couchbase
1 parent a02194c commit 9a725ae

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/modules/couchbase/src/couchbase-container.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class CouchbaseContainer extends GenericContainer {
118118
if (this.enabledServices.has(CouchbaseService.EVENTING)) {
119119
exposedPorts.push(PORTS.EVENTING_PORT, PORTS.EVENTING_SSL_PORT);
120120
}
121-
return exposedPorts;
121+
return exposedPorts.filter((port) => !this.hasExposedPort(port));
122122
}
123123

124124
private constructWaitStrategies() {
@@ -572,8 +572,7 @@ export class CouchbaseContainer extends GenericContainer {
572572
}
573573

574574
public override async start(): Promise<StartedCouchbaseContainer> {
575-
const exposedPorts = this.createOpts.ExposedPorts ?? {};
576-
this.withExposedPorts(...this.getPortsToExpose().filter((port) => exposedPorts[`${port}/tcp`] === undefined));
575+
this.withExposedPorts(...this.getPortsToExpose());
577576
return new StartedCouchbaseContainer(await super.start(), this.username, this.password);
578577
}
579578
}

packages/testcontainers/src/generic-container/generic-container.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ export class GenericContainer implements TestContainer {
425425
return this;
426426
}
427427

428+
protected hasExposedPort(port: PortWithOptionalBinding): boolean {
429+
const containerPort = getContainerPort(port);
430+
const protocol = getProtocol(port);
431+
432+
return Object.hasOwn(this.createOpts.ExposedPorts ?? {}, `${containerPort}/${protocol}`);
433+
}
434+
428435
public withBindMounts(bindMounts: BindMount[]): this {
429436
this.hostConfig.Binds = bindMounts
430437
.map((bindMount) => ({ mode: "rw", ...bindMount }))

0 commit comments

Comments
 (0)