diff --git a/__tests__/aws.test.ts b/__tests__/aws.test.ts index 30e82a6..55a368c 100644 --- a/__tests__/aws.test.ts +++ b/__tests__/aws.test.ts @@ -1,5 +1,6 @@ import {beforeEach, describe, expect, jest, test} from '@jest/globals'; import {AuthorizationData} from '@aws-sdk/client-ecr'; + import * as aws from '../src/aws'; describe('isECR', () => { diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 9f792de..8e46253 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -1,4 +1,5 @@ import {expect, test} from '@jest/globals'; + import {getInputs} from '../src/context'; test('with password and username getInputs does not throw error', async () => { diff --git a/__tests__/docker.test.ts b/__tests__/docker.test.ts index e480ba7..1f45be5 100644 --- a/__tests__/docker.test.ts +++ b/__tests__/docker.test.ts @@ -1,14 +1,15 @@ import {expect, jest, test} from '@jest/globals'; -import {loginStandard, logout} from '../src/docker'; import * as path from 'path'; -import * as exec from '@actions/exec'; + +import {loginStandard, logout} from '../src/docker'; +import {Exec} from '@docker/actions-toolkit/lib/exec'; process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner'); test('loginStandard calls exec', async () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => { + const execSpy = jest.spyOn(Exec, 'getExecOutput').mockImplementation(async () => { return { exitCode: expect.any(Number), stdout: expect.any(Function), @@ -32,7 +33,7 @@ test('loginStandard calls exec', async () => { test('logout calls exec', async () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => { + const execSpy = jest.spyOn(Exec, 'getExecOutput').mockImplementation(async () => { return { exitCode: expect.any(Number), stdout: expect.any(Function), diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index 8e4f153..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import {expect, jest, test} from '@jest/globals'; -import osm = require('os'); - -import {main} from '../src/main'; -import * as docker from '../src/docker'; -import * as stateHelper from '../src/state-helper'; - -test('errors without username and password', async () => { - jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); - process.env['INPUT_LOGOUT'] = 'true'; // default value - await expect(main()).rejects.toThrow(new Error('Username and password required')); -}); - -test('successful with username and password', async () => { - jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); - const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry'); - const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout'); - const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve()); - - const username = 'dbowie'; - process.env[`INPUT_USERNAME`] = username; - - const password = 'groundcontrol'; - process.env[`INPUT_PASSWORD`] = password; - - const ecr = 'auto'; - process.env['INPUT_ECR'] = ecr; - - const logout = false; - process.env['INPUT_LOGOUT'] = String(logout); - - await main(); - - expect(setRegistrySpy).toHaveBeenCalledWith(''); - expect(setLogoutSpy).toHaveBeenCalledWith(logout); - expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr); -}); - -test('calls docker login', async () => { - jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); - const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry'); - const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout'); - const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve()); - - const username = 'dbowie'; - process.env[`INPUT_USERNAME`] = username; - - const password = 'groundcontrol'; - process.env[`INPUT_PASSWORD`] = password; - - const registry = 'ghcr.io'; - process.env[`INPUT_REGISTRY`] = registry; - - const ecr = 'auto'; - process.env['INPUT_ECR'] = ecr; - - const logout = true; - process.env['INPUT_LOGOUT'] = String(logout); - - await main(); - - expect(setRegistrySpy).toHaveBeenCalledWith(registry); - expect(setLogoutSpy).toHaveBeenCalledWith(logout); - expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr); -});