Add more tests for the archive-filesystem-provider
This commit is contained in:
Родитель
fac5f98d80
Коммит
8db488563b
|
@ -173,7 +173,7 @@ export class ArchiveFileSystemProvider implements vscode.FileSystemProvider {
|
|||
const ref = decodeSourceArchiveUri(uri);
|
||||
const archive = await this.getArchive(ref.sourceArchiveZipPath);
|
||||
const contents = archive.dirMap.get(ref.pathWithinSourceArchive);
|
||||
const result = contents === undefined ? [] : Array.from(contents.entries());
|
||||
const result = contents === undefined ? undefined : Array.from(contents.entries());
|
||||
if (result === undefined) {
|
||||
throw vscode.FileSystemError.FileNotFound(uri);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { expect } from "chai";
|
||||
import * as path from "path";
|
||||
import { ArchiveFileSystemProvider, decodeSourceArchiveUri, encodeSourceArchiveUri, ZipFileReference } from "../../archive-filesystem-provider";
|
||||
import { expect } from 'chai';
|
||||
import * as path from 'path';
|
||||
|
||||
describe("archive filesystem provider", () => {
|
||||
import { encodeSourceArchiveUri, ArchiveFileSystemProvider, decodeSourceArchiveUri, ZipFileReference } from '../../archive-filesystem-provider';
|
||||
import { FileType, FileSystemError } from 'vscode';
|
||||
|
||||
describe('archive-filesystem-provider', () => {
|
||||
it("reads empty file correctly", async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
|
@ -12,6 +14,98 @@ describe("archive filesystem provider", () => {
|
|||
const data = await archiveProvider.readFile(uri);
|
||||
expect(data.length).to.equal(0);
|
||||
});
|
||||
|
||||
it("read non-empty file correctly", async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/textFile.txt"
|
||||
});
|
||||
const data = await archiveProvider.readFile(uri);
|
||||
expect(Buffer.from(data).toString('utf8')).to.be.equal('I am a text\n');
|
||||
});
|
||||
|
||||
it("read a directory", async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1"
|
||||
});
|
||||
const files = await archiveProvider.readDirectory(uri);
|
||||
expect(files).to.be.deep.equal([
|
||||
['folder2', FileType.Directory],
|
||||
['textFile.txt', FileType.File],
|
||||
['textFile2.txt', FileType.File],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle a missing directory', async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/not-here"
|
||||
});
|
||||
try {
|
||||
await archiveProvider.readDirectory(uri);
|
||||
throw new Error('Failed');
|
||||
} catch (e) {
|
||||
expect(e).to.be.instanceOf(FileSystemError);
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle a missing file', async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/not-here"
|
||||
});
|
||||
try {
|
||||
await archiveProvider.readFile(uri);
|
||||
throw new Error('Failed');
|
||||
} catch (e) {
|
||||
expect(e).to.be.instanceOf(FileSystemError);
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle reading a file as a directory', async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/textFile.txt"
|
||||
});
|
||||
try {
|
||||
await archiveProvider.readDirectory(uri);
|
||||
throw new Error('Failed');
|
||||
} catch (e) {
|
||||
expect(e).to.be.instanceOf(FileSystemError);
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle reading a directory as a file', async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/folder2"
|
||||
});
|
||||
try {
|
||||
await archiveProvider.readFile(uri);
|
||||
throw new Error('Failed');
|
||||
} catch (e) {
|
||||
expect(e).to.be.instanceOf(FileSystemError);
|
||||
}
|
||||
});
|
||||
|
||||
it("read a nested directory", async () => {
|
||||
const archiveProvider = new ArchiveFileSystemProvider();
|
||||
const uri = encodeSourceArchiveUri({
|
||||
sourceArchiveZipPath: path.resolve(__dirname, "data/archive-filesystem-provider-test/zip_with_folder.zip"),
|
||||
pathWithinSourceArchive: "folder1/folder2"
|
||||
});
|
||||
const files = await archiveProvider.readDirectory(uri);
|
||||
expect(files).to.be.deep.equal([
|
||||
['textFile3.txt', FileType.File],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('source archive uri encoding', function() {
|
||||
|
|
Двоичные данные
extensions/ql-vscode/src/vscode-tests/no-workspace/data/archive-filesystem-provider-test/zip_with_folder.zip
Normal file
Двоичные данные
extensions/ql-vscode/src/vscode-tests/no-workspace/data/archive-filesystem-provider-test/zip_with_folder.zip
Normal file
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче