Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets committed Oct 26, 2023
1 parent ca76b8e commit f2c460d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
],
"default": null,
"description": "Path to local mirrord installation."
},
"mirrord.autoUpdate": {
"type": ["string", "boolean"],
"default": true,
"description": "Automatically update mirrord binary."
}
}
},
Expand Down
69 changes: 28 additions & 41 deletions src/binaryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ function getExtensionMirrordPath(): Uri {
* Tries to find local mirrord in path or in extension storage.
*/
export async function getLocalMirrordBinary(version?: string): Promise<string | null> {
try {
const mirrordPath = getExtensionMirrordPath();
await workspace.fs.stat(mirrordPath);
if (version) {
const api = new MirrordAPI(mirrordPath.fsPath);
const installedVersion = await api.getBinaryVersion();
if (installedVersion === version) {
return mirrordPath.fsPath;
}
} else {
return mirrordPath.fsPath;
}

} catch (e) {
console.log("couldn't find mirrord in extension storage");
}
try {
const mirrordPath = await which("mirrord");
if (version) {
Expand All @@ -40,22 +56,6 @@ export async function getLocalMirrordBinary(version?: string): Promise<string |
} catch (e) {
console.debug("couldn't find mirrord in path");
}
try {
const mirrordPath = getExtensionMirrordPath();
await workspace.fs.stat(mirrordPath);
if (version) {
const api = new MirrordAPI(mirrordPath.fsPath);
const installedVersion = await api.getBinaryVersion();
if (installedVersion === version) {
return mirrordPath.fsPath;
}
} else {
return mirrordPath.fsPath;
}

} catch (e) {
console.log("couldn't find mirrord in extension storage");
}
return null;
}

Expand Down Expand Up @@ -97,15 +97,6 @@ async function getConfiguredMirrordBinary(): Promise<string | null> {
return configured;
}

/**
* Auto-update configuration i.e. workspace settings for mirrord auto-update
*/

interface AutoUpdateConfiguration {
enabled: boolean;
version: string | null;
}

/**
* Toggles auto-update of mirrord binary.
* Criteria for auto-update:
Expand All @@ -114,7 +105,7 @@ interface AutoUpdateConfiguration {
* - if auto-update is enabled, then latest supported version is downloaded
* - if auto-update is disabled, and a version is specified, then that version is downloaded
* - if auto-update is disabled, and no version is specified, then local mirrord binary is used
* * - if auto-update is disabled, and no version is specified, and no local mirrord binary is found, then latest supported version is downloaded
* - if auto-update is disabled, and no version is specified, and no local mirrord binary is found, then latest supported version is downloaded
* @returns Path to mirrord binary
*/
export async function getMirrordBinary(): Promise<string> {
Expand All @@ -124,35 +115,31 @@ export async function getMirrordBinary(): Promise<string> {
vscode.window.showInformationMessage(`Using mirrord binary specified in settings: ${configured}`);
return configured;
}
const latestVersion = await getLatestSupportedVersion(10000);

const autoUpdateConfigured: AutoUpdateConfiguration | null = vscode.workspace.getConfiguration().get("mirrord.autoUpdate", { enabled: true, version: null });
const autoUpdateConfigured = vscode.workspace.getConfiguration().get("mirrord.autoUpdate", true);

const extensionMirrordPath = getExtensionMirrordPath();
const latestVersion = await getLatestSupportedVersion(10000);

if (autoUpdateConfigured && !autoUpdateConfigured.enabled) {
if (autoUpdateConfigured.version && semver.valid(autoUpdateConfigured.version)) {
const localMirrordBinary = await getLocalMirrordBinary(autoUpdateConfigured.version);
if (typeof autoUpdateConfigured === 'string') {
if (semver.valid(autoUpdateConfigured)) {
const localMirrordBinary = await getLocalMirrordBinary(autoUpdateConfigured);
if (localMirrordBinary) {
return localMirrordBinary;
}
await downloadMirrordBinary(extensionMirrordPath, autoUpdateConfigured.version);
await downloadMirrordBinary(getExtensionMirrordPath(), autoUpdateConfigured);
return getExtensionMirrordPath().fsPath;
} else {
vscode.window.showErrorMessage(`Invalid version format ${autoUpdateConfigured.version}: must follow semver format`);
vscode.window.showErrorMessage(`Invalid version format ${autoUpdateConfigured}: must follow semver format`);
}
}

// Auto-update is enabled or no specific version specified.
// Auto-update is enabled or no specific version specified.
const localMirrordBinary = await getLocalMirrordBinary();

if (localMirrordBinary) {
return localMirrordBinary;
}

// No local mirrord binary found, download the latest supported version.
await downloadMirrordBinary(extensionMirrordPath, latestVersion);

return extensionMirrordPath.fsPath;
await downloadMirrordBinary(getExtensionMirrordPath(), latestVersion);
return getExtensionMirrordPath().fsPath;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/tests/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const podToSelect = process.env.POD_TO_SELECT;
* - Send traffic to the pod
* - Tests successfully exit if "GET: Request completed" is found in the terminal
*/
describe("mirrord sample flow test", function() {
describe("mirrord sample flow test", function () {

this.timeout("6 minutes"); // --> mocha tests timeout
this.bail(true); // --> stop tests on first failure
Expand All @@ -26,7 +26,7 @@ describe("mirrord sample flow test", function() {
const fileName = "app_flask.py";
const defaultTimeout = 10000; // = 10 seconds

before(async function() {
before(async function () {
console.log("podToSelect: " + podToSelect);
console.log("kubeService: " + kubeService);

Expand All @@ -48,7 +48,7 @@ describe("mirrord sample flow test", function() {
await ew.openEditor('app_flask.py');
});

it("enable mirrord button", async function() {
it("enable mirrord button", async function () {
const statusBar = new StatusBar();

await browser.driver.wait(async () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe("mirrord sample flow test", function() {
}, defaultTimeout, "mirrord `enable` button not found -- timed out");
});

it("select pod from quickpick", async function() {
it("select pod from quickpick", async function () {
await startDebugging();
const inputBox = await InputBox.create(defaultTimeout * 2);
// assertion that podToSelect is not undefined is done in "before" block
Expand Down Expand Up @@ -108,7 +108,7 @@ describe("mirrord sample flow test", function() {
await inputBox.selectQuickPick(podToSelect!);
});

it("wait for process to write to terminal", async function() {
it("wait for process to write to terminal", async function () {
const debugToolbar = await DebugToolbar.create(2 * defaultTimeout);
const panel = new BottomBarPanel();
await browser.driver.wait(async () => {
Expand Down
7 changes: 7 additions & 0 deletions test-workspace/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mirrord.autoUpdate": {
"enabled": false,
"version": "3.70.0"
},
"mirrord.binaryPath": null
}

0 comments on commit f2c460d

Please sign in to comment.