Skip to content

Commit

Permalink
Move the Global Command Test to the Runtime Extension
Browse files Browse the repository at this point in the history
Since we arent shipping a new SDK extension, we don't need to duplicate the test in both places.
  • Loading branch information
nagilson committed Oct 25, 2023
1 parent b955625 commit c57609a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as rimraf from 'rimraf';
import * as vscode from 'vscode';
import {
DotnetCoreAcquisitionWorker,
FileUtilities,
IDotnetAcquireContext,
IDotnetAcquireResult,
ITelemetryEvent,
Expand All @@ -19,6 +20,7 @@ import {
MockWindowDisplayWorker
} from 'vscode-dotnet-runtime-library';
import * as extension from '../../extension';
import { warn } from 'console';
/* tslint:disable:no-any */
const assert : any = chai.assert;
const standardTimeoutTime = 40000;
Expand Down Expand Up @@ -62,7 +64,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
assert.isAbove(extensionContext.subscriptions.length, 0);
}).timeout(standardTimeoutTime);

test('Install Command', async () => {
test('Install Local Runtime Command', async () => {
const context: IDotnetAcquireContext = { version: '2.2', requestingExtensionId };
const result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', context);
assert.exists(result);
Expand All @@ -72,7 +74,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
assert.include(result!.dotnetPath, context.version);
}).timeout(standardTimeoutTime);

test('Uninstall Command', async () => {
test('Uninstall Local Runtime Command', async () => {
const context: IDotnetAcquireContext = { version: '2.1', requestingExtensionId };
const result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', context);
assert.exists(result);
Expand All @@ -84,7 +86,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
}).timeout(standardTimeoutTime);


test('Install and Uninstall Multiple Versions', async () => {
test('Install and Uninstall Multiple Local Runtime Versions', async () => {
const versions = ['2.2', '3.0', '3.1'];
let dotnetPaths: string[] = [];
for (const version of versions) {
Expand All @@ -102,6 +104,57 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
}
}).timeout(standardTimeoutTime * 2);

test('Install SDK Globally E2E (Requires Admin)', async () => {
// We only test if the process is running under ADMIN because non-admin requires user-intervention.
if(new FileUtilities().isElevated())
{
const originalPath = process.env.PATH;
const sdkVersion = '7.0.103';
const context : IDotnetAcquireContext = { version: sdkVersion, requestingExtensionId: 'sample-extension', installType: 'global' };

// We cannot use the describe pattern to restore the environment variables using vscodes extension testing infrastructure.
// So we must set and unset it ourselves, which isn't ideal as this variable could remain.
let result : IDotnetAcquireResult;
let error : any;
let pathAfterInstall;

// We cannot test much as we don't want to leave global installs on dev boxes. But we do want to make sure the e-2-e goes through the right path. Vendors can test the rest.
// So we have this environment variable that tells us to stop before running any real install.
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = 'true';
try
{
result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquireGlobalSDK', context);
}
catch(err)
{
error = err;
}
finally
{
pathAfterInstall = process.env.PATH;
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = undefined;
process.env.PATH = originalPath;

if(error)
{
throw(new Error(`The test failed to run the acquire command successfully. Error: ${error}`));
}
}

assert.exists(result!, 'The global acquisition command did not provide a result?');
assert.exists(result!.dotnetPath);
assert.equal(result!.dotnetPath, 'fake-sdk');
assert.exists(pathAfterInstall, 'The environment variable PATH for DOTNET was not found?');
assert.include(pathAfterInstall, result!.dotnetPath, 'Is the PATH correctly set by the global installer?');
}
else
{
// We could run the installer without privilege but it would require human interaction to use the UAC
// And we wouldn't be able to kill the process so the test would leave a lot of hanging processes on the machine
warn('The Global SDK E2E Install test cannot run as the machine is unprivileged.');
}
}).timeout(standardTimeoutTime*1000);

test('Telemetry Sent During Install and Uninstall', async () => {
const rntVersion = '2.2';
const fullyResolvedVersion = '2.2.8'; // 2.2 is very much out of support, so we don't expect this to change to a newer version
Expand Down Expand Up @@ -151,7 +204,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
}
}).timeout(standardTimeoutTime/2);

test('Install Command Passes With Warning With No RequestingExtensionId', async () => {
test('Install Local Runtime Command Passes With Warning With No RequestingExtensionId', async () => {
const context: IDotnetAcquireContext = { version: '3.1' };
const result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', context);
assert.exists(result);
Expand All @@ -160,7 +213,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function() {
assert.include(mockDisplayWorker.warningMessage, 'Ignoring existing .NET paths');
}).timeout(standardTimeoutTime);

test('Install Command With Path Config Defined', async () => {
test('Install Local Runtime Command With Path Config Defined', async () => {
const context: IDotnetAcquireContext = { version: '0.1', requestingExtensionId: 'alternative.extension' };
const result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', context);
assert.exists(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,58 +302,6 @@ suite('DotnetCoreAcquisitionExtension End to End', function()
assert.strictEqual(await resolver.getFullySpecifiedVersion(), fullVersion);
}).timeout(standardTimeoutTime);


test('Install Globally E2E (Requires Admin)', async () => {
// We only test if the process is running under ADMIN because non-admin requires user-intervention.
if(new FileUtilities().isElevated())
{
const originalPath = process.env.PATH;
const sdkVersion = '7.0.103';
const context : IDotnetAcquireContext = { version: sdkVersion, requestingExtensionId: 'ms-dotnettools.sample-extension', installType: 'global' };

// We cannot use the describe pattern to restore the environment variables using vscodes extension testing infrastructure.
// So we must set and unset it ourselves, which isn't ideal as this variable could remain.
let result : IDotnetAcquireResult;
let error : any;
let pathAfterInstall;

// We cannot test much as we don't want to leave global installs on dev boxes. But we do want to make sure the e-2-e goes through the right path. Vendors can test the rest.
// So we have this environment variable that tells us to stop before running any real install.
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = 'true';
try
{
result = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet-sdk.acquire', context);
}
catch(err)
{
error = err;
}
finally
{
pathAfterInstall = process.env.PATH;
process.env.VSCODE_DOTNET_GLOBAL_INSTALL_FAKE_PATH = undefined;
process.env.PATH = originalPath;

if(error)
{
throw(new Error(`The test failed to run the acquire command successfully. Error: ${error}`));
}
}

assert.exists(result!, 'The global acquisition command did not provide a result?');
assert.exists(result!.dotnetPath);
assert.equal(result!.dotnetPath, 'fake-sdk');
assert.exists(pathAfterInstall, 'The environment variable PATH for DOTNET was not found?');
assert.include(pathAfterInstall, result!.dotnetPath, 'Is the PATH correctly set by the global installer?');
}
else
{
// We could run the installer without privilege but it would require human interaction to use the UAC
// And we wouldn't be able to kill the process so the test would leave a lot of hanging processes on the machine
warn('The Global SDK E2E Install test cannot run as the machine is unprivileged.');
}
}).timeout(standardTimeoutTime*1000);

test('Install Command Sets the PATH', async () =>
{
const existingPath = process.env.PATH;
Expand Down

0 comments on commit c57609a

Please sign in to comment.