mirror of https://github.com/actions/toolkit
Refactor test to run status codes 1 by 1
parent
e6109ecebb
commit
c359bfc506
|
@ -4,17 +4,17 @@ import * as io from '../../io/src/io'
|
||||||
import * as net from 'net'
|
import * as net from 'net'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as configVariables from '../src/internal/config-variables'
|
import * as configVariables from '../src/internal/config-variables'
|
||||||
import {promises as fs} from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import {DownloadItem} from '../src/internal/download-specification'
|
import { DownloadItem } from '../src/internal/download-specification'
|
||||||
import {HttpClient, HttpClientResponse} from '@actions/http-client'
|
import { HttpClient, HttpClientResponse } from '@actions/http-client'
|
||||||
import {DownloadHttpClient} from '../src/internal/download-http-client'
|
import { DownloadHttpClient } from '../src/internal/download-http-client'
|
||||||
import {
|
import {
|
||||||
ListArtifactsResponse,
|
ListArtifactsResponse,
|
||||||
QueryArtifactResponse
|
QueryArtifactResponse
|
||||||
} from '../src/internal/contracts'
|
} from '../src/internal/contracts'
|
||||||
import * as stream from 'stream'
|
import * as stream from 'stream'
|
||||||
import {gzip} from 'zlib'
|
import { gzip } from 'zlib'
|
||||||
import {promisify} from 'util'
|
import { promisify } from 'util'
|
||||||
|
|
||||||
const root = path.join(__dirname, '_temp', 'artifact-download-tests')
|
const root = path.join(__dirname, '_temp', 'artifact-download-tests')
|
||||||
const defaultEncoding = 'utf8'
|
const defaultEncoding = 'utf8'
|
||||||
|
@ -24,17 +24,18 @@ jest.mock('@actions/http-client')
|
||||||
|
|
||||||
describe('Download Tests', () => {
|
describe('Download Tests', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
jest.setTimeout(300000);
|
||||||
await io.rmRF(root)
|
await io.rmRF(root)
|
||||||
await fs.mkdir(path.join(root), {
|
await fs.mkdir(path.join(root), {
|
||||||
recursive: true
|
recursive: true
|
||||||
})
|
})
|
||||||
|
|
||||||
// mock all output so that there is less noise when running tests
|
// mock all output so that there is less noise when running tests
|
||||||
jest.spyOn(console, 'log').mockImplementation(() => {})
|
jest.spyOn(console, 'log').mockImplementation(() => { })
|
||||||
jest.spyOn(core, 'debug').mockImplementation(() => {})
|
jest.spyOn(core, 'debug').mockImplementation(() => { })
|
||||||
jest.spyOn(core, 'info').mockImplementation(() => {})
|
jest.spyOn(core, 'info').mockImplementation(() => { })
|
||||||
jest.spyOn(core, 'warning').mockImplementation(() => {})
|
jest.spyOn(core, 'warning').mockImplementation(() => { })
|
||||||
jest.spyOn(core, 'error').mockImplementation(() => {})
|
jest.spyOn(core, 'error').mockImplementation(() => { })
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,13 +164,19 @@ describe('Download Tests', () => {
|
||||||
await checkDestinationFile(targetPath, fileContents)
|
await checkDestinationFile(targetPath, fileContents)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Test retryable status codes during artifact download', async () => {
|
it.each([
|
||||||
|
429,
|
||||||
|
500,
|
||||||
|
502,
|
||||||
|
503,
|
||||||
|
504
|
||||||
|
])('Test retryable status code %p during artifact download', async (scode: number) => {
|
||||||
// The first http response should return a retryable status call while the subsequent call should return a 200 so
|
// The first http response should return a retryable status call while the subsequent call should return a 200 so
|
||||||
// the download should successfully finish
|
// the download should successfully finish
|
||||||
const retryableStatusCodes = [429, 500, 502, 503, 504]
|
const retryableStatusCodes = [scode]
|
||||||
for (const statusCode of retryableStatusCodes) {
|
for (const statusCode of retryableStatusCodes) {
|
||||||
const fileContents = Buffer.from('try, try again\n', defaultEncoding)
|
const fileContents = Buffer.from('try, try again\n', defaultEncoding)
|
||||||
const targetPath = path.join(root, `FileC-${statusCode}.txt`)
|
const targetPath = path.join(root, `AAAFileC-${statusCode}.txt`)
|
||||||
|
|
||||||
setupDownloadItemResponse(fileContents, false, statusCode, false, true)
|
setupDownloadItemResponse(fileContents, false, statusCode, false, true)
|
||||||
const downloadHttpClient = new DownloadHttpClient()
|
const downloadHttpClient = new DownloadHttpClient()
|
||||||
|
@ -186,7 +193,7 @@ describe('Download Tests', () => {
|
||||||
|
|
||||||
await checkDestinationFile(targetPath, fileContents)
|
await checkDestinationFile(targetPath, fileContents)
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
it('Test retry on truncated response with gzip', async () => {
|
it('Test retry on truncated response with gzip', async () => {
|
||||||
const fileContents = Buffer.from(
|
const fileContents = Buffer.from(
|
||||||
|
@ -276,7 +283,7 @@ describe('Download Tests', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
const returnData: string = JSON.stringify(response, null, 2)
|
const returnData: string = JSON.stringify(response, null, 2)
|
||||||
mockReadBody = async function(): Promise<string> {
|
mockReadBody = async function (): Promise<string> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
resolve(returnData)
|
resolve(returnData)
|
||||||
})
|
})
|
||||||
|
@ -447,7 +454,7 @@ describe('Download Tests', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
const returnData: string = JSON.stringify(response, null, 2)
|
const returnData: string = JSON.stringify(response, null, 2)
|
||||||
mockReadBody = async function(): Promise<string> {
|
mockReadBody = async function (): Promise<string> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
resolve(returnData)
|
resolve(returnData)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue