Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 0 additions & 28 deletions packages/modules/azurite/src/azurite-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,6 @@ describe("Azurite", () => {
});
// }

// customPorts {
it("should be able to specify custom ports", async () => {
const blobPort = 13000;
const queuePort = 14000;
const tablePort = 15000;
const container = await new AzuriteContainer()
.withBlobPort(blobPort)
.withQueuePort(queuePort)
.withTablePort(tablePort)
.start();

expect(container.getBlobPort()).toBe(blobPort);
expect(container.getQueuePort()).toBe(queuePort);
expect(container.getTablePort()).toBe(tablePort);

const connectionString = container.getConnectionString();
expect(connectionString).toContain("13000");
expect(connectionString).toContain("14000");
expect(connectionString).toContain("15000");

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().withInMemoryPersistence().start();
Expand Down
57 changes: 10 additions & 47 deletions packages/modules/azurite/src/azurite-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export class AzuriteContainer extends GenericContainer {
.withStartupTimeout(120_000);
}

private blobPort: number = BLOB_PORT;
private queuePort: number = QUEUE_PORT;
private tablePort: number = TABLE_PORT;
private accountName: string = DEFAULT_ACCOUNT_NAME;
private accountKey: string = DEFAULT_ACCOUNT_KEY;

Expand All @@ -49,33 +46,6 @@ export class AzuriteContainer extends GenericContainer {
return this;
}

/**
* Sets the port to expose the Blob service on.
* @param port The port to expose the Blob service on. Default is 10000.
*/
public withBlobPort(port: number): this {
this.blobPort = port;
return this;
}

/**
* Sets the port to expose the Queue service on.
* @param port The port to expose the Queue service on. Default is 10001.
*/
public withQueuePort(port: number): this {
this.queuePort = port;
return this;
}

/**
* Sets the port to expose the Table service on.
* @param port The port to expose the Table service on. Default is 10002.
*/
public withTablePort(port: number): this {
this.tablePort = port;
return this;
}

/**
* Disable persisting any data to disk and only store data in-memory. If the Azurite process is terminated, all data is lost.
*/
Expand Down Expand Up @@ -119,11 +89,7 @@ export class AzuriteContainer extends GenericContainer {
command.push("--skipApiVersionCheck");
}

this.withCommand(command).withExposedPorts(
{ container: BLOB_PORT, host: this.blobPort },
{ container: QUEUE_PORT, host: this.queuePort },
{ container: TABLE_PORT, host: this.tablePort }
);
this.withCommand(command).withExposedPorts(BLOB_PORT, QUEUE_PORT, TABLE_PORT);
Copy link
Collaborator

@cristianrgreco cristianrgreco Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The withExposedPorts should move to the constructor. If we keep it in the start method, then it cannot be overridden by users.

You should be able to verify this by re-enabling the should be able to specify custom ports test and providing

.withExposedPorts(
      { container: BLOB_PORT, host: this.blobPort },
      { container: QUEUE_PORT, host: this.queuePort },
      { container: TABLE_PORT, host: this.tablePort }
    );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If developers are allowed to use withExposedPort(), it becomes difficult to create the necessary endpoints as the port order for blob, queue, and table can be set arbitrarily.

Appreciating the existing implementation, the withBlobPort, withQueuePort, and withTablePort functions were modified to accept PortWithOptionalBinding. By using hasHostBinding, it distinguishes whether the port is custom or automatically mapped. Could you review this again? 🙏


if (this.accountName !== DEFAULT_ACCOUNT_NAME || this.accountKey !== DEFAULT_ACCOUNT_KEY) {
this.withEnvironment({
Expand All @@ -133,27 +99,24 @@ export class AzuriteContainer extends GenericContainer {

const startedContainer = await super.start();

return new StartedAzuriteContainer(
startedContainer,
this.accountName,
this.accountKey,
this.blobPort,
this.queuePort,
this.tablePort
);
return new StartedAzuriteContainer(startedContainer, this.accountName, this.accountKey);
}
}

export class StartedAzuriteContainer extends AbstractStartedContainer {
private readonly blobPort: number;
private readonly queuePort: number;
private readonly tablePort: number;

constructor(
startedTestContainer: StartedTestContainer,
private readonly accountName: string,
private readonly accountKey: string,
private readonly blobPort: number,
private readonly queuePort: number,
private readonly tablePort: number
private readonly accountKey: string
) {
super(startedTestContainer);
this.blobPort = this.getMappedPort(BLOB_PORT);
this.queuePort = this.getMappedPort(QUEUE_PORT);
this.tablePort = this.getMappedPort(TABLE_PORT);
}

public getAccountName(): string {
Expand Down
Loading