testcontainers 8.12.0 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -169,7 +169,8 @@ const { GenericContainer } = require("testcontainers");
|
|
|
169
169
|
|
|
170
170
|
const container = await new GenericContainer("alpine")
|
|
171
171
|
.start();
|
|
172
|
-
|
|
172
|
+
|
|
173
|
+
await container.restart();
|
|
173
174
|
```
|
|
174
175
|
|
|
175
176
|
Creating a container with a specified name:
|
|
@@ -145,7 +145,7 @@ class GenericContainer {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
if (this.tarToCopy) {
|
|
148
|
-
|
|
148
|
+
this.tarToCopy.finalize();
|
|
149
149
|
yield (0, put_container_archive_1.putContainerArchive)({ container, stream: this.tarToCopy, containerPath: "/" });
|
|
150
150
|
}
|
|
151
151
|
logger_1.log.info(`Starting container ${this.imageName} with ID: ${container.id}`);
|
package/dist/index.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export { ArangoDBContainer, StartedArangoContainer } from "./modules/arangodb/ar
|
|
|
16
16
|
export { ElasticsearchContainer, StartedElasticsearchContainer } from "./modules/elasticsearch/elasticsearch-container";
|
|
17
17
|
export { MySqlContainer, StartedMySqlContainer } from "./modules/mysql/mysql-container";
|
|
18
18
|
export { NatsContainer, StartedNatsContainer, NatsConnectionOptions, NatsTlsOptions, } from "./modules/nats/nats-container";
|
|
19
|
+
export { MongoDBContainer, StartedMongoDBContainer } from "./modules/mongodb/mongodb-container";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StartedNatsContainer = exports.NatsContainer = exports.StartedMySqlContainer = exports.MySqlContainer = exports.StartedElasticsearchContainer = exports.ElasticsearchContainer = exports.StartedArangoContainer = exports.ArangoDBContainer = exports.StartedNeo4jContainer = exports.Neo4jContainer = exports.StartedKafkaContainer = exports.KafkaContainer = exports.StartedPostgreSqlContainer = exports.PostgreSqlContainer = exports.AlwaysPullPolicy = exports.DefaultPullPolicy = exports.Wait = exports.StoppedNetwork = exports.StartedNetwork = exports.Network = exports.DownedDockerComposeEnvironment = exports.StoppedDockerComposeEnvironment = exports.StartedDockerComposeEnvironment = exports.DockerComposeEnvironment = exports.TestContainers = exports.GenericContainerBuilder = exports.GenericContainer = void 0;
|
|
3
|
+
exports.StartedMongoDBContainer = exports.MongoDBContainer = exports.StartedNatsContainer = exports.NatsContainer = exports.StartedMySqlContainer = exports.MySqlContainer = exports.StartedElasticsearchContainer = exports.ElasticsearchContainer = exports.StartedArangoContainer = exports.ArangoDBContainer = exports.StartedNeo4jContainer = exports.Neo4jContainer = exports.StartedKafkaContainer = exports.KafkaContainer = exports.StartedPostgreSqlContainer = exports.PostgreSqlContainer = exports.AlwaysPullPolicy = exports.DefaultPullPolicy = exports.Wait = exports.StoppedNetwork = exports.StartedNetwork = exports.Network = exports.DownedDockerComposeEnvironment = exports.StoppedDockerComposeEnvironment = exports.StartedDockerComposeEnvironment = exports.DockerComposeEnvironment = exports.TestContainers = exports.GenericContainerBuilder = exports.GenericContainer = void 0;
|
|
4
4
|
var generic_container_1 = require("./generic-container/generic-container");
|
|
5
5
|
Object.defineProperty(exports, "GenericContainer", { enumerable: true, get: function () { return generic_container_1.GenericContainer; } });
|
|
6
6
|
var generic_container_builder_1 = require("./generic-container/generic-container-builder");
|
|
@@ -45,3 +45,6 @@ Object.defineProperty(exports, "StartedMySqlContainer", { enumerable: true, get:
|
|
|
45
45
|
var nats_container_1 = require("./modules/nats/nats-container");
|
|
46
46
|
Object.defineProperty(exports, "NatsContainer", { enumerable: true, get: function () { return nats_container_1.NatsContainer; } });
|
|
47
47
|
Object.defineProperty(exports, "StartedNatsContainer", { enumerable: true, get: function () { return nats_container_1.StartedNatsContainer; } });
|
|
48
|
+
var mongodb_container_1 = require("./modules/mongodb/mongodb-container");
|
|
49
|
+
Object.defineProperty(exports, "MongoDBContainer", { enumerable: true, get: function () { return mongodb_container_1.MongoDBContainer; } });
|
|
50
|
+
Object.defineProperty(exports, "StartedMongoDBContainer", { enumerable: true, get: function () { return mongodb_container_1.StartedMongoDBContainer; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GenericContainer } from "../../generic-container/generic-container";
|
|
2
|
+
import { AbstractStartedContainer } from "../abstract-started-container";
|
|
3
|
+
import { StartedTestContainer } from "../../test-container";
|
|
4
|
+
export declare class MongoDBContainer extends GenericContainer {
|
|
5
|
+
private readonly dockerImageName;
|
|
6
|
+
constructor(image?: string);
|
|
7
|
+
start(): Promise<StartedMongoDBContainer>;
|
|
8
|
+
protected postStart(startedTestContainer: StartedTestContainer): Promise<void>;
|
|
9
|
+
private initReplicaSet;
|
|
10
|
+
private executeMongoEvalCommand;
|
|
11
|
+
private buildMongoEvalCommand;
|
|
12
|
+
private getMongoCmdBasedOnImageTag;
|
|
13
|
+
private checkMongoNodeExitCode;
|
|
14
|
+
private buildMongoWaitCommand;
|
|
15
|
+
}
|
|
16
|
+
export declare class StartedMongoDBContainer extends AbstractStartedContainer {
|
|
17
|
+
constructor(startedTestContainer: StartedTestContainer);
|
|
18
|
+
getConnectionString(): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StartedMongoDBContainer = exports.MongoDBContainer = void 0;
|
|
13
|
+
const generic_container_1 = require("../../generic-container/generic-container");
|
|
14
|
+
const abstract_started_container_1 = require("../abstract-started-container");
|
|
15
|
+
const wait_1 = require("../../wait");
|
|
16
|
+
const docker_image_name_1 = require("../../docker-image-name");
|
|
17
|
+
const MONGODB_PORT = 27017;
|
|
18
|
+
class MongoDBContainer extends generic_container_1.GenericContainer {
|
|
19
|
+
constructor(image = "mongo:4.0.1") {
|
|
20
|
+
super(image);
|
|
21
|
+
this.dockerImageName = docker_image_name_1.DockerImageName.fromString(this.image);
|
|
22
|
+
}
|
|
23
|
+
start() {
|
|
24
|
+
const _super = Object.create(null, {
|
|
25
|
+
start: { get: () => super.start }
|
|
26
|
+
});
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
this.withExposedPorts(MONGODB_PORT)
|
|
29
|
+
.withCmd(["--replSet", "rs0"])
|
|
30
|
+
.withWaitStrategy(wait_1.Wait.forLogMessage(new RegExp(".*waiting for connections.*", "i")))
|
|
31
|
+
.withStartupTimeout(120000);
|
|
32
|
+
return new StartedMongoDBContainer(yield _super.start.call(this));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
postStart(startedTestContainer) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield this.initReplicaSet(startedTestContainer);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
initReplicaSet(startedTestContainer) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield this.executeMongoEvalCommand(startedTestContainer, "rs.initiate();");
|
|
43
|
+
yield this.executeMongoEvalCommand(startedTestContainer, this.buildMongoWaitCommand());
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
executeMongoEvalCommand(startedTestContainer, command) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const execResult = yield startedTestContainer.exec(this.buildMongoEvalCommand(command));
|
|
49
|
+
this.checkMongoNodeExitCode(execResult);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
buildMongoEvalCommand(command) {
|
|
53
|
+
return [this.getMongoCmdBasedOnImageTag(), "--eval", command];
|
|
54
|
+
}
|
|
55
|
+
getMongoCmdBasedOnImageTag() {
|
|
56
|
+
return parseInt(this.dockerImageName.tag[0]) >= 5 ? "mongosh" : "mongo";
|
|
57
|
+
}
|
|
58
|
+
checkMongoNodeExitCode(execResult) {
|
|
59
|
+
const { exitCode, output } = execResult;
|
|
60
|
+
if (execResult.exitCode !== 0) {
|
|
61
|
+
throw new Error(`Error running mongo command. Exit code ${exitCode}: ${output}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
buildMongoWaitCommand() {
|
|
65
|
+
return `
|
|
66
|
+
var attempt = 0;
|
|
67
|
+
while(db.runCommand({isMaster: 1}).ismaster==false) {
|
|
68
|
+
if (attempt > 60) {
|
|
69
|
+
quit(1);
|
|
70
|
+
}
|
|
71
|
+
print(attempt); sleep(100); attempt++;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MongoDBContainer = MongoDBContainer;
|
|
77
|
+
class StartedMongoDBContainer extends abstract_started_container_1.AbstractStartedContainer {
|
|
78
|
+
constructor(startedTestContainer) {
|
|
79
|
+
super(startedTestContainer);
|
|
80
|
+
}
|
|
81
|
+
getConnectionString() {
|
|
82
|
+
return `mongodb://${this.getHost()}:${this.getMappedPort(MONGODB_PORT)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.StartedMongoDBContainer = StartedMongoDBContainer;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testcontainers",
|
|
3
3
|
"author": "Cristian Greco",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.13.0",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"keywords": [
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"docker-compose": "^0.23.17",
|
|
42
42
|
"dockerode": "^3.3.1",
|
|
43
43
|
"get-port": "^5.1.1",
|
|
44
|
+
"mongoose": "^5.13.15",
|
|
44
45
|
"properties-reader": "^2.2.0",
|
|
45
46
|
"ssh-remote-port-forward": "^1.0.4",
|
|
46
47
|
"tar-fs": "^2.1.1"
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"kafkajs": "^1.16.0",
|
|
67
68
|
"lint-staged": "^12.3.8",
|
|
68
69
|
"mysql2": "^2.3.3",
|
|
70
|
+
"nats": "^2.7.1",
|
|
69
71
|
"neo4j-driver": "^4.4.5",
|
|
70
72
|
"node-fetch": "^2.6.7",
|
|
71
73
|
"pg": "^8.7.3",
|
|
@@ -74,8 +76,7 @@
|
|
|
74
76
|
"ts-jest": "^27.1.4",
|
|
75
77
|
"ts-node": "^10.7.0",
|
|
76
78
|
"typescript": "^4.6.3",
|
|
77
|
-
"wait-for-expect": "^3.0.2"
|
|
78
|
-
"nats": "^2.7.1"
|
|
79
|
+
"wait-for-expect": "^3.0.2"
|
|
79
80
|
},
|
|
80
81
|
"lint-staged": {
|
|
81
82
|
"src/**/*.ts": [
|