|
1 | | -const { DockerComposeEnvironment , Wait } = require("testcontainers"); |
| 1 | +const {DockerComposeEnvironment, Wait} = require("testcontainers"); |
2 | 2 |
|
3 | | -let dbPort = 27017; |
4 | | -let exposedDbPort = 0; |
5 | | -let dbURL = "" |
6 | 3 | let test_container = null; |
7 | 4 |
|
8 | | -module.exports ={ |
9 | | - startDb: async () =>{ |
10 | | - if(process.env.DOCKER_DBC && process.env.DOCKER_DBC === '0'){ |
11 | | - console.log("use local redis on port:" + process.env.REDIS_PORT) |
12 | | - }else{ |
13 | | - console.log("start docker db") |
14 | | - dbPort = process.env.DB_PORT || 50000; |
15 | | - |
16 | | - // solve ioredis connection problem https://github.com/luin/ioredis/issues/763 |
17 | | - const environment = await new DockerComposeEnvironment(__dirname, "test-redis-db.yml") |
18 | | - .withWaitStrategy("redis_1", Wait.forLogMessage("Ready to accept connections")) |
19 | | - .up(); |
20 | | - test_container = await environment.getContainer("redis_1"); |
21 | | - exposedDbPort = test_container.getMappedPort(dbPort); |
22 | | - process.env.REDIS_PORT = exposedDbPort; |
23 | | - |
24 | | - console.log("connecting redis-server with " + exposedDbPort+ " " + test_container.getHost()); |
25 | | - } |
26 | | - return test_container; |
27 | | - }, |
| 5 | +module.exports = { |
| 6 | + startDb: async () => { |
28 | 7 |
|
29 | | - checkdb: async () =>{ |
| 8 | + console.log("starting docker db") |
| 9 | + const dbPort = 50000; |
30 | 10 |
|
| 11 | + // solve ioredis connection problem https://github.com/luin/ioredis/issues/763 |
| 12 | + const environment = await new DockerComposeEnvironment(__dirname, "test-redis-db.yml") |
| 13 | + .withWaitStrategy("redis_1", Wait.forLogMessage("Ready to accept connections")) |
| 14 | + .up(); |
| 15 | + test_container = await environment.getContainer("redis_1"); |
| 16 | + const exposedDbPort = test_container.getMappedPort(dbPort); |
| 17 | + process.env.REDIS_PORT = exposedDbPort; |
| 18 | + |
| 19 | + console.log("connecting redis-server with " + exposedDbPort + " " + test_container.getHost()); |
| 20 | + |
| 21 | + return test_container; |
31 | 22 | }, |
32 | 23 |
|
33 | | - getDbPort: () =>{ |
34 | | - return exposedDbPort |
| 24 | + checkdb: async () => { |
35 | 25 | }, |
36 | 26 |
|
37 | | - cleanDb: async () =>{ |
38 | 27 |
|
| 28 | + cleanDb: async () => { |
| 29 | + //read-only DB |
39 | 30 | }, |
40 | 31 |
|
41 | | - stopDb : () =>{ |
42 | | - if (test_container){ |
| 32 | + stopDb: () => { |
| 33 | + if (test_container) { |
43 | 34 | test_container.stop(); |
44 | 35 | test_container = null; |
45 | 36 | } |
|
0 commit comments