@testcontainers/toxiproxy 10.17.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 - 2023 Cristian Greco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Testcontainers
2
+
3
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=116414510&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=EastUs)
4
+
5
+ [![Test](https://github.com/testcontainers/testcontainers-node/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/testcontainers/testcontainers-node/actions/workflows/test.yml)
6
+ [![npm version](https://badge.fury.io/js/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
7
+ [![npm version](https://img.shields.io/npm/dm/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
8
+
9
+ ![Testcontainers Banner](https://github.com/testcontainers/testcontainers-node/raw/main/docs/site/logo.png)
10
+
11
+ ## [📖 Documentation](https://node.testcontainers.org/)
12
+
13
+ ## License
14
+
15
+ See [LICENSE](https://github.com/testcontainers/testcontainers-node/blob/main/LICENSE).
16
+
17
+ ## Copyright
18
+
19
+ Copyright (c) 2018 - 2023 Cristian Greco and other authors.
20
+
21
+ ## Contributing
22
+
23
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute to this repo.
24
+
25
+ See [contributors](https://github.com/testcontainers/testcontainers-node/graphs/contributors/) for all contributors.
26
+
27
+
28
+ ----
29
+
30
+ Join our [Slack workspace](https://slack.testcontainers.org/) | [Testcontainers OSS](https://java.testcontainers.org/) | [Testcontainers Cloud](https://www.testcontainers.cloud/)
@@ -0,0 +1 @@
1
+ export { ToxiProxyContainer, StartedToxiProxyContainer, CreatedProxy } from "./toxiproxy-container";
package/build/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartedToxiProxyContainer = exports.ToxiProxyContainer = void 0;
4
+ var toxiproxy_container_1 = require("./toxiproxy-container");
5
+ Object.defineProperty(exports, "ToxiProxyContainer", { enumerable: true, get: function () { return toxiproxy_container_1.ToxiProxyContainer; } });
6
+ Object.defineProperty(exports, "StartedToxiProxyContainer", { enumerable: true, get: function () { return toxiproxy_container_1.StartedToxiProxyContainer; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAoG;AAA3F,yHAAA,kBAAkB,OAAA;AAAE,gIAAA,yBAAyB,OAAA"}
@@ -0,0 +1,25 @@
1
+ import { AbstractStartedContainer, GenericContainer, StartedTestContainer } from "testcontainers";
2
+ import * as TPClient from "toxiproxy-node-client";
3
+ export interface CreatedProxy {
4
+ host: string;
5
+ port: number;
6
+ instance: TPClient.Proxy;
7
+ setEnabled: (enabled: boolean) => Promise<TPClient.Proxy>;
8
+ }
9
+ export { TPClient };
10
+ export declare class ToxiProxyContainer extends GenericContainer {
11
+ constructor(image?: string);
12
+ start(): Promise<StartedToxiProxyContainer>;
13
+ }
14
+ export declare class StartedToxiProxyContainer extends AbstractStartedContainer {
15
+ /**
16
+ *
17
+ */
18
+ readonly client: TPClient.Toxiproxy;
19
+ /**
20
+ *
21
+ * @param startedTestContainer
22
+ */
23
+ constructor(startedTestContainer: StartedTestContainer);
24
+ createProxy(createProxyBody: Omit<TPClient.ICreateProxyBody, "listen">): Promise<CreatedProxy>;
25
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.StartedToxiProxyContainer = exports.ToxiProxyContainer = exports.TPClient = void 0;
27
+ const testcontainers_1 = require("testcontainers");
28
+ const TPClient = __importStar(require("toxiproxy-node-client"));
29
+ exports.TPClient = TPClient;
30
+ const CONTROL_PORT = 8474;
31
+ const FIRST_PROXIED_PORT = 8666;
32
+ const PORT_ARRAY = Array.from({ length: 32 }, (_, i) => i + FIRST_PROXIED_PORT);
33
+ class ToxiProxyContainer extends testcontainers_1.GenericContainer {
34
+ constructor(image = "ghcr.io/shopify/toxiproxy:2.11.0") {
35
+ super(image);
36
+ this.withExposedPorts(CONTROL_PORT, ...PORT_ARRAY)
37
+ .withWaitStrategy(testcontainers_1.Wait.forHttp("/version", CONTROL_PORT))
38
+ .withStartupTimeout(30000);
39
+ }
40
+ async start() {
41
+ return new StartedToxiProxyContainer(await super.start());
42
+ }
43
+ }
44
+ exports.ToxiProxyContainer = ToxiProxyContainer;
45
+ class StartedToxiProxyContainer extends testcontainers_1.AbstractStartedContainer {
46
+ /**
47
+ *
48
+ */
49
+ client;
50
+ /**
51
+ *
52
+ * @param startedTestContainer
53
+ */
54
+ constructor(startedTestContainer) {
55
+ super(startedTestContainer);
56
+ this.client = new TPClient.Toxiproxy(`http://${this.getHost()}:${this.getMappedPort(CONTROL_PORT)}`);
57
+ }
58
+ async createProxy(createProxyBody) {
59
+ // Firstly get the list of proxies to find the next available port
60
+ const proxies = await this.client.getAll();
61
+ const usedPorts = PORT_ARRAY.reduce((acc, port) => {
62
+ acc[port] = false;
63
+ return acc;
64
+ }, {});
65
+ for (const proxy of Object.values(proxies)) {
66
+ const lastColon = proxy.listen.lastIndexOf(":");
67
+ const port = parseInt(proxy.listen.substring(lastColon + 1), 10);
68
+ usedPorts[port] = true;
69
+ }
70
+ // Find the first available port
71
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
72
+ const port = Object.entries(usedPorts).find(([_, used]) => !used);
73
+ if (!port) {
74
+ throw new Error("No available ports left");
75
+ }
76
+ const listen = `0.0.0.0:${port[0]}`;
77
+ const proxy = await this.client.createProxy({
78
+ ...createProxyBody,
79
+ listen,
80
+ });
81
+ const setEnabled = (enabled) => proxy.update({
82
+ enabled,
83
+ listen,
84
+ upstream: createProxyBody.upstream,
85
+ });
86
+ return {
87
+ host: this.getHost(),
88
+ port: this.getMappedPort(parseInt(port[0], 10)),
89
+ instance: proxy,
90
+ setEnabled,
91
+ };
92
+ }
93
+ }
94
+ exports.StartedToxiProxyContainer = StartedToxiProxyContainer;
95
+ //# sourceMappingURL=toxiproxy-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toxiproxy-container.js","sourceRoot":"","sources":["../src/toxiproxy-container.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwG;AACxG,gEAAkD;AAezC,4BAAQ;AAbjB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC;AAYhF,MAAa,kBAAmB,SAAQ,iCAAgB;IACtD,YAAY,KAAK,GAAG,kCAAkC;QACpD,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,GAAG,UAAU,CAAC;aAC/C,gBAAgB,CAAC,qBAAI,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;aACxD,kBAAkB,CAAC,KAAM,CAAC,CAAC;IAChC,CAAC;IAEe,KAAK,CAAC,KAAK;QACzB,OAAO,IAAI,yBAAyB,CAAC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF;AAZD,gDAYC;AAED,MAAa,yBAA0B,SAAQ,yCAAwB;IACrE;;OAEG;IACa,MAAM,CAAqB;IAE3C;;;OAGG;IACH,YAAY,oBAA0C;QACpD,KAAK,CAAC,oBAAoB,C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GAAG,eAAe;YAClB,MAAM;SACP,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE,CACtC,KAAK,CAAC,MAAM,CAAC;YACX,OAAO;YACP,MAAM;YACN,QAAQ,EAAE,eAAe,CAAC,QAAQ;SACnC,CAAC,CAAC;QAEL,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;YACpB,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,QAAQ,EAAE,KAAK;YACf,UAAU;SACX,CAAC;IACJ,CAAC;CACF;AA3DD,8DA2DC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@testcontainers/toxiproxy",
3
+ "version": "10.17.1",
4
+ "license": "MIT",
5
+ "keywords": [
6
+ "toxiproxy",
7
+ "testing",
8
+ "docker",
9
+ "testcontainers"
10
+ ],
11
+ "description": "Toxiproxy module for Testcontainers",
12
+ "homepage": "https://github.com/testcontainers/testcontainers-node#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/testcontainers/testcontainers-node"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/testcontainers/testcontainers-node/issues"
19
+ },
20
+ "main": "build/index.js",
21
+ "files": [
22
+ "build"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
29
+ "build": "tsc --project tsconfig.build.json"
30
+ },
31
+ "dependencies": {
32
+ "testcontainers": "^10.17.1",
33
+ "toxiproxy-node-client": "^4.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@testcontainers/redis": "^10.16.0",
37
+ "redis": "^4.7.0"
38
+ }
39
+ }