Skip to content

Commit

Permalink
fixup! chore: add attachToContainer methods
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Sep 14, 2023
1 parent 715bfe3 commit fd5e26d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions packages/main/src/plugin/container-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1923,4 +1923,48 @@ describe('attachToContainer', () => {
expect(containerRegistry.getStreamsOutputPerContainerId().get(dockerodeContainer.id)).toBeUndefined();
expect(containerRegistry.getStreamsPerContainerId().get(dockerodeContainer.id)).toBeUndefined();
});

test('container do not attach stream as tty but no OpenStdin', async () => {
const fakeDockerode = {} as Dockerode;

const engine = {
name: 'docker1',
id: 'docker1',
connection: {
type: 'docker',
},
api: fakeDockerode,
} as InternalContainerProvider;

const attachMock = vi.fn();
const inspectMock = vi.fn();

const dockerodeContainer = {
id: '1234',
attach: attachMock,
inspect: inspectMock,
} as unknown as Dockerode.Container;

inspectMock.mockResolvedValue({
Config: {
Tty: true,
OpenStdin: false,
},
});

// create a read/write stream
const stream = new PassThrough();
// need to reply with a stream
attachMock.mockResolvedValue(stream);

await containerRegistry.attachToContainer(engine, dockerodeContainer);

const data = 'log message';
//send some data
stream.write(data);

expect(attachMock).not.toBeCalled();
expect(containerRegistry.getStreamsOutputPerContainerId().get(dockerodeContainer.id)).toBeUndefined();
expect(containerRegistry.getStreamsPerContainerId().get(dockerodeContainer.id)).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion packages/main/src/plugin/container-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ export class ContainerProviderRegistry {
openStdin = containerInspectInfo.Config.OpenStdin;
}
// no tty and no stdin, do not need to try to attach a terminal
if (!hasTty && !openStdin) {
if (!hasTty || !openStdin) {
return;
}

Expand Down

0 comments on commit fd5e26d

Please sign in to comment.