@testcontainers/redis 10.5.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/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,25 @@
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
+ See [contributors](https://github.com/testcontainers/testcontainers-node/graphs/contributors/) for all contributors.
22
+
23
+ ----
24
+
25
+ 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 { RedisContainer, StartedRedisContainer } from "./redis-container";
package/build/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartedRedisContainer = exports.RedisContainer = void 0;
4
+ var redis_container_1 = require("./redis-container");
5
+ Object.defineProperty(exports, "RedisContainer", { enumerable: true, get: function () { return redis_container_1.RedisContainer; } });
6
+ Object.defineProperty(exports, "StartedRedisContainer", { enumerable: true, get: function () { return redis_container_1.StartedRedisContainer; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0E;AAAjE,iHAAA,cAAc,OAAA;AAAE,wHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,21 @@
1
+ import { AbstractStartedContainer, GenericContainer, StartedTestContainer } from "testcontainers";
2
+ export declare class RedisContainer extends GenericContainer {
3
+ private readonly importFilePath;
4
+ private password?;
5
+ private persistenceVolume?;
6
+ private initialImportScriptFile?;
7
+ constructor(image?: string);
8
+ withPassword(password: string): this;
9
+ withPersistence(sourcePath: string): this;
10
+ withInitialData(importScriptFile: string): this;
11
+ start(): Promise<StartedRedisContainer>;
12
+ private importInitialData;
13
+ }
14
+ export declare class StartedRedisContainer extends AbstractStartedContainer {
15
+ private readonly password?;
16
+ constructor(startedTestContainer: StartedTestContainer, password?: string | undefined);
17
+ getPort(): number;
18
+ getPassword(): string;
19
+ getConnectionUrl(): string;
20
+ executeCliCmd(cmd: string, additionalFlags?: string[]): Promise<string>;
21
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StartedRedisContainer = exports.RedisContainer = void 0;
7
+ const testcontainers_1 = require("testcontainers");
8
+ const path_1 = __importDefault(require("path"));
9
+ const REDIS_PORT = 6379;
10
+ class RedisContainer extends testcontainers_1.GenericContainer {
11
+ importFilePath = "/tmp/import.redis";
12
+ password = "";
13
+ persistenceVolume = "";
14
+ initialImportScriptFile = "";
15
+ constructor(image = "redis:7.2") {
16
+ super(image);
17
+ }
18
+ withPassword(password) {
19
+ this.password = password;
20
+ return this;
21
+ }
22
+ withPersistence(sourcePath) {
23
+ this.persistenceVolume = sourcePath;
24
+ return this;
25
+ }
26
+ /* Expect data to be in redis import script format, see https://developer.redis.com/explore/import/*/
27
+ withInitialData(importScriptFile) {
28
+ this.initialImportScriptFile = importScriptFile;
29
+ return this;
30
+ }
31
+ async start() {
32
+ this.withExposedPorts(...(this.hasExposedPorts ? this.exposedPorts : [REDIS_PORT]))
33
+ .withCommand([
34
+ "redis-server",
35
+ ...(this.password ? [`--requirepass "${this.password}"`] : []),
36
+ ...(this.persistenceVolume ? ["--save 1 1 ", "--appendonly yes"] : []),
37
+ ])
38
+ .withStartupTimeout(120000)
39
+ .withWaitStrategy(testcontainers_1.Wait.forLogMessage("Ready to accept connections tcp"));
40
+ if (this.persistenceVolume)
41
+ this.withBindMounts([{ mode: "rw", source: this.persistenceVolume, target: "/data" }]);
42
+ if (this.initialImportScriptFile) {
43
+ this.withCopyFilesToContainer([
44
+ {
45
+ mode: 666,
46
+ source: this.initialImportScriptFile,
47
+ target: this.importFilePath,
48
+ },
49
+ {
50
+ mode: 777,
51
+ source: path_1.default.join(__dirname, "import.sh"),
52
+ target: "/tmp/import.sh",
53
+ },
54
+ ]);
55
+ }
56
+ const startedRedisContainer = new StartedRedisContainer(await super.start(), this.password);
57
+ if (this.initialImportScriptFile)
58
+ await this.importInitialData(startedRedisContainer);
59
+ return startedRedisContainer;
60
+ }
61
+ async importInitialData(container) {
62
+ const re = await container.exec(`/tmp/import.sh ${this.password}`);
63
+ if (re.exitCode != 0 || re.output.includes("ERR"))
64
+ throw Error(`Could not import initial data from ${this.initialImportScriptFile}: ${re.output}`);
65
+ }
66
+ }
67
+ exports.RedisContainer = RedisContainer;
68
+ class StartedRedisContainer extends testcontainers_1.AbstractStartedContainer {
69
+ password;
70
+ constructor(startedTestContainer, password) {
71
+ super(startedTestContainer);
72
+ this.password = password;
73
+ }
74
+ getPort() {
75
+ return this.getMappedPort(REDIS_PORT);
76
+ }
77
+ getPassword() {
78
+ return this.password ? this.password.toString() : "";
79
+ }
80
+ getConnectionUrl() {
81
+ const url = new URL("", "redis://");
82
+ url.hostname = this.getHost();
83
+ url.port = this.getPort().toString();
84
+ url.password = this.getPassword();
85
+ return url.toString();
86
+ }
87
+ async executeCliCmd(cmd, additionalFlags = []) {
88
+ const result = await this.startedTestContainer.exec([
89
+ "redis-cli",
90
+ ...(this.password != "" ? [`-a ${this.password}`] : []),
91
+ `${cmd}`,
92
+ ...additionalFlags,
93
+ ]);
94
+ if (result.exitCode !== 0) {
95
+ throw new Error(`executeQuery failed with exit code ${result.exitCode} for query: ${cmd}. ${result.output}`);
96
+ }
97
+ return result.output;
98
+ }
99
+ }
100
+ exports.StartedRedisContainer = StartedRedisContainer;
101
+ //# sourceMappingURL=redis-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-container.js","s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json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@testcontainers/redis",
3
+ "version": "10.5.0",
4
+ "license": "MIT",
5
+ "keywords": [
6
+ "redis",
7
+ "testing",
8
+ "docker",
9
+ "testcontainers"
10
+ ],
11
+ "description": "Redis 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
+ "devDependencies": {
32
+ "@types/redis": "^4.0.11",
33
+ "redis": "^4.6.7"
34
+ },
35
+ "dependencies": {
36
+ "testcontainers": "^10.5.0"
37
+ }
38
+ }