1- import { AbstractStartedContainer , GenericContainer , StartedTestContainer , Wait } from "testcontainers" ;
1+ import {
2+ AbstractStartedContainer ,
3+ GenericContainer ,
4+ hasHostBinding ,
5+ PortWithOptionalBinding ,
6+ StartedTestContainer ,
7+ Wait ,
8+ } from "testcontainers" ;
29
310const AZURITE_IMAGE = "mcr.microsoft.com/azure-storage/azurite:3.33.0" ;
411const BLOB_PORT = 10000 ;
@@ -21,9 +28,10 @@ export class AzuriteContainer extends GenericContainer {
2128 . withStartupTimeout ( 120_000 ) ;
2229 }
2330
24- private blobPort : number = BLOB_PORT ;
25- private queuePort : number = QUEUE_PORT ;
26- private tablePort : number = TABLE_PORT ;
31+ private blobPort : PortWithOptionalBinding = BLOB_PORT ;
32+ private queuePort : PortWithOptionalBinding = QUEUE_PORT ;
33+ private tablePort : PortWithOptionalBinding = TABLE_PORT ;
34+
2735 private accountName : string = DEFAULT_ACCOUNT_NAME ;
2836 private accountKey : string = DEFAULT_ACCOUNT_KEY ;
2937
@@ -53,26 +61,26 @@ export class AzuriteContainer extends GenericContainer {
5361 * Sets the port to expose the Blob service on.
5462 * @param port The port to expose the Blob service on. Default is 10000.
5563 */
56- public withBlobPort ( port : number ) : this {
57- this . blobPort = port ;
64+ public withBlobPort ( blobPort : PortWithOptionalBinding ) : this {
65+ this . blobPort = blobPort ;
5866 return this ;
5967 }
6068
6169 /**
6270 * Sets the port to expose the Queue service on.
6371 * @param port The port to expose the Queue service on. Default is 10001.
6472 */
65- public withQueuePort ( port : number ) : this {
66- this . queuePort = port ;
73+ public withQueuePort ( queuePort : PortWithOptionalBinding ) : this {
74+ this . queuePort = queuePort ;
6775 return this ;
6876 }
6977
7078 /**
7179 * Sets the port to expose the Table service on.
7280 * @param port The port to expose the Table service on. Default is 10002.
7381 */
74- public withTablePort ( port : number ) : this {
75- this . tablePort = port ;
82+ public withTablePort ( tablePort : PortWithOptionalBinding ) : this {
83+ this . tablePort = tablePort ;
7684 return this ;
7785 }
7886
@@ -119,11 +127,7 @@ export class AzuriteContainer extends GenericContainer {
119127 command . push ( "--skipApiVersionCheck" ) ;
120128 }
121129
122- this . withCommand ( command ) . withExposedPorts (
123- { container : BLOB_PORT , host : this . blobPort } ,
124- { container : QUEUE_PORT , host : this . queuePort } ,
125- { container : TABLE_PORT , host : this . tablePort }
126- ) ;
130+ this . withCommand ( command ) . withExposedPorts ( this . blobPort , this . queuePort , this . tablePort ) ;
127131
128132 if ( this . accountName !== DEFAULT_ACCOUNT_NAME || this . accountKey !== DEFAULT_ACCOUNT_KEY ) {
129133 this . withEnvironment ( {
@@ -149,9 +153,9 @@ export class StartedAzuriteContainer extends AbstractStartedContainer {
149153 startedTestContainer : StartedTestContainer ,
150154 private readonly accountName : string ,
151155 private readonly accountKey : string ,
152- private readonly blobPort : number ,
153- private readonly queuePort : number ,
154- private readonly tablePort : number
156+ private readonly blobPort : PortWithOptionalBinding ,
157+ private readonly queuePort : PortWithOptionalBinding ,
158+ private readonly tablePort : PortWithOptionalBinding
155159 ) {
156160 super ( startedTestContainer ) ;
157161 }
@@ -165,27 +169,39 @@ export class StartedAzuriteContainer extends AbstractStartedContainer {
165169 }
166170
167171 public getBlobPort ( ) : number {
168- return this . blobPort ;
172+ if ( hasHostBinding ( this . blobPort ) ) {
173+ return this . blobPort . host ;
174+ } else {
175+ return this . getMappedPort ( this . blobPort ) ;
176+ }
169177 }
170178
171179 public getQueuePort ( ) : number {
172- return this . queuePort ;
180+ if ( hasHostBinding ( this . queuePort ) ) {
181+ return this . queuePort . host ;
182+ } else {
183+ return this . getMappedPort ( this . queuePort ) ;
184+ }
173185 }
174186
175187 public getTablePort ( ) : number {
176- return this . tablePort ;
188+ if ( hasHostBinding ( this . tablePort ) ) {
189+ return this . tablePort . host ;
190+ } else {
191+ return this . getMappedPort ( this . tablePort ) ;
192+ }
177193 }
178194
179195 public getBlobEndpoint ( ) : string {
180- return this . getEndpoint ( this . blobPort , this . accountName ) ;
196+ return this . getEndpoint ( this . getBlobPort ( ) , this . accountName ) ;
181197 }
182198
183199 public getQueueEndpoint ( ) : string {
184- return this . getEndpoint ( this . queuePort , this . accountName ) ;
200+ return this . getEndpoint ( this . getQueuePort ( ) , this . accountName ) ;
185201 }
186202
187203 public getTableEndpoint ( ) : string {
188- return this . getEndpoint ( this . tablePort , this . accountName ) ;
204+ return this . getEndpoint ( this . getTablePort ( ) , this . accountName ) ;
189205 }
190206
191207 /**
0 commit comments