Skip to content

Commit 3213731

Browse files
committed
Debug
1 parent 9ca3855 commit 3213731

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { AbstractStartedContainer, ExecResult, GenericContainer, StartedTestCont
33
import { promises as fs } from "fs";
44
import os from "os";
55
import path from "path";
6-
import { FileToCopy } from "testcontainers/src/types";
76

87
const MONGODB_PORT = 27017;
98

@@ -43,15 +42,13 @@ chmod 600 "${keyfileContainerPath}"`;
4342
const initScriptHostPath = path.join(tempDir, "01-init-keyfile.sh");
4443
await fs.writeFile(initScriptHostPath, initKeyfileScript, { mode: 0o755 });
4544

46-
const filesToCopy: FileToCopy[] = [
45+
this.withCopyFilesToContainer([
4746
{
4847
source: initScriptHostPath,
4948
target: initScriptContainerPath,
5049
mode: 0o755,
5150
},
52-
];
53-
54-
this.withCopyFilesToContainer(filesToCopy);
51+
]);
5552

5653
this.withCommand(["--replSet", "rs0", "--keyFile", keyfileContainerPath, "--bind_ip_all"]);
5754
this.withEnvironment({ MONGO_INITDB_ROOT_USERNAME: this.username, MONGO_INITDB_ROOT_PASSWORD: this.password });
@@ -65,7 +62,10 @@ chmod 600 "${keyfileContainerPath}"`;
6562
}
6663

6764
private async initReplicaSet(startedTestContainer: StartedTestContainer) {
68-
await this.executeMongoEvalCommand(startedTestContainer, "rs.initiate();");
65+
await this.executeMongoEvalCommand(
66+
startedTestContainer,
67+
"try { rs.status(); } catch(e) { rs.initiate({_id: 'rs0', members: [{_id: 0, host: '127.0.0.1:27017'}]}); throw e; }"
68+
);
6969
await this.executeMongoEvalCommand(startedTestContainer, this.buildMongoWaitCommand());
7070
}
7171

0 commit comments

Comments
 (0)