2020-08-18 17:40:31 +02:00
|
|
|
import fs = require('fs');
|
2020-08-27 01:48:38 +02:00
|
|
|
import * as docker from '../src/docker';
|
2020-08-18 17:40:31 +02:00
|
|
|
import * as buildx from '../src/buildx';
|
|
|
|
import * as path from 'path';
|
|
|
|
import * as os from 'os';
|
2020-09-03 21:02:36 +02:00
|
|
|
import * as semver from 'semver';
|
|
|
|
import * as exec from '@actions/exec';
|
2020-08-18 17:40:31 +02:00
|
|
|
|
2020-09-03 21:02:36 +02:00
|
|
|
describe('getVersion', () => {
|
|
|
|
it('valid', async () => {
|
|
|
|
await exec.exec('docker', ['buildx', 'version']);
|
|
|
|
const version = await buildx.getVersion();
|
|
|
|
console.log(`version: ${version}`);
|
|
|
|
expect(semver.valid(version)).not.toBeNull();
|
|
|
|
}, 100000);
|
|
|
|
});
|
2020-08-18 17:40:31 +02:00
|
|
|
|
2020-09-03 21:02:36 +02:00
|
|
|
describe('parseVersion', () => {
|
|
|
|
test.each([
|
|
|
|
['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
|
|
|
|
['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
|
|
|
|
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2']
|
|
|
|
])('given %p', async (stdout, expected) => {
|
|
|
|
expect(await buildx.parseVersion(stdout)).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('platforms', () => {
|
2020-08-27 01:48:38 +02:00
|
|
|
async function isDaemonRunning() {
|
|
|
|
return await docker.isDaemonRunning();
|
|
|
|
}
|
|
|
|
(isDaemonRunning() ? it : it.skip)(
|
2020-09-03 21:02:36 +02:00
|
|
|
'valid',
|
2020-08-27 01:48:38 +02:00
|
|
|
async () => {
|
|
|
|
const platforms = buildx.platforms();
|
|
|
|
console.log(`platforms: ${platforms}`);
|
|
|
|
expect(platforms).not.toBeUndefined();
|
|
|
|
expect(platforms).not.toEqual('');
|
|
|
|
},
|
|
|
|
100000
|
|
|
|
);
|
2020-09-03 21:02:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('install', () => {
|
|
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
|
2021-01-04 19:03:58 +01:00
|
|
|
it('acquires v0.4.1 version of buildx', async () => {
|
|
|
|
const buildxBin = await buildx.install('v0.4.1', tmpDir);
|
2020-08-18 17:40:31 +02:00
|
|
|
console.log(buildxBin);
|
|
|
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
|
|
|
}, 100000);
|
|
|
|
it('acquires latest version of buildx', async () => {
|
|
|
|
const buildxBin = await buildx.install('latest', tmpDir);
|
|
|
|
console.log(buildxBin);
|
|
|
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
|
|
|
}, 100000);
|
|
|
|
});
|