Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Account details Uri #95

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cloud/mock/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const account: osc.Account = {

export function initMock() {
const getAccountMock = ImportMock.mockFunction(osc.AccountApi.prototype, 'readAccounts');
getAccountMock.onFirstCall().returns(Promise.reject("403"));
getAccountMock.returns(Promise.resolve(
{
accounts: [account],
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { OscExplorer } from "./explorer";
import { ExplorerResourceNode, ResourceNodeType } from './flat/node';
import { ResourceNode } from './flat/resources/node.resources';
import { VmResourceNode } from './flat/resources/node.resources.vms';
import { OscVirtualContentProvider } from './virtual_filesystem/oscvirtualfs';
import { OscVirtualContentProvider, computeUri } from './virtual_filesystem/oscvirtualfs';
import { LogsProvider } from './virtual_filesystem/logs';
import { ProfileNode } from './flat/node.profile';
import { FolderNode } from './flat/folders/node.folder';
Expand All @@ -28,7 +28,7 @@ function getMultipleSelection<T>(mainSelectedItem: T, allSelectedItems?: any[]):
}

export async function showResourceDetails(profileName: string, resourceType: ResourceNodeType, resourceId: string) {
const uri = vscode.Uri.parse('osc:/' + profileName + "/" + resourceType + "/" + resourceId + ".json");
const uri = computeUri(profileName, `${resourceType}`, resourceId);
const doc = await vscode.workspace.openTextDocument(uri); // calls back into the provider
await vscode.window.showTextDocument(doc);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ export function activate(context: vscode.ExtensionContext) {
});

vscode.commands.registerCommand('osc.showAccountInfo', async (arg: ProfileNode) => {
const uri = vscode.Uri.parse('osc:/' + arg.profile.name + "/profile/" + arg.profile.name);
const uri = computeUri(arg.profile.name, "profile", arg.profile.name);
try {
const doc = await vscode.workspace.openTextDocument(uri); // calls back into the provider
await vscode.window.showTextDocument(doc);
Expand Down
28 changes: 26 additions & 2 deletions src/ui-test/treeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,33 @@ describe('ActivityBar', () => {
expect(await menu.hasItem(expectedCommandName)).equals(true);
});

it('has show Account Info button', async () => {
describe('has show Account Info button', async () => {
const expectedCommandName = getButtonTitle("osc.showAccountInfo");
expect(await menu.hasItem(expectedCommandName)).equals(true);

after(async () => {
await (new EditorView()).closeAllEditors();
});

it("exists", async () => {
expect(await menu.hasItem(expectedCommandName)).equals(true);
});

it("shows resource detail when clicking", async () => {
const action = await menu.getItem(expectedCommandName);
await action?.select();

await delay(500);

// New titles in editor
const editor = new TextEditor();
expect(await editor.getTitle()).equals("first_profile.json");
const data = await editor.getText();
const account = osc.AccountFromJSON(JSON.parse(data));
expect(account.accountId).equals("accountid");

const editorView = new EditorView();
await editorView.closeEditor("first_profile.json");
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/virtual_filesystem/oscvirtualfs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

import { AccessKeyToJSON, AccountToJSON, ApiAccessRuleToJSON, CaToJSON, ClientGatewayToJSON, DhcpOptionsSetToJSON, DirectLinkInterfaceToJSON, DirectLinkToJSON, FlexibleGpuToJSON, ImageToJSON, InternetServiceToJSON, KeypairToJSON, LoadBalancerToJSON, NatServiceToJSON, NetAccessPointToJSON, NetPeeringToJSON, NetToJSON, NicToJSON, PublicIpToJSON, RouteTableToJSON, SecurityGroupToJSON, SnapshotToJSON, SubnetToJSON, VirtualGatewayToJSON, VmGroupFromJSON, VmGroupToJSON, VmTemplateToJSON, VmToJSON, VolumeToJSON, VpnConnectionToJSON } from "outscale-api";

Check warning on line 3 in src/virtual_filesystem/oscvirtualfs.ts

View workflow job for this annotation

GitHub Actions / format

'VmGroupFromJSON' is defined but never used
import { getExternalIP } from "../cloud/publicips";
import { getKeypair } from "../cloud/keypairs";
import { getLoadBalancer } from "../cloud/loadbalancers";
Expand Down Expand Up @@ -109,4 +109,8 @@
}
return JSON.stringify(resourceEncoding.toString(res), null, 4);
}
}

export function computeUri(profile: string, resourceType: string, resourceId: string): vscode.Uri {
return vscode.Uri.parse(`osc:/${profile}/${resourceType}/${resourceId}.json`);
}
Loading