Skip to content

Commit f252ded

Browse files
github1github1
authored andcommitted
fix typing issues
1 parent b43178c commit f252ded

File tree

5 files changed

+539
-308
lines changed

5 files changed

+539
-308
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meshage",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "A simple service mesh. Messages sent within the service mesh can be consistently partitioned across members of the cluster.",
55
"main": "./index.js",
66
"types": "./index.d.ts",

src/backends/nats/docker-test-helper.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,97 @@
11
// tslint:disable:typedef no-implicit-dependencies no-any
2-
import {Docker} from 'node-docker-api';
2+
import { Docker } from 'node-docker-api';
33
// tslint:disable-next-line:no-submodule-imports
4-
import {execSync} from 'child_process';
4+
import { execSync } from 'child_process';
55
import * as getPort from 'get-port';
66

77
const testIdCounter = {};
88
const testContainers = {};
99
const testContainerPorts = {};
1010
let fetchedImage = false;
1111

12-
const docker : Docker = new Docker(process.env.CI === 'true'
13-
? {protocol: 'http', host: 'localhost', port: '2375'}
14-
: {socketPath: '/var/run/docker.sock'});
12+
const docker: Docker = new Docker(
13+
process.env.CI === 'true'
14+
? { protocol: 'http', host: 'localhost', port: '2375' }
15+
: { socketPath: '/var/run/docker.sock' }
16+
);
1517

16-
function promisifyStream(stream) {
18+
function promisifyStream(stream: NodeJS.ReadableStream) {
1719
return new Promise((resolve, reject) => {
18-
stream.on('data', (d) => console.log(d.toString()));
20+
stream.on('data', (d: Buffer) => console.log(d.toString()));
1921
stream.on('end', resolve);
2022
stream.on('error', reject);
2123
});
2224
}
2325

24-
export function stopContainersByName(...names : string[]) {
26+
export function stopContainersByName(...names: string[]) {
2527
for (const name of names) {
26-
execSync(`bash -c "docker ps | grep ${name} | awk '{print \\$1}' | xargs -I{} docker stop {}"`);
27-
execSync(`bash -c "docker ps -a | grep ${name} | awk '{print \\$1}' | xargs -I{} docker rm {}"`);
28+
execSync(
29+
`bash -c "docker ps | grep ${name} | awk '{print \\$1}' | xargs -I{} docker stop {}"`
30+
);
31+
execSync(
32+
`bash -c "docker ps -a | grep ${name} | awk '{print \\$1}' | xargs -I{} docker rm {}"`
33+
);
2834
}
2935
}
3036

3137
// tslint:disable-next-line:no-any
32-
export async function startContainer(testId : string, image : string, tag : string, ...ports : string[]) : Promise<any> {
33-
testIdCounter[testId] = (testIdCounter[testId] || 0);
38+
export async function startContainer(
39+
testId: string,
40+
image: string,
41+
tag: string,
42+
...ports: string[]
43+
): Promise<any> {
44+
testIdCounter[testId] = testIdCounter[testId] || 0;
3445
testIdCounter[testId]++;
35-
const containerName = ['jest-test-container', image, tag, testId, testIdCounter[testId]].join('-')
46+
const containerName = [
47+
'jest-test-container',
48+
image,
49+
tag,
50+
testId,
51+
testIdCounter[testId],
52+
]
53+
.join('-')
3654
.replace(/[^a-z0-9]+/g, '-');
3755
testContainers[testId] = testContainers[testId] || [];
3856
testContainers[testId].push(containerName);
3957
testContainerPorts[containerName] = testContainerPorts[containerName] || {};
40-
let container = await docker.container.get(containerName);
58+
let container = docker.container.get(containerName);
4159
try {
4260
const containerStatus = await container.status();
4361
console.log('Found existing container', containerStatus);
44-
await stopContainersByName(testId);
62+
stopContainersByName(testId);
4563
} catch (err) {
4664
// ignore
4765
}
4866
if (!fetchedImage) {
4967
fetchedImage = true;
50-
await docker.image.create({}, {fromImage: image, tag: tag})
68+
await docker.image
69+
.create({}, { fromImage: image, tag: tag })
5170
.then(promisifyStream)
52-
.then(() => docker.image.get(`${image}:${tag}`)
53-
.status());
71+
.then(() => docker.image.get(`${image}:${tag}`).status());
5472
}
5573
const createOpts = {
5674
Image: `${image}:${tag}`,
5775
name: containerName,
58-
PortBindings: {}
76+
PortBindings: {},
5977
};
6078
for (const portDef of ports) {
6179
const parts = portDef.split('/');
6280
const hostPort = await getPort();
63-
createOpts.PortBindings[`${parts[0]}/${parts[1] || 'tcp'}`] = [{HostPort: `${hostPort}`}];
81+
createOpts.PortBindings[`${parts[0]}/${parts[1] || 'tcp'}`] = [
82+
{ HostPort: `${hostPort}` },
83+
];
6484
testContainerPorts[containerName][parts[0]] = hostPort;
6585
}
6686
container = await docker.container.create(createOpts);
6787
await container.start();
68-
await new Promise((resolve) => setTimeout(resolve, 1000));
88+
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
6989
try {
70-
await container.logs({
71-
stdout: true,
72-
stderr: true
73-
})
90+
await container
91+
.logs({
92+
stdout: true,
93+
stderr: true,
94+
})
7495
.then(promisifyStream);
7596
} catch (err) {
7697
// ignore

0 commit comments

Comments
 (0)