.
This commit is contained in:
1 parent
d788e084ec
commit
be66121509
1 file changed
+45
-12
@@ -9,8 +9,8 @@ import {uploadArtifact} from '../src/internal/upload/upload-artifact'
|
|||||||
import {noopLogs} from './common'
|
import {noopLogs} from './common'
|
||||||
import {FilesNotFoundError} from '../src/internal/shared/errors'
|
import {FilesNotFoundError} from '../src/internal/shared/errors'
|
||||||
import {BlockBlobClient} from '@azure/storage-blob'
|
import {BlockBlobClient} from '@azure/storage-blob'
|
||||||
import fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import {Readable} from 'stream'
|
import * as path from 'path'
|
||||||
|
|
||||||
describe('upload-artifact', () => {
|
describe('upload-artifact', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -357,14 +357,47 @@ describe('upload-artifact', () => {
|
|||||||
|
|
||||||
it('should throw an error uploading blob chunks get delayed', async () => {
|
it('should throw an error uploading blob chunks get delayed', async () => {
|
||||||
const mockDate = new Date('2020-01-01')
|
const mockDate = new Date('2020-01-01')
|
||||||
|
// const root = path.join('/home/user/files/')
|
||||||
|
const dirPath = path.join(__dirname, `plz-upload`)
|
||||||
|
|
||||||
// Mock fs.createReadStream to return a mock stream
|
// const filePath = path.join(dirPath, 'file1.txt')
|
||||||
fs.createReadStream = jest.fn().mockImplementation(() => {
|
// const root = '/home/user/files'
|
||||||
const mockStream = new Readable()
|
if (!fs.existsSync(dirPath)) {
|
||||||
mockStream.push('file content')
|
fs.mkdirSync(dirPath, {recursive: true})
|
||||||
mockStream.push(null)
|
// fs.mkdirSync(path.join(dirPath, 'file1.txt'), {recursive: true})
|
||||||
return mockStream
|
}
|
||||||
})
|
|
||||||
|
// Now write the file
|
||||||
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(dirPath, 'file1.txt'),
|
||||||
|
'test file content',
|
||||||
|
err => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(dirPath, 'file2.txt'),
|
||||||
|
'test file content',
|
||||||
|
err => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(dirPath, 'file3.txt'),
|
||||||
|
'test file content',
|
||||||
|
err => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.spyOn(uploadZipSpecification, 'validateRootDirectory')
|
.spyOn(uploadZipSpecification, 'validateRootDirectory')
|
||||||
@@ -373,15 +406,15 @@ describe('upload-artifact', () => {
|
|||||||
.spyOn(uploadZipSpecification, 'getUploadZipSpecification')
|
.spyOn(uploadZipSpecification, 'getUploadZipSpecification')
|
||||||
.mockReturnValue([
|
.mockReturnValue([
|
||||||
{
|
{
|
||||||
sourcePath: '/home/user/files/plz-upload/file1.txt',
|
sourcePath: path.join(dirPath, 'file1.txt'),
|
||||||
destinationPath: 'file1.txt'
|
destinationPath: 'file1.txt'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sourcePath: '/home/user/files/plz-upload/file2.txt',
|
sourcePath: path.join(dirPath, 'file2.txt'),
|
||||||
destinationPath: 'file2.txt'
|
destinationPath: 'file2.txt'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sourcePath: '/home/user/files/plz-upload/dir/file3.txt',
|
sourcePath: path.join(dirPath, 'file3.txt'),
|
||||||
destinationPath: 'dir/file3.txt'
|
destinationPath: 'dir/file3.txt'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in new issue
Block a user