mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
Merge pull request #17 from crazy-max/docker-configdir
docker: configDir
This commit is contained in:
commit
d21d31d108
@ -14,8 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||
import * as exec from '@actions/exec';
|
||||
import path from 'path';
|
||||
import osm = require('os');
|
||||
|
||||
import {Docker} from '../src/docker';
|
||||
|
||||
@ -23,10 +25,32 @@ beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('configDir', () => {
|
||||
const originalEnv = process.env;
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
DOCKER_CONFIG: '/var/docker/config'
|
||||
};
|
||||
});
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
it('returns default', async () => {
|
||||
process.env.DOCKER_CONFIG = '';
|
||||
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
|
||||
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
|
||||
});
|
||||
it('returns from env', async () => {
|
||||
expect(Docker.configDir).toEqual('/var/docker/config');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAvailable', () => {
|
||||
it('cli', () => {
|
||||
const execSpy = jest.spyOn(exec, 'getExecOutput');
|
||||
Docker.isAvailable();
|
||||
Docker.isAvailable;
|
||||
// eslint-disable-next-line jest/no-standalone-expect
|
||||
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
|
||||
silent: true,
|
||||
|
@ -39,7 +39,7 @@ export class Buildx {
|
||||
this.context = opts.context;
|
||||
this.inputs = new Inputs(this.context);
|
||||
this.install = new Install({standalone: opts.standalone});
|
||||
this.standalone = opts?.standalone ?? !Docker.isAvailable();
|
||||
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||
}
|
||||
|
||||
public getCommand(args: Array<string>) {
|
||||
|
@ -14,10 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
export class Docker {
|
||||
public static isAvailable(): boolean {
|
||||
static get configDir(): string {
|
||||
return process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
|
||||
}
|
||||
|
||||
static get isAvailable(): boolean {
|
||||
let dockerAvailable = false;
|
||||
exec
|
||||
.getExecOutput('docker', undefined, {
|
||||
@ -39,7 +45,7 @@ export class Docker {
|
||||
}
|
||||
|
||||
public static async printVersion(standalone?: boolean) {
|
||||
const noDocker = standalone ?? !Docker.isAvailable();
|
||||
const noDocker = standalone ?? !Docker.isAvailable;
|
||||
if (noDocker) {
|
||||
return;
|
||||
}
|
||||
@ -49,7 +55,7 @@ export class Docker {
|
||||
}
|
||||
|
||||
public static async printInfo(standalone?: boolean) {
|
||||
const noDocker = standalone ?? !Docker.isAvailable();
|
||||
const noDocker = standalone ?? !Docker.isAvailable;
|
||||
if (noDocker) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user