Skip to content

Commit

Permalink
Merge pull request #56 from crazy-max/docker-context
Browse files Browse the repository at this point in the history
docker: context method
  • Loading branch information
crazy-max committed Feb 25, 2023
2 parents e08fc16 + 97e647f commit 1cc5fc8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions __tests__/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ describe('isAvailable', () => {
});
});

describe('context', () => {
it('call docker context show', async () => {
const execSpy = jest.spyOn(Exec, 'getExecOutput');
await Docker.context().catch(() => {
// noop
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['context', 'show'], {
ignoreReturnCode: true,
silent: true
});
});
});

describe('printVersion', () => {
it('call docker version', async () => {
const execSpy = jest.spyOn(Exec, 'exec');
Expand Down
12 changes: 12 additions & 0 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export class Docker {
});
}

public static async context(): Promise<string> {
return await Exec.getExecOutput(`docker`, ['context', 'show'], {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
}

public static async printVersion(): Promise<void> {
await Exec.exec('docker', ['version']);
}
Expand Down

0 comments on commit 1cc5fc8

Please sign in to comment.