Skip to content

Commit 95e73b6

Browse files
Change type of logs to Readable
1 parent d5d1c80 commit 95e73b6

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

src/container.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import byline from "byline";
21
import dockerode, { ContainerInspectInfo } from "dockerode";
32
import { log } from "./logger";
43
import { Duration, TemporalUnit } from "node-duration";
54
import { Command, ContainerName, ExitCode } from "./docker-client";
65
import { Port } from "./port";
6+
import { Readable } from "stream";
77

88
export type Id = string;
99

@@ -45,7 +45,7 @@ export interface Container {
4545
stop(options: StopOptions): Promise<void>;
4646
remove(options: RemoveOptions): Promise<void>;
4747
exec(options: ExecOptions): Promise<Exec>;
48-
logs(): Promise<NodeJS.ReadableStream>;
48+
logs(): Promise<Readable>;
4949
inspect(): Promise<InspectResult>;
5050
}
5151

@@ -91,13 +91,13 @@ export class DockerodeContainer implements Container {
9191
);
9292
}
9393

94-
public async logs(): Promise<NodeJS.ReadableStream> {
94+
public async logs(): Promise<Readable> {
9595
const options = {
9696
follow: true,
9797
stdout: true,
9898
stderr: true,
9999
};
100-
return (await this.container.logs(options)).setEncoding("utf-8");
100+
return (await this.container.logs(options)).setEncoding("utf-8") as Readable;
101101
}
102102

103103
public async inspect(): Promise<InspectResult> {

src/generic-container.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "path";
55
import { GenericContainer } from "./generic-container";
66
import { AlwaysPullPolicy } from "./pull-policy";
77
import { Wait } from "./wait";
8+
import { Readable } from "stream";
89

910
describe("GenericContainer", () => {
1011
jest.setTimeout(180_000);
@@ -194,8 +195,7 @@ describe("GenericContainer", () => {
194195
.withExposedPorts(8080)
195196
.start();
196197

197-
const events = await dockerodeClient.getEvents();
198-
events.setEncoding("utf-8");
198+
const events = (await dockerodeClient.getEvents()).setEncoding("utf-8") as Readable;
199199

200200
const container2 = await new GenericContainer("cristianrgreco/testcontainer", "1.1.12")
201201
.withPullPolicy(new AlwaysPullPolicy())
@@ -215,7 +215,6 @@ describe("GenericContainer", () => {
215215

216216
expect(statuses).toContain("pull");
217217

218-
// @ts-ignore
219218
events.destroy();
220219
await container1.stop();
221220
await container2.stop();

src/generic-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import { RandomUuid, Uuid } from "./uuid";
3838
import { HostPortWaitStrategy, WaitStrategy } from "./wait-strategy";
3939
import { Reaper } from "./reaper";
40+
import { Readable } from "stream";
4041

4142
export class GenericContainerBuilder {
4243
private buildArgs: BuildArgs = {};
@@ -289,7 +290,7 @@ export class StartedGenericContainer implements StartedTestContainer {
289290
return this.dockerClient.exec(this.container, command);
290291
}
291292

292-
public logs(): Promise<NodeJS.ReadableStream> {
293+
public logs(): Promise<Readable> {
293294
return this.container.logs();
294295
}
295296
}

src/modules/abstract-started-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Host } from "../docker-client-factory";
33
import { Port } from "../port";
44
import { Command, ContainerName, ExecResult } from "../docker-client";
55
import { Id as ContainerId } from "../container";
6+
import { Readable } from "stream";
67

78
export class AbstractStartedContainer {
89
constructor(protected readonly startedTestContainer: StartedTestContainer) {}
@@ -31,7 +32,7 @@ export class AbstractStartedContainer {
3132
return this.startedTestContainer.exec(command);
3233
}
3334

34-
public logs(): Promise<NodeJS.ReadableStream> {
35+
public logs(): Promise<Readable> {
3536
return this.startedTestContainer.logs();
3637
}
3738
}

src/modules/arangodb/arangodb-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class StartedArangoContainer extends AbstractStartedContainer {
3636

3737
constructor(
3838
startedTestContainer: StartedTestContainer,
39-
private port: Port,
39+
private readonly port: Port,
4040
private readonly username: string,
4141
private readonly password: string
4242
) {

src/test-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Host } from "./docker-client-factory";
1616
import { Port } from "./port";
1717
import { PullPolicy } from "./pull-policy";
1818
import { WaitStrategy } from "./wait-strategy";
19+
import { Readable } from "stream";
1920

2021
export interface TestContainer {
2122
start(): Promise<StartedTestContainer>;
@@ -50,7 +51,7 @@ export interface StartedTestContainer {
5051
getName(): ContainerName;
5152
getId(): ContainerId;
5253
exec(command: Command[]): Promise<ExecResult>;
53-
logs(): Promise<NodeJS.ReadableStream>;
54+
logs(): Promise<Readable>;
5455
}
5556

5657
export interface StoppedTestContainer {}

src/wait-strategy.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,22 @@ export class LogWaitStrategy extends AbstractWaitStrategy {
8989
stream
9090
.on("data", (line) => {
9191
if (line.includes(this.message)) {
92-
this.destroyStream(stream);
92+
stream.destroy();
9393
resolve();
9494
}
9595
})
9696
.on("err", (line) => {
9797
if (line.includes(this.message)) {
98-
this.destroyStream(stream);
98+
stream.destroy();
9999
resolve();
100100
}
101101
})
102102
.on("end", () => {
103-
this.destroyStream(stream);
103+
stream.destroy();
104104
reject();
105105
});
106106
});
107107
}
108-
109-
private destroyStream(stream: NodeJS.ReadableStream) {
110-
// @ts-ignore
111-
stream.destroy();
112-
}
113108
}
114109

115110
export class HealthCheckWaitStrategy extends AbstractWaitStrategy {

0 commit comments

Comments
 (0)