1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Testing unpacking tar

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-02-16 15:09:39 +03:00
parent 8a5d657d50
commit eb52c1ac1d
3 changed files with 40 additions and 2 deletions

View File

@ -7,10 +7,11 @@ import { BundledExtensionUpdater } from "../bundled-extension-updater";
import fs from "fs";
import mockFs from "mock-fs";
import nock from "nock";
import path from "path";
const mockOpts = {
"some-user-data-directory": {
"some-file.tgz": "file content here",
"some-file.tgz": mockFs.load(path.resolve(__dirname, "./survey-mock.tgz")),
},
"extension-updates": {
"file.txt": "text",
@ -47,7 +48,7 @@ describe("BundledExtensionUpdater", () => {
expect(exist).toBeTruthy();
});
it.only("Should skip download if no file found on server", () => {
it("Should skip download if no file found on server", () => {
mockFs(mockOpts);
nock("http://my-example-url.com")
@ -98,4 +99,30 @@ describe("BundledExtensionUpdater", () => {
expect(exist).toBeTruthy();
});
it.only("Should unpack downloaded tar file", async () => {
mockFs(mockOpts);
nock("http://my-example-url.com")
.get("/some-file.tgz")
.replyWithFile(200, `./some-user-data-directory/some-file.tgz`, {
"Content-Type": "application/tar",
});
await new BundledExtensionUpdater({
name: "test-extension",
version: "0.0.1",
downloadUrl: "http://my-example-url.com/some-file.tgz",
}, "./extension-updates").update();
fs.readdirSync("./extension-updates/").forEach(file => {
console.log(file);
});
const existTar = fs.existsSync("./extension-updates/test-extension-0.0.1.tgz");
const existFolder = fs.existsSync("./extension-updates/test-extension-0.0.1");
expect(existTar).toBeTruthy();
expect(existFolder).toBeTruthy();
});
});

Binary file not shown.

View File

@ -9,6 +9,7 @@ import request from "request";
import logger from "../logger";
import path from "path";
import { noop } from "../../common/utils";
import tar from "tar-fs";
type Extension = {
name: string
@ -28,6 +29,7 @@ export class BundledExtensionUpdater {
public async update() {
await this.download();
await this.removePreviousUpdateFolder();
// await this.unpackTar();
}
private get filePath() {
@ -85,4 +87,13 @@ export class BundledExtensionUpdater {
});
}
}
private async unpackTar() {
logger.info(`[EXTENSION-UPDATER]: Unpacking '${this.filePath}' into '${this.folderPath}'`);
const extract = tar.extract("./extension-updates/");
// console.log(this.filePath.replace("./", ""))
fs.createReadStream("extension-updates/file.txt").pipe(extract).end();
}
}