Skip to content
9 changes: 8 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",

Check notice on line 2 in biome.json

View workflow job for this annotation

GitHub Actions / Lint

deserialize

The configuration schema version does not match the CLI version 2.5.15
"vcs": {
"enabled": true,
"clientKind": "git",
Expand All @@ -24,6 +24,7 @@
"rules": {
"preset": "recommended",
"complexity": {
"noExcessiveCognitiveComplexity": "error",
"noExcessiveLinesPerFunction": {
"level": "error",
"options": {
Expand All @@ -38,8 +39,14 @@
"noFloatingPromises": "error",
"useNullishCoalescing": "error"
},
"style": {
"noUselessElse": "error",
"useBlockStatements": "error",
"useReadonlyClassProperties": "error"
},
"suspicious": {
"noImportCycles": "error"
"noImportCycles": "error",
"noShadow": "error"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const DEFAULT_EXPLORER_ENABLED = false;
const COSMOS_READY_LOG_MESSAGE = "Now listening on: ";

export class AzureCosmosDbEmulatorContainer extends GenericContainer {
private key = DEFAULT_KEY;
private readonly key = DEFAULT_KEY;
private protocol: Protocol = DEFAULT_PROTOCOL;
private telemetryEnabled = DEFAULT_TELEMETRY_ENABLED;
private explorerEnabled = DEFAULT_EXPLORER_ENABLED;
private portGenerator: PortGenerator;
private readonly explorerEnabled = DEFAULT_EXPLORER_ENABLED;
private readonly portGenerator: PortGenerator;

constructor(image: string) {
super(image);
Expand Down
15 changes: 6 additions & 9 deletions packages/modules/azurite/src/azurite-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,25 @@ export class StartedAzuriteContainer extends AbstractStartedContainer {
public getBlobPort(): number {
if (hasHostBinding(this.blobPort)) {
return this.blobPort.host;
} else {
const containerPort = getContainerPort(this.blobPort);
return this.getMappedPort(containerPort);
}
const containerPort = getContainerPort(this.blobPort);
return this.getMappedPort(containerPort);
}

public getQueuePort(): number {
if (hasHostBinding(this.queuePort)) {
return this.queuePort.host;
} else {
const containerPort = getContainerPort(this.queuePort);
return this.getMappedPort(containerPort);
}
const containerPort = getContainerPort(this.queuePort);
return this.getMappedPort(containerPort);
}

public getTablePort(): number {
if (hasHostBinding(this.tablePort)) {
return this.tablePort.host;
} else {
const containerPort = getContainerPort(this.tablePort);
return this.getMappedPort(containerPort);
}
const containerPort = getContainerPort(this.tablePort);
return this.getMappedPort(containerPort);
}

public getBlobEndpoint(): string {
Expand Down
24 changes: 14 additions & 10 deletions packages/modules/couchbase/src/couchbase-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ export class CouchbaseContainer extends GenericContainer {
body.set("mgmtSSL", container.getMappedPort(PORTS.MGMT_SSL_PORT).toString());
}

this.setServicePorts(body, container);

const response = await this.doHttpRequest(
container.getHost(),
container.getMappedPort(PORTS.MGMT_PORT),
"/node/controller/setupAlternateAddresses/external",
"PUT",
body,
true
);
await this.checkResponse(response, "Could not configure external ports");
}

private setServicePorts(body: URLSearchParams, container: StartedTestContainer) {
if (this.enabledServices.has(CouchbaseService.KV)) {
body.set("kv", container.getMappedPort(PORTS.KV_PORT).toString());
body.set("capi", container.getMappedPort(PORTS.VIEW_PORT).toString());
Expand Down Expand Up @@ -348,16 +362,6 @@ export class CouchbaseContainer extends GenericContainer {
body.set("eventingSSL", container.getMappedPort(PORTS.EVENTING_SSL_PORT).toString());
}
}

const response = await this.doHttpRequest(
container.getHost(),
container.getMappedPort(PORTS.MGMT_PORT),
"/node/controller/setupAlternateAddresses/external",
"PUT",
body,
true
);
await this.checkResponse(response, "Could not configure external ports");
}

private async configureIndexer(container: StartedTestContainer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ async function getRequestBodyFromReadableStream(stream: ReadableStream<Uint8Arra
while (true) {
const { value, done } = await reader.read();

if (done) break;
if (done) {
break;
}

if (value) {
fullString += decoder.decode(value, { stream: true });
Expand Down Expand Up @@ -112,7 +114,9 @@ describe("CloudStorageEmulatorContainer", { concurrent: false, timeout: 240_000
let configUpdated = false;

server.events.on("request:start", ({ request }) => {
if (request.url.includes("/_internal/config")) configUpdated = true;
if (request.url.includes("/_internal/config")) {
configUpdated = true;
}
});

await using container = await new CloudStorageEmulatorContainer(IMAGE).start();
Expand All @@ -126,7 +130,9 @@ describe("CloudStorageEmulatorContainer", { concurrent: false, timeout: 240_000
let configUpdated = false;

server.events.on("request:start", ({ request }) => {
if (request.url.includes("/_internal/config")) configUpdated = true;
if (request.url.includes("/_internal/config")) {
configUpdated = true;
}
});

await using container = await new CloudStorageEmulatorContainer(IMAGE).withAutoUpdateExternalUrl(false).start();
Expand Down
11 changes: 8 additions & 3 deletions packages/modules/gcloud/src/emulator-flags-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export class EmulatorFlagsManager {
* @returns this instance for chaining.
*/
public withFlag(name: string, value: string): this {
if (!name) throw new Error("Flag name must be set.");
if (name.startsWith("--")) this.flags[name] = value;
else this.flags[`--${name}`] = value;
if (!name) {
throw new Error("Flag name must be set.");
}
if (name.startsWith("--")) {
this.flags[name] = value;
} else {
this.flags[`--${name}`] = value;
}
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/modules/gcloud/src/spanner-emulator-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class SpannerEmulatorHelper {
* Lazily get or create the Spanner client.
*/
public async client(): Promise<Spanner> {
const { Spanner } = await import("@google-cloud/spanner");
this.clientInstance ??= new Spanner({
const { Spanner: SpannerClient } = await import("@google-cloud/spanner");
this.clientInstance ??= new SpannerClient({
projectId: this.emulator.getProjectId(),
apiEndpoint: this.emulator.getHost(),
port: this.emulator.getGrpcPort(),
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/hivemq/src/hivemq-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("HiveMQContainer", { timeout: 240_000 }, () => {
const mqttClient = await mqtt.connectAsync(container.getConnectionString());

const firstMessagePromise = new Promise<{ topic: string; message: Buffer }>((resolve, reject) => {
mqttClient.once("message", (topic, message) => resolve({ topic, message }));
mqttClient.once("message", (topic, payload) => resolve({ topic, message: payload }));
mqttClient.once("error", (err) => reject(err));
});

Expand Down
4 changes: 2 additions & 2 deletions packages/modules/kurrentdb/src/kurrentdb-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ describe("KurrentDbContainer", { concurrent: false, timeout: 240_000 }, () => {
await stream.unsubscribe();
await client.dispose();

async function getStreamFirstEvent(stream: StreamSubscription): Promise<unknown> {
for await (const event of stream) {
async function getStreamFirstEvent(subscription: StreamSubscription): Promise<unknown> {
for await (const event of subscription) {
return event;
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/modules/mongodb/src/mongodb-atlas-local-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export class MongoDBAtlasLocalContainer extends GenericContainer {
}

public withUsername(username: string): this {
if (!username) throw new Error("Username should not be empty.");
if (!username) {
throw new Error("Username should not be empty.");
}
this.username = username;
return this;
}

public withPassword(password: string): this {
if (!password) throw new Error("Password should not be empty.");
if (!password) {
throw new Error("Password should not be empty.");
}
this.password = password;
return this;
}
Expand Down
32 changes: 22 additions & 10 deletions packages/modules/mongodb/src/mongodb-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ export class MongoDBContainer extends GenericContainer {
}

public withUsername(username: string): this {
if (!username) throw new Error("Username should not be empty.");
if (!username) {
throw new Error("Username should not be empty.");
}
this.username = username;
return this;
}

public withPassword(password: string): this {
if (!password) throw new Error("Password should not be empty.");
if (!password) {
throw new Error("Password should not be empty.");
}
this.password = password;
return this;
}

public override async start(): Promise<StartedMongoDBContainer> {
const cmdArgs = ["--replSet", "rs0"];
if (!this.healthCheck) this.withWaitForRsHealthCheck();
if (!this.healthCheck) {
this.withWaitForRsHealthCheck();
}
if (this.username && this.password) {
cmdArgs.push("--keyFile", "/data/db/key.txt");
this.withEnvironment({
Expand Down Expand Up @@ -58,18 +64,23 @@ export class MongoDBContainer extends GenericContainer {

private buildMongoEvalCommand(command: string) {
const args = [];
if (this.isV5OrLater()) args.push("mongosh");
else args.push("mongo", "admin");
if (this.username && this.password) args.push("-u", this.username, "-p", this.password);
if (this.isV5OrLater()) {
args.push("mongosh");
} else {
args.push("mongo", "admin");
}
if (this.username && this.password) {
args.push("-u", this.username, "-p", this.password);
}
args.push("--quiet", "--eval", command);
return args.join(" ");
}

private getRsInitCmd() {
if (this.isV5OrLater())
if (this.isV5OrLater()) {
return `'try { rs.status(); } catch (e) { rs.initiate(); } while (db.runCommand({isMaster: 1}).ismaster==false) { sleep(100); }'`;
else
return `'try { rs.initiate(); } catch (e) {} while (db.runCommand({isMaster: 1}).ismaster==false) { sleep(100); }'`;
}
return `'try { rs.initiate(); } catch (e) {} while (db.runCommand({isMaster: 1}).ismaster==false) { sleep(100); }'`;
}

private isV5OrLater() {
Expand All @@ -92,8 +103,9 @@ export class StartedMongoDBContainer extends AbstractStartedContainer {
}

public getConnectionString(): string {
if (this.username && this.password)
if (this.username && this.password) {
return `mongodb://${this.username}:${this.password}@${this.getHost()}:${this.getMappedPort(MONGODB_PORT)}?authSource=admin`;
}
return `mongodb://${this.getHost()}:${this.getMappedPort(MONGODB_PORT)}`;
}
}
4 changes: 2 additions & 2 deletions packages/modules/mosquitto/src/mosquitto-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("MosquittoContainer", { timeout: 240_000 }, () => {
const mqttClient = await mqtt.connectAsync(container.getConnectionString());

const firstMessagePromise = new Promise<{ topic: string; message: Buffer }>((resolve, reject) => {
mqttClient.once("message", (topic, message) => resolve({ topic, message }));
mqttClient.once("message", (topic, payload) => resolve({ topic, message: payload }));
mqttClient.once("error", (err) => reject(err));
});

Expand Down Expand Up @@ -43,7 +43,7 @@ describe("MosquittoContainer", { timeout: 240_000 }, () => {
const mqttClient = await mqtt.connectAsync(container.getConnectionString());

const firstMessagePromise = new Promise<{ topic: string; message: Buffer }>((resolve, reject) => {
mqttClient.once("message", (topic, message) => resolve({ topic, message }));
mqttClient.once("message", (topic, payload) => resolve({ topic, message: payload }));
mqttClient.once("error", (err) => reject(err));
});

Expand Down
8 changes: 6 additions & 2 deletions packages/modules/mosquitto/src/mosquitto-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ export class MosquittoContainer extends GenericContainer {
}

public withUsername(username: string): this {
if (!username) throw new Error("Username should not be empty.");
if (!username) {
throw new Error("Username should not be empty.");
}
this.username = username;
return this;
}

public withPassword(password: string): this {
if (!password) throw new Error("Password should not be empty.");
if (!password) {
throw new Error("Password should not be empty.");
}
this.password = password;
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/mssqlserver/src/mssqlserver-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MSSQL_PORT = 1433;

export class MSSQLServerContainer extends GenericContainer {
private database = "master";
private username = "sa";
private readonly username = "sa";
private password = "Passw0rd";
private acceptEula = "N";
private message: string | RegExp = /.*Recovery is complete.*/;
Expand Down
7 changes: 3 additions & 4 deletions packages/modules/nats/src/nats-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const USER_ARGUMENT_KEY = "--user";
const PASS_ARGUMENT_KEY = "--pass";

export class NatsContainer extends GenericContainer {
private args = new Set<string>();
private values = new Map<string, string | undefined>();
private readonly args = new Set<string>();
private readonly values = new Map<string, string | undefined>();

constructor(image: string) {
super(image);
Expand Down Expand Up @@ -62,9 +62,8 @@ export class NatsContainer extends GenericContainer {

if (name.length === 1) {
return `-${name}`;
} else {
return `--${name}`;
}
return `--${name}`;
}

public override async start(): Promise<StartedNatsContainer> {
Expand Down
16 changes: 12 additions & 4 deletions packages/modules/postgresql/src/postgresql-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ export class PostgreSqlContainer extends GenericContainer {
}

public withSSL(certFile: string, keyFile: string, caCertFile?: string): this {
if (!certFile) throw new Error("SSL certificate file should not be empty.");
if (!keyFile) throw new Error("SSL key file should not be empty.");
if (caCertFile !== undefined && !caCertFile) throw new Error("SSL CA certificate file should not be empty.");
if (!certFile) {
throw new Error("SSL certificate file should not be empty.");
}
if (!keyFile) {
throw new Error("SSL key file should not be empty.");
}
if (caCertFile !== undefined && !caCertFile) {
throw new Error("SSL CA certificate file should not be empty.");
}

const filesToCopy = [
{ source: certFile, target: POSTGRES_SSL_CERT_PATH, mode: 0o600 },
Expand Down Expand Up @@ -91,7 +97,9 @@ export class PostgreSqlContainer extends GenericContainer {
}

public withSSLCert(caCertFile: string, certFile: string, keyFile: string): this {
if (!caCertFile) throw new Error("SSL CA certificate file should not be empty.");
if (!caCertFile) {
throw new Error("SSL CA certificate file should not be empty.");
}
return this.withSSL(certFile, keyFile, caCertFile);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/redis/src/redis-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export class RedisContainer extends GenericContainer {

private async importInitialData(container: StartedTestContainer) {
const re = await container.exec(`/tmp/import.sh ${this.password}`);
if (re.exitCode !== 0 || re.output.includes("ERR"))
if (re.exitCode !== 0 || re.output.includes("ERR")) {
throw Error(`Could not import initial data from ${this.initialImportScriptFile}: ${re.output}`);
}
}
}

Expand Down
Loading
Loading