@@ -3,7 +3,6 @@ import { AbstractStartedContainer, ExecResult, GenericContainer, StartedTestCont
33import { promises as fs } from "fs" ;
44import os from "os" ;
55import path from "path" ;
6- import { FileToCopy } from "testcontainers/src/types" ;
76
87const 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