Exec class

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-20 09:01:01 +01:00
parent 2915834633
commit 35a8193474
10 changed files with 171 additions and 104 deletions

View File

@@ -19,10 +19,10 @@ import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';
import * as semver from 'semver';
import * as exec from '@actions/exec';
import {Buildx} from '../../src/buildx/buildx';
import {Context} from '../../src/context';
import {Exec} from '../../src/exec';
import {Cert} from '../../src/types/buildx';
@@ -91,7 +91,7 @@ describe('certsDir', () => {
describe('isAvailable', () => {
it('docker cli', async () => {
const execSpy = jest.spyOn(exec, 'getExecOutput');
const execSpy = jest.spyOn(Exec, 'getExecOutput');
const buildx = new Buildx({
standalone: false
});
@@ -103,7 +103,7 @@ describe('isAvailable', () => {
});
});
it('standalone', async () => {
const execSpy = jest.spyOn(exec, 'getExecOutput');
const execSpy = jest.spyOn(Exec, 'getExecOutput');
const buildx = new Buildx({
standalone: true
});
@@ -118,7 +118,7 @@ describe('isAvailable', () => {
describe('printInspect', () => {
it('prints builder2 instance', async () => {
const execSpy = jest.spyOn(exec, 'exec');
const execSpy = jest.spyOn(Exec, 'exec');
const buildx = new Buildx({
standalone: true
});
@@ -133,7 +133,7 @@ describe('printInspect', () => {
describe('printVersion', () => {
it('docker cli', async () => {
const execSpy = jest.spyOn(exec, 'exec');
const execSpy = jest.spyOn(Exec, 'exec');
const buildx = new Buildx({
standalone: false
});
@@ -143,7 +143,7 @@ describe('printVersion', () => {
});
});
it('standalone', async () => {
const execSpy = jest.spyOn(exec, 'exec');
const execSpy = jest.spyOn(Exec, 'exec');
const buildx = new Buildx({
standalone: true
});

View File

@@ -15,11 +15,11 @@
*/
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';
import {Exec} from '../src/exec';
beforeEach(() => {
jest.clearAllMocks();
@@ -49,7 +49,7 @@ describe('configDir', () => {
describe('isAvailable', () => {
it('cli', async () => {
const execSpy = jest.spyOn(exec, 'getExecOutput');
const execSpy = jest.spyOn(Exec, 'getExecOutput');
await Docker.isAvailable();
// eslint-disable-next-line jest/no-standalone-expect
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
@@ -61,7 +61,7 @@ describe('isAvailable', () => {
describe('printVersion', () => {
it('call docker version', async () => {
const execSpy = jest.spyOn(exec, 'exec');
const execSpy = jest.spyOn(Exec, 'exec');
await Docker.printVersion().catch(() => {
// noop
});
@@ -71,7 +71,7 @@ describe('printVersion', () => {
describe('printInfo', () => {
it('call docker info', async () => {
const execSpy = jest.spyOn(exec, 'exec');
const execSpy = jest.spyOn(Exec, 'exec');
await Docker.printInfo().catch(() => {
// noop
});

51
__tests__/exec.test.ts Normal file
View File

@@ -0,0 +1,51 @@
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import {Exec} from '../src/exec';
beforeEach(() => {
jest.clearAllMocks();
});
describe('exec', () => {
it('returns docker version', async () => {
const execSpy = jest.spyOn(Exec, 'exec');
await Exec.exec('docker', ['version'], {
ignoreReturnCode: true,
silent: true
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], {
ignoreReturnCode: true,
silent: true
});
});
});
describe('getExecOutput', () => {
it('returns docker version', async () => {
const execSpy = jest.spyOn(Exec, 'getExecOutput');
await Exec.getExecOutput('docker', ['version'], {
ignoreReturnCode: true,
silent: true
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], {
ignoreReturnCode: true,
silent: true
});
});
});