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

Refactor installer #432

Merged
merged 21 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dd32dd7
Update installers
nikolai-laevskii May 12, 2023
6d92b9b
Refactor install dir computation
nikolai-laevskii May 12, 2023
aa85432
Refactor installer
nikolai-laevskii May 12, 2023
3dfe267
Format: Refactor installer
nikolai-laevskii May 24, 2023
7e164d3
Fix DOTNET_INSTALL_DIR enviornment variable
nikolai-laevskii May 12, 2023
abf9166
build: Fix DOTNET_INSTALL_DIR enviornment variable
nikolai-laevskii May 12, 2023
df506c2
Refactor convertInstallPathToAbsolute
nikolai-laevskii May 12, 2023
cce8e1b
Merge branch 'main' into refactor-installer
nikolai-laevskii May 24, 2023
b7461a1
Remove excessive whitespace
nikolai-laevskii May 24, 2023
5c7ae4f
Apply consistent naming
nikolai-laevskii May 24, 2023
eb0b7f8
Update build
nikolai-laevskii May 24, 2023
80a318b
Change PLATFORM to constant instead of function
nikolai-laevskii May 25, 2023
2785e21
Update build
nikolai-laevskii May 25, 2023
916aec4
Rename DotnetInstallDir.path to DotnetInstallDir.dirPath
nikolai-laevskii May 30, 2023
defac24
Rename initialize to setEnvironmentVariable
nikolai-laevskii May 30, 2023
89b480a
Call addToPath method on DotnetInstallDir directly
nikolai-laevskii May 30, 2023
427804d
Update tests
nikolai-laevskii May 30, 2023
820f30d
Make assigning of the script path intuitive
nikolai-laevskii May 30, 2023
addb470
Make setup script functions synchronous
nikolai-laevskii May 30, 2023
6019612
Merge remote-tracking branch 'github/main' into refactor-installer
nikolai-laevskii May 31, 2023
3cdb094
Build
nikolai-laevskii May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,22 @@ describe('installer tests', () => {
describe('addToPath() tests', () => {
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const dotnet_root = process.env['DOTNET_ROOT'];
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
});

it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const path = process.env['PATH'];
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
});
});
});

describe('DotnetVersionResolver tests', () => {
describe('createDotNetVersion() tests', () => {
describe('createDotnetVersion() tests', () => {
each([
'3.1',
'3.x',
Expand All @@ -329,7 +329,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(!!versionObject.value).toBe(true);
}
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('installer tests', () => {
);

await expect(
async () => await dotnetVersionResolver.createDotNetVersion()
async () => await dotnetVersionResolver.createDotnetVersion()
).rejects.toThrow();
}
);
Expand All @@ -380,7 +380,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('channel')).toBe(
true
Expand All @@ -395,7 +395,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('channel')).toBe(
true
Expand All @@ -411,7 +411,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('version')).toBe(
true
Expand All @@ -427,7 +427,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);

Expand All @@ -447,7 +447,7 @@ describe('installer tests', () => {
version
);
await expect(
async () => await dotnetVersionResolver.createDotNetVersion()
async () => await dotnetVersionResolver.createDotnetVersion()
).rejects.toThrow(
`'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
);
Expand Down
19 changes: 7 additions & 12 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import semver from 'semver';
import * as auth from '../src/authutil';

import * as setup from '../src/setup-dotnet';
import {DotnetCoreInstaller} from '../src/installer';
import {DotnetCoreInstaller, DotnetInstallDir} from '../src/installer';
import * as cacheUtils from '../src/cache-utils';
import * as cacheRestore from '../src/cache-restore';

Expand All @@ -28,22 +28,25 @@ describe('setup-dotnet tests', () => {
DotnetCoreInstaller.prototype,
'installDotnet'
);
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');

const isCacheFeatureAvailableSpy = jest.spyOn(
cacheUtils,
'isCacheFeatureAvailable'
);
const restoreCacheSpy = jest.spyOn(cacheRestore, 'restoreCache');
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
const addToPathOriginal = DotnetInstallDir.addToPath;

describe('run() tests', () => {
beforeEach(() => {
DotnetInstallDir.addToPath = jest.fn();
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
getInputSpy.mockImplementation(input => inputs[input as string]);
getBooleanInputSpy.mockImplementation(input => inputs[input as string]);
});

afterEach(() => {
DotnetInstallDir.addToPath = addToPathOriginal;
jest.clearAllMocks();
jest.resetAllMocks();
});
Expand Down Expand Up @@ -104,10 +107,9 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-quality'] = '';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(addToPathSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it('should call auth.configAuthentication() if source-url input is provided', async () => {
Expand Down Expand Up @@ -148,18 +150,16 @@ describe('setup-dotnet tests', () => {
installDotnetSpy.mockImplementation(() =>
Promise.resolve(`${inputs['dotnet-version']}`)
);
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(setOutputSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;

installDotnetSpy.mockImplementation(() => Promise.resolve(null));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
Expand All @@ -170,8 +170,6 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-version'] = [];
const warningMessage = `The 'dotnet-version' output will not be set.`;

addToPathSpy.mockImplementation(() => {});

await setup.run();

expect(infoSpy).toHaveBeenCalledWith(warningMessage);
Expand All @@ -185,7 +183,6 @@ describe('setup-dotnet tests', () => {
inputs['cache-dependency-path'] = 'fictitious.package.lock.json';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => true);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand All @@ -203,7 +200,6 @@ describe('setup-dotnet tests', () => {
inputs['cache'] = false;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => true);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand All @@ -218,7 +214,6 @@ describe('setup-dotnet tests', () => {
inputs['cache'] = true;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => false);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand Down