|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +// tslint:disable:max-func-body-length |
| 5 | + |
| 6 | +import { expect } from 'chai'; |
| 7 | +import * as TypeMoq from 'typemoq'; |
| 8 | +import { TemporaryFileSystem } from '../../../client/common/platform/fs-temp'; |
| 9 | + |
| 10 | +interface IDeps { |
| 11 | + // tmp module |
| 12 | + // tslint:disable-next-line:no-any |
| 13 | + file(config: { postfix?: string }, callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void): void; |
| 14 | +} |
| 15 | + |
| 16 | +suite('FileSystem - temp files', () => { |
| 17 | + let deps: TypeMoq.IMock<IDeps>; |
| 18 | + let temp: TemporaryFileSystem; |
| 19 | + setup(() => { |
| 20 | + deps = TypeMoq.Mock.ofType<IDeps>(undefined, TypeMoq.MockBehavior.Strict); |
| 21 | + temp = new TemporaryFileSystem(deps.object); |
| 22 | + }); |
| 23 | + function verifyAll() { |
| 24 | + deps.verifyAll(); |
| 25 | + } |
| 26 | + |
| 27 | + suite('createFile', () => { |
| 28 | + test(`fails if the raw call fails`, async () => { |
| 29 | + const failure = new Error('oops'); |
| 30 | + // prettier-ignore |
| 31 | + deps.setup(d => d.file({ postfix: '.tmp' }, TypeMoq.It.isAny())) |
| 32 | + .throws(failure); |
| 33 | + |
| 34 | + const promise = temp.createFile('.tmp'); |
| 35 | + |
| 36 | + await expect(promise).to.eventually.be.rejected; |
| 37 | + verifyAll(); |
| 38 | + }); |
| 39 | + |
| 40 | + test(`fails if the raw call "returns" an error`, async () => { |
| 41 | + const failure = new Error('oops'); |
| 42 | + deps.setup(d => d.file({ postfix: '.tmp' }, TypeMoq.It.isAny())) |
| 43 | + // tslint:disable-next-line:no-empty |
| 44 | + .callback((_cfg, cb) => cb(failure, '...', -1, () => {})); |
| 45 | + |
| 46 | + const promise = temp.createFile('.tmp'); |
| 47 | + |
| 48 | + await expect(promise).to.eventually.be.rejected; |
| 49 | + verifyAll(); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments