testcontainers 9.3.0 → 9.4.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.
Files changed (59) hide show
  1. package/dist/package.json +17 -17
  2. package/dist/src/docker/docker-client.js +2 -45
  3. package/dist/src/docker/functions/container/exec-container.d.ts +1 -7
  4. package/dist/src/docker/functions/container/exec-container.js +4 -4
  5. package/dist/src/docker/resolve-host.d.ts +6 -0
  6. package/dist/src/docker/resolve-host.js +60 -0
  7. package/dist/src/docker-compose/default-docker-compose-options.js +12 -0
  8. package/dist/src/docker-compose/functions/docker-compose-up.js +2 -2
  9. package/dist/src/docker-compose-environment/docker-compose-environment.d.ts +1 -1
  10. package/dist/src/docker-compose-environment/docker-compose-environment.js +7 -5
  11. package/dist/src/dockerfile-parser.js +2 -1
  12. package/dist/src/generic-container/create-container-options.d.ts +3 -0
  13. package/dist/src/generic-container/create-container-options.js +18 -0
  14. package/dist/src/generic-container/generic-container.d.ts +17 -26
  15. package/dist/src/generic-container/generic-container.js +80 -83
  16. package/dist/src/generic-container/started-generic-container.d.ts +5 -3
  17. package/dist/src/generic-container/started-generic-container.js +13 -6
  18. package/dist/src/index.d.ts +3 -2
  19. package/dist/src/index.js +2 -2
  20. package/dist/src/modules/abstract-started-container.d.ts +2 -0
  21. package/dist/src/modules/abstract-started-container.js +10 -1
  22. package/dist/src/modules/arangodb/arangodb-container.js +1 -1
  23. package/dist/src/modules/elasticsearch/elasticsearch-container.js +7 -1
  24. package/dist/src/modules/kafka/kafka-container.d.ts +2 -3
  25. package/dist/src/modules/kafka/kafka-container.js +8 -8
  26. package/dist/src/modules/mongodb/mongodb-container.d.ts +1 -1
  27. package/dist/src/modules/mongodb/mongodb-container.js +2 -2
  28. package/dist/src/modules/mysql/mysql-container.js +1 -1
  29. package/dist/src/modules/nats/nats-container.js +4 -2
  30. package/dist/src/modules/neo4j/neo4j-container.js +1 -1
  31. package/dist/src/modules/postgresql/postgresql-container.js +2 -2
  32. package/dist/src/port-check.js +1 -1
  33. package/dist/src/reaper.js +1 -1
  34. package/dist/src/test-container.d.ts +1 -1
  35. package/dist/src/type-guards.d.ts +2 -0
  36. package/dist/src/type-guards.js +6 -4
  37. package/dist/src/wait-for-container.d.ts +1 -1
  38. package/dist/src/wait-strategy/default-wait-strategy.d.ts +3 -0
  39. package/dist/src/wait-strategy/default-wait-strategy.js +7 -0
  40. package/dist/src/wait-strategy/health-check-wait-strategy.d.ts +5 -0
  41. package/dist/src/wait-strategy/health-check-wait-strategy.js +31 -0
  42. package/dist/src/wait-strategy/host-port-wait-strategy.d.ts +13 -0
  43. package/dist/src/wait-strategy/host-port-wait-strategy.js +54 -0
  44. package/dist/src/{http-wait-strategy.d.ts → wait-strategy/http-wait-strategy.d.ts} +1 -1
  45. package/dist/src/{http-wait-strategy.js → wait-strategy/http-wait-strategy.js} +1 -1
  46. package/dist/src/wait-strategy/log-wait-strategy.d.ts +10 -0
  47. package/dist/src/wait-strategy/log-wait-strategy.js +67 -0
  48. package/dist/src/wait-strategy/shell-wait-strategy.d.ts +7 -0
  49. package/dist/src/wait-strategy/shell-wait-strategy.js +35 -0
  50. package/dist/src/{startup-check-strategy.js → wait-strategy/startup-check-strategy.js} +2 -2
  51. package/dist/src/wait-strategy/wait-strategy.d.ts +11 -0
  52. package/dist/src/wait-strategy/wait-strategy.js +13 -0
  53. package/dist/src/{wait.d.ts → wait-strategy/wait.d.ts} +4 -1
  54. package/dist/src/wait-strategy/wait.js +22 -0
  55. package/package.json +17 -17
  56. package/dist/src/wait-strategy.d.ts +0 -32
  57. package/dist/src/wait-strategy.js +0 -137
  58. package/dist/src/wait.js +0 -17
  59. /package/dist/src/{startup-check-strategy.d.ts → wait-strategy/startup-check-strategy.d.ts} +0 -0
