Skip to content

Commit

Permalink
Fix tests, fix reveal
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger committed Dec 6, 2024
1 parent 787e835 commit ac0a467
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/tree/ResourceTreeDataProviderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp

async findItemById(id: string): Promise<ResourceGroupsItem | undefined> {
let element: ResourceGroupsItem | undefined = undefined;

outerLoop: while (true) {
const children: ResourceGroupsItem[] | null | undefined = await this.getChildren(element);

Expand All @@ -124,7 +123,9 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp
}

protected isAncestorOf(element: ResourceGroupsItem, id: string): boolean {
return id.toLowerCase().startsWith(element.id.toLowerCase() + '/');
// remove accounts/<accountId>/tenant/<tenantId> from the beginning of the id
const elementId = element.id.replace(/\/accounts\/[^/]+\/tenants\/[^/]+\//i, '/').toLowerCase() + '/';
return id.toLowerCase().startsWith(elementId);
}

protected abstract onGetChildren(element?: ResourceGroupsItem | undefined): Promise<ResourceGroupsItem[] | null | undefined>;
Expand Down
2 changes: 1 addition & 1 deletion src/tree/azure/SubscriptionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SubscriptionItem implements ResourceGroupsItem {
...subscription
};

this.id = `/subscriptions/${subscription.subscriptionId}/${subscription.tenantId}/${nonNullValueAndProp(subscription.account, 'id')}`;
this.id = `/accounts/${nonNullValueAndProp(subscription.account, 'id')}/tenants/${subscription.tenantId}/subscriptions/${subscription.subscriptionId}`;
this.description = description ? description : '';

this.portalUrl = createPortalUrl(this.subscription, this.id);
Expand Down
9 changes: 6 additions & 3 deletions test/api/subscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ suite('SubscriptionItem tests', async () => {
test('Tree should show a subscription item for each Azure subscription', async () => {
const { mockResources, subscriptionItems } = await mockResourcesAndGetSubscriptionItems();
mockResources.subscriptions.forEach((subscription) => {
assert.ok(subscriptionItems?.find((node) => node.id === subscription.id));
assert.ok(
subscriptionItems?.find((node) => node.subscription.subscriptionId === subscription.subscriptionId),
`Subscription ${subscription.id} not found in the tree. Found: ${subscriptionItems.map((node) => node.subscription.subscriptionId).join(', ')}`
);
});

assert.strictEqual(subscriptionItems.length, mockResources.subscriptions.length, `There should be ${mockResources.subscriptions.length} subscription nodes. Found ${subscriptionItems.length}.`);
});

test('SubscriptionItem.id should be in the "/subscriptions/<subscription id>" format', async () => {
test('SubscriptionItem.id should be in the "/accounts/<account id>/tenants/<tenant id>/subscriptions/<subscription id>" format', async () => {
const { subscriptionItems } = await mockResourcesAndGetSubscriptionItems();
subscriptionItems.forEach((subscriptionItem) => {
assert.match(subscriptionItem.id, /^\/subscriptions\/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/i);
assert.match(subscriptionItem.id, /^\/accounts\/[^/]+\/tenants\/[^/]+\/subscriptions\/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/i);
});
});

Expand Down

0 comments on commit ac0a467

Please sign in to comment.