mirror of
https://github.com/actions/download-artifact.git
synced 2025-04-03 01:20:12 +08:00
Lint
This commit is contained in:
parent
96a6f165f4
commit
9a869e9c49
@ -1,19 +1,8 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import * as os from 'os'
|
||||
import artifact, {ArtifactNotFoundError} from '@actions/artifact'
|
||||
import {run} from '../src/download-artifact'
|
||||
import {Inputs} from '../src/constants'
|
||||
|
||||
const fixtures = {
|
||||
artifactName: 'artifact-name',
|
||||
rootDirectory: '/some/artifact/path',
|
||||
filesToUpload: [
|
||||
'/some/artifact/path/file1.txt',
|
||||
'/some/artifact/path/file2.txt'
|
||||
]
|
||||
}
|
||||
|
||||
jest.mock('@actions/github', () => ({
|
||||
context: {
|
||||
repo: {
|
||||
@ -27,7 +16,7 @@ jest.mock('@actions/github', () => ({
|
||||
|
||||
jest.mock('@actions/core')
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
|
||||
const inputs = {
|
||||
[Inputs.Name]: 'artifact-name',
|
||||
@ -55,15 +44,15 @@ describe('download', () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
// Mock artifact client methods
|
||||
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
|
||||
Promise.resolve({ artifacts: [] })
|
||||
)
|
||||
jest.spyOn(artifact, 'getArtifact').mockImplementation((name) => {
|
||||
jest
|
||||
.spyOn(artifact, 'listArtifacts')
|
||||
.mockImplementation(() => Promise.resolve({artifacts: []}))
|
||||
jest.spyOn(artifact, 'getArtifact').mockImplementation(name => {
|
||||
throw new ArtifactNotFoundError(`Artifact '${name}' not found`)
|
||||
})
|
||||
jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>
|
||||
Promise.resolve({ digestMismatch: false })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'downloadArtifact')
|
||||
.mockImplementation(() => Promise.resolve({digestMismatch: false}))
|
||||
})
|
||||
|
||||
test('downloads a single artifact by name', async () => {
|
||||
@ -74,9 +63,9 @@ describe('download', () => {
|
||||
digest: 'abc123'
|
||||
}
|
||||
|
||||
jest.spyOn(artifact, 'getArtifact').mockImplementation(() =>
|
||||
Promise.resolve({ artifact: mockArtifact })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'getArtifact')
|
||||
.mockImplementation(() => Promise.resolve({artifact: mockArtifact}))
|
||||
|
||||
await run()
|
||||
|
||||
@ -102,18 +91,20 @@ describe('download', () => {
|
||||
]
|
||||
|
||||
// Set up artifact mock after clearing mocks
|
||||
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
|
||||
Promise.resolve({ artifacts: mockArtifacts })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'listArtifacts')
|
||||
.mockImplementation(() => Promise.resolve({artifacts: mockArtifacts}))
|
||||
|
||||
// Reset downloadArtifact mock as well
|
||||
jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>
|
||||
Promise.resolve({ digestMismatch: false })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'downloadArtifact')
|
||||
.mockImplementation(() => Promise.resolve({digestMismatch: false}))
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith('No input name or pattern filtered specified, downloading all artifacts')
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
'No input name or pattern filtered specified, downloading all artifacts'
|
||||
)
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith('Total of 2 artifact(s) downloaded')
|
||||
expect(artifact.downloadArtifact).toHaveBeenCalledTimes(2)
|
||||
@ -133,9 +124,7 @@ describe('download', () => {
|
||||
'Download artifact has finished successfully'
|
||||
)
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
'Total of 0 artifact(s) downloaded'
|
||||
)
|
||||
expect(core.info).toHaveBeenCalledWith('Total of 0 artifact(s) downloaded')
|
||||
})
|
||||
|
||||
test('filters artifacts by pattern', async () => {
|
||||
@ -144,9 +133,9 @@ describe('download', () => {
|
||||
{id: 456, name: 'prod-artifact', size: 2048, digest: 'def456'}
|
||||
]
|
||||
|
||||
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
|
||||
Promise.resolve({ artifacts: mockArtifacts })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'listArtifacts')
|
||||
.mockImplementation(() => Promise.resolve({artifacts: mockArtifacts}))
|
||||
|
||||
mockInputs({
|
||||
[Inputs.Name]: '',
|
||||
@ -172,9 +161,9 @@ describe('download', () => {
|
||||
[Inputs.RunID]: '789'
|
||||
})
|
||||
|
||||
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
|
||||
Promise.resolve({ artifacts: [] })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'listArtifacts')
|
||||
.mockImplementation(() => Promise.resolve({artifacts: []}))
|
||||
|
||||
await run()
|
||||
|
||||
@ -209,13 +198,13 @@ describe('download', () => {
|
||||
digest: 'abc123'
|
||||
}
|
||||
|
||||
jest.spyOn(artifact, 'getArtifact').mockImplementation(() =>
|
||||
Promise.resolve({ artifact: mockArtifact })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'getArtifact')
|
||||
.mockImplementation(() => Promise.resolve({artifact: mockArtifact}))
|
||||
|
||||
jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>
|
||||
Promise.resolve({ digestMismatch: true })
|
||||
)
|
||||
jest
|
||||
.spyOn(artifact, 'downloadArtifact')
|
||||
.mockImplementation(() => Promise.resolve({digestMismatch: true}))
|
||||
|
||||
await run()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user