@@ -1,137 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.defaultWaitStrategy = exports.HealthCheckWaitStrategy = exports.LogWaitStrategy = exports.HostPortWaitStrategy = exports.AbstractWaitStrategy = void 0;
16
- const byline_1 = __importDefault(require("byline"));
17
- const logger_1 = require("./logger");
18
- const port_check_1 = require("./port-check");
19
- const retry_strategy_1 = require("./retry-strategy");
20
- const container_logs_1 = require("./docker/functions/container/container-logs");
21
- const inspect_container_1 = require("./docker/functions/container/inspect-container");
22
- class AbstractWaitStrategy {
23
- constructor() {
24
- this.startupTimeout = 60000;
25
- }
26
- withStartupTimeout(startupTimeout) {
27
- this.startupTimeout = startupTimeout;
28
- return this;
29
- }
30
- }
31
- exports.AbstractWaitStrategy = AbstractWaitStrategy;
32
- class HostPortWaitStrategy extends AbstractWaitStrategy {
33
- constructor(hostPortCheck, internalPortCheck) {
34
- super();
35
- this.hostPortCheck = hostPortCheck;
36
- this.internalPortCheck = internalPortCheck;
37
- }
38
- waitUntilReady(container, host, boundPorts) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- yield Promise.all([this.waitForHostPorts(container, boundPorts), this.waitForInternalPorts(container, boundPorts)]);
41
- });
42
- }
43
- waitForHostPorts(container, boundPorts) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- for (const [, hostPort] of boundPorts.iterator()) {
46
- logger_1.log.debug(`Waiting for host port ${hostPort} for ${container.id}`);
47
- yield this.waitForPort(container, hostPort, this.hostPortCheck);
48
- logger_1.log.debug(`Host port ${hostPort} ready for ${container.id}`);
49
- }
50
- });
51
- }
52
- waitForInternalPorts(container, boundPorts) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- for (const [internalPort] of boundPorts.iterator()) {
55
- logger_1.log.debug(`Waiting for internal port ${internalPort} for ${container.id}`);
56
- yield this.waitForPort(container, internalPort, this.internalPortCheck);
57
- logger_1.log.debug(`Internal port ${internalPort} ready for ${container.id}`);
58
- }
59
- });
60
- }
61
- waitForPort(container, port, portCheck) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const retryStrategy = new retry_strategy_1.IntervalRetryStrategy(100);
64
- yield retryStrategy.retryUntil(() => portCheck.isBound(port), (isBound) => isBound, () => {
65
- const timeout = this.startupTimeout;
66
- throw new Error(`Port ${port} not bound after ${timeout}ms for ${container.id}`);
67
- }, this.startupTimeout);
68
- });
69
- }
70
- }
71
- exports.HostPortWaitStrategy = HostPortWaitStrategy;
72
- class LogWaitStrategy extends AbstractWaitStrategy {
73
- constructor(message, times) {
74
- super();
75
- this.message = message;
76
- this.times = times;
77
- }
78
- waitUntilReady(container, host, boundPorts, startTime) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- logger_1.log.debug(`Waiting for log message "${this.message}" for ${container.id}`);
81
- const stream = yield (0, container_logs_1.containerLogs)(container, { since: startTime });
82
- return new Promise((resolve, reject) => {
83
- const startupTimeout = this.startupTimeout;
84
- const timeout = setTimeout(() => {
85
- const message = `Log message "${this.message}" not received after ${startupTimeout}ms for ${container.id}`;
86
- logger_1.log.error(message);
87
- reject(new Error(message));
88
- }, startupTimeout);
89
- const comparisonFn = (line) => {
90
- if (this.message instanceof RegExp) {
91
- return this.message.test(line);
92
- }
93
- else {
94
- return line.includes(this.message);
95
- }
96
- };
97
- let count = 0;
98
- const lineProcessor = (line) => {
99
- if (comparisonFn(line)) {
100
- if (++count === this.times) {
101
- stream.destroy();
102
- clearTimeout(timeout);
103
- resolve();
104
- }
105
- }
106
- };
107
- (0, byline_1.default)(stream)
108
- .on("data", lineProcessor)
109
- .on("err", lineProcessor)
110
- .on("end", () => {
111
- stream.destroy();
112
- clearTimeout(timeout);
113
- reject(new Error(`Log stream ended and message "${this.message}" was not received for ${container.id}`));
114
- });
115
- });
116
- });
117
- }
118
- }
119
- exports.LogWaitStrategy = LogWaitStrategy;
120
- class HealthCheckWaitStrategy extends AbstractWaitStrategy {
121
- waitUntilReady(container) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- logger_1.log.debug(`Waiting for health check for ${container.id}`);
124
- const retryStrategy = new retry_strategy_1.IntervalRetryStrategy(100);
125
- const status = yield retryStrategy.retryUntil(() => __awaiter(this, void 0, void 0, function* () { return (yield (0, inspect_container_1.inspectContainer)(container)).healthCheckStatus; }), (healthCheckStatus) => healthCheckStatus === "healthy" || healthCheckStatus === "unhealthy", () => {
126
- const timeout = this.startupTimeout;
127
- throw new Error(`Health check not healthy after ${timeout}ms for ${container.id}`);
128
- }, this.startupTimeout);
129
- if (status !== "healthy") {
130
- throw new Error(`Health check failed: ${status} for ${container.id}`);
131
- }
132
- });
133
- }
134
- }
135
- exports.HealthCheckWaitStrategy = HealthCheckWaitStrategy;
136
- const defaultWaitStrategy = (host, container) => new HostPortWaitStrategy(new port_check_1.HostPortCheck(host), new port_check_1.InternalPortCheck(container));
137
- exports.defaultWaitStrategy = defaultWaitStrategy;
package/dist/src/wait.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Wait = void 0;
4
- const wait_strategy_1 = require("./wait-strategy");
5
- const http_wait_strategy_1 = require("./http-wait-strategy");
6
- class Wait {
7
- static forLogMessage(message, times = 1) {
8
- return new wait_strategy_1.LogWaitStrategy(message, times);
9
- }
10
- static forHealthCheck() {
11
- return new wait_strategy_1.HealthCheckWaitStrategy();
12
- }
13
- static forHttp(path, port) {
14
- return new http_wait_strategy_1.HttpWaitStrategy(path, port);
15
- }
16
- }
17
- exports.Wait = Wait;