Skip to content

Commit 29f1eeb

Browse files
committed
Use built-in getExecOutput
Signed-off-by: CrazyMax <[email protected]>
1 parent faca783 commit 29f1eeb

6 files changed

Lines changed: 5267 additions & 5277 deletions

File tree

__tests__/buildx.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
import fs = require('fs');
2-
import * as docker from '../src/docker';
32
import * as buildx from '../src/buildx';
43
import * as path from 'path';
54
import * as os from 'os';
65
import * as semver from 'semver';
76
import * as exec from '@actions/exec';
87

8+
describe('isAvailable', () => {
9+
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
10+
buildx.isAvailable();
11+
12+
expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], {
13+
silent: true,
14+
ignoreReturnCode: true
15+
});
16+
});
17+
918
describe('getVersion', () => {
10-
it('valid', async () => {
11-
await exec.exec('docker', ['buildx', 'version']);
12-
const version = await buildx.getVersion();
13-
console.log(`version: ${version}`);
14-
expect(semver.valid(version)).not.toBeNull();
15-
}, 100000);
19+
async function isDaemonRunning() {
20+
return await exec
21+
.getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], {
22+
ignoreReturnCode: true,
23+
silent: true
24+
})
25+
.then(res => {
26+
return !res.stdout.includes(' ') && res.exitCode == 0;
27+
});
28+
}
29+
(isDaemonRunning() ? it : it.skip)(
30+
'valid',
31+
async () => {
32+
const version = await buildx.getVersion();
33+
console.log(`version: ${version}`);
34+
expect(semver.valid(version)).not.toBeNull();
35+
},
36+
100000
37+
);
1638
});
1739

1840
describe('parseVersion', () => {
@@ -27,7 +49,14 @@ describe('parseVersion', () => {
2749

2850
describe('inspect', () => {
2951
async function isDaemonRunning() {
30-
return await docker.isDaemonRunning();
52+
return await exec
53+
.getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], {
54+
ignoreReturnCode: true,
55+
silent: true
56+
})
57+
.then(res => {
58+
return !res.stdout.includes(' ') && res.exitCode == 0;
59+
});
3160
}
3261
(isDaemonRunning() ? it : it.skip)(
3362
'valid',

0 commit comments

Comments
 (0)