mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-15 05:05:08 +00:00
Update unit-tests
This commit is contained in:
parent
d1558ba62e
commit
595c6fb023
2
.github/workflows/e2e-tests.yml
vendored
2
.github/workflows/e2e-tests.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
|||||||
- name: Clear toolcache
|
- name: Clear toolcache
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
- name: Setup dotnet 2.2.402 and 3.1.404
|
- name: Setup dotnet 2.2.402, 3.1.404 and 3.0.x
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
dotnet-version: |
|
dotnet-version: |
|
||||||
|
@ -93,7 +93,7 @@ describe('authutil tests', () => {
|
|||||||
|
|
||||||
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -107,7 +107,7 @@ describe('authutil tests', () => {
|
|||||||
it('No existing config, auth token environment variable not provided, throws', async () => {
|
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -121,7 +121,7 @@ describe('authutil tests', () => {
|
|||||||
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
process.env['INPUT_OWNER'] = 'otherorg';
|
process.env['INPUT_OWNER'] = 'otherorg';
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/otherorg/index.json',
|
'https://nuget.pkg.github.com/otherorg/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -141,7 +141,7 @@ describe('authutil tests', () => {
|
|||||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -159,7 +159,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -177,7 +177,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -195,7 +195,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -213,7 +213,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -231,7 +231,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com',
|
'https://nuget.pkg.github.com',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -251,7 +251,7 @@ describe('authutil tests', () => {
|
|||||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -274,7 +274,7 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'subfolder/nuget.config',
|
'subfolder/nuget.config',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -292,7 +292,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -310,7 +310,7 @@ describe('authutil tests', () => {
|
|||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
@ -323,7 +323,7 @@ describe('authutil tests', () => {
|
|||||||
|
|
||||||
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
'',
|
'',
|
||||||
fakeSourcesDirForTesting
|
fakeSourcesDirForTesting
|
||||||
|
@ -32,12 +32,13 @@ describe('csc tests', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
stringsToMatch.forEach((string, index) => {
|
stringsToMatch.map((string, index) => {
|
||||||
const matchedResult = string.match(regex);
|
const matchedResultsArray = string.match(regex);
|
||||||
for (const name in expectedResults[index]) {
|
for (const propName in expectedResults[index]) {
|
||||||
expect(matchedResult![regexResultsMap[name]]).toEqual(
|
const propertyIndex = regexResultsMap[propName];
|
||||||
expectedResults[index][name]
|
const expectedPropValue = expectedResults[index][propName];
|
||||||
);
|
const matchedPropValue = matchedResultsArray![propertyIndex];
|
||||||
|
expect(matchedPropValue).toEqual(expectedPropValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
@ -8,134 +8,70 @@ import * as installer from '../src/installer';
|
|||||||
import {IS_WINDOWS} from '../src/utils';
|
import {IS_WINDOWS} from '../src/utils';
|
||||||
import {QualityOptions} from '../src/setup-dotnet';
|
import {QualityOptions} from '../src/setup-dotnet';
|
||||||
|
|
||||||
const env = process.env;
|
describe('installer tests', () => {
|
||||||
|
const env = process.env;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
process.env = {...env};
|
process.env = {...env};
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env = env;
|
process.env = env;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('DotnetCoreInstaller tests', () => {
|
describe('DotnetCoreInstaller tests', () => {
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
const warningSpy = jest.spyOn(core, 'warning');
|
const warningSpy = jest.spyOn(core, 'warning');
|
||||||
const whichSpy = jest.spyOn(io, 'which');
|
const whichSpy = jest.spyOn(io, 'which');
|
||||||
const maxSatisfyingSpy = jest.spyOn(semver, 'maxSatisfying');
|
const maxSatisfyingSpy = jest.spyOn(semver, 'maxSatisfying');
|
||||||
|
|
||||||
describe('installDotnet() tests', () => {
|
describe('installDotnet() tests', () => {
|
||||||
whichSpy.mockImplementation(() => Promise.resolve('PathToShell'));
|
whichSpy.mockImplementation(() => Promise.resolve('PathToShell'));
|
||||||
|
|
||||||
it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => {
|
it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => {
|
||||||
const inputVersion = '3.1.100';
|
const inputVersion = '3.1.100';
|
||||||
const inputQuality = '' as QualityOptions;
|
const inputQuality = '' as QualityOptions;
|
||||||
const errorMessage = 'Fictious error message!';
|
const errorMessage = 'Fictious error message!';
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: 1, stdout: '', stderr: errorMessage});
|
|
||||||
});
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
|
|
||||||
`Failed to install dotnet, exit code: 1. ${errorMessage}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return version of .NET SDK after installation complete', async () => {
|
|
||||||
const inputVersion = '3.1.100';
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
const installedVersion = await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
expect(installedVersion).toBe(inputVersion);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
|
|
||||||
const inputVersion = '6.0.300';
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
const expectedArgument = IS_WINDOWS
|
|
||||||
? `-Version ${inputVersion}`
|
|
||||||
: `--version ${inputVersion}`;
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
|
|
||||||
const inputVersion = '6.0.300';
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should warn if the 'quality' input is set and version isn't in A.B.C syntax but major tag is lower then 6`, async () => {
|
|
||||||
const inputVersion = '3.1';
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
|
||||||
`should supply 'quality' argument to the installation script if quality input is set and version is not in A.B.C syntax`,
|
|
||||||
async inputVersion => {
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
const exitCode = 0;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
return Promise.resolve({exitCode: exitCode, stdout: '', stderr: ''});
|
return Promise.resolve({
|
||||||
|
exitCode: 1,
|
||||||
|
stdout: '',
|
||||||
|
stderr: errorMessage
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
inputVersion,
|
||||||
|
inputQuality
|
||||||
|
);
|
||||||
|
await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
|
||||||
|
`Failed to install dotnet, exit code: 1. ${errorMessage}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return version of .NET SDK after installation complete', async () => {
|
||||||
|
const inputVersion = '3.1.100';
|
||||||
|
const inputQuality = '' as QualityOptions;
|
||||||
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
|
});
|
||||||
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
inputVersion,
|
||||||
|
inputQuality
|
||||||
|
);
|
||||||
|
const installedVersion = await dotnetInstaller.installDotnet();
|
||||||
|
|
||||||
|
expect(installedVersion).toBe(inputVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
|
||||||
|
const inputVersion = '6.0.300';
|
||||||
|
const inputQuality = '' as QualityOptions;
|
||||||
|
|
||||||
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
});
|
});
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
@ -150,44 +86,15 @@ describe('DotnetCoreInstaller tests', () => {
|
|||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||||
).join(' ');
|
).join(' ');
|
||||||
const expectedArgument = IS_WINDOWS
|
const expectedArgument = IS_WINDOWS
|
||||||
? `-Quality ${inputQuality}`
|
? `-Version ${inputVersion}`
|
||||||
: `--quality ${inputQuality}`;
|
: `--version ${inputVersion}`;
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
expect(scriptArguments).toContain(expectedArgument);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
|
||||||
`should supply 'channel' argument to the installation script if version isn't in A.B.C syntax`,
|
const inputVersion = '6.0.300';
|
||||||
async inputVersion => {
|
const inputQuality = 'ga' as QualityOptions;
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
const exitCode = 0;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({exitCode: exitCode, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
const expectedArgument = IS_WINDOWS ? `-Channel 6.0` : `--channel 6.0`;
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
|
|
||||||
process.env['https_proxy'] = 'https://proxy.com';
|
|
||||||
const inputVersion = '6.0.100';
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
@ -201,19 +108,14 @@ describe('DotnetCoreInstaller tests', () => {
|
|||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
|
|
||||||
const scriptArguments = (
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
||||||
).join(' ');
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(
|
|
||||||
`-ProxyAddress ${process.env['https_proxy']}`
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should supply '-ProxyBypassList' argument to the installation script if env.variable 'no_proxy' is set`, async () => {
|
it(`should warn if the 'quality' input is set and version isn't in A.B.C syntax but major tag is lower then 6`, async () => {
|
||||||
process.env['no_proxy'] = 'first.url,second.url';
|
const inputVersion = '3.1';
|
||||||
const inputVersion = '6.0.100';
|
const inputQuality = 'ga' as QualityOptions;
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
@ -227,142 +129,274 @@ describe('DotnetCoreInstaller tests', () => {
|
|||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
|
|
||||||
const scriptArguments = (
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
||||||
).join(' ');
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(
|
|
||||||
`-ProxyBypassList ${process.env['no_proxy']}`
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
describe('addToPath() tests', () => {
|
|
||||||
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
|
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictious/dotnet/install/dir';
|
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
|
||||||
const dotnet_root = process.env['DOTNET_ROOT'];
|
|
||||||
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should export value from the DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
|
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictious/dotnet/install/dir';
|
`should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`,
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
async inputVersion => {
|
||||||
const path = process.env['PATH'];
|
const inputQuality = 'ga' as QualityOptions;
|
||||||
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
|
const exitCode = 0;
|
||||||
});
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
});
|
return Promise.resolve({
|
||||||
});
|
exitCode: exitCode,
|
||||||
|
stdout: '',
|
||||||
|
stderr: ''
|
||||||
|
});
|
||||||
|
});
|
||||||
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
describe('DotnetVersionResolver tests', () => {
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
each([
|
inputVersion,
|
||||||
'3.1',
|
inputQuality
|
||||||
'3.x',
|
);
|
||||||
'3.1.x',
|
|
||||||
'3.1.*',
|
await dotnetInstaller.installDotnet();
|
||||||
'3.1.X',
|
|
||||||
'3.1.2',
|
const scriptArguments = (
|
||||||
'3.1.0-preview1'
|
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||||
]).test(
|
).join(' ');
|
||||||
'if valid version is supplied, it should return version object with some value',
|
const expectedArgument = IS_WINDOWS
|
||||||
async version => {
|
? `-Quality ${inputQuality}`
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
: `--quality ${inputQuality}`;
|
||||||
version
|
|
||||||
|
expect(scriptArguments).toContain(expectedArgument);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(!!versionObject.value).toBe(true);
|
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
||||||
}
|
`should supply 'channel' argument to the installation script if version (%s) isn't in A.B.C syntax`,
|
||||||
);
|
async inputVersion => {
|
||||||
|
const inputQuality = '' as QualityOptions;
|
||||||
|
const exitCode = 0;
|
||||||
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
exitCode: exitCode,
|
||||||
|
stdout: '',
|
||||||
|
stderr: ''
|
||||||
|
});
|
||||||
|
});
|
||||||
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
each([
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
'.',
|
inputVersion,
|
||||||
'..',
|
inputQuality
|
||||||
' . ',
|
);
|
||||||
'. ',
|
|
||||||
' .',
|
|
||||||
' . . ',
|
|
||||||
' .. ',
|
|
||||||
' . ',
|
|
||||||
'-1.-1',
|
|
||||||
'-1',
|
|
||||||
'-1.-1.-1',
|
|
||||||
'..3',
|
|
||||||
'1..3',
|
|
||||||
'1..',
|
|
||||||
'.2.3',
|
|
||||||
'.2.x',
|
|
||||||
'*.',
|
|
||||||
'1.2.',
|
|
||||||
'1.2.-abc',
|
|
||||||
'a.b',
|
|
||||||
'a.b.c',
|
|
||||||
'a.b.c-preview',
|
|
||||||
' 0 . 1 . 2 ',
|
|
||||||
'invalid'
|
|
||||||
]).test('if invalid version is supplied, it should throw', async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(version);
|
|
||||||
|
|
||||||
await expect(
|
await dotnetInstaller.installDotnet();
|
||||||
async () => await dotnetVersionResolver.createDotNetVersion()
|
|
||||||
).rejects.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X']).test(
|
const scriptArguments = (
|
||||||
"if version that can be resolved to 'channel' option is supplied, it should set type to 'channel' in version object",
|
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||||
async version => {
|
).join(' ');
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
const expectedArgument = IS_WINDOWS
|
||||||
version
|
? `-Channel 6.0`
|
||||||
|
: `--channel 6.0`;
|
||||||
|
|
||||||
|
expect(scriptArguments).toContain(expectedArgument);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
|
||||||
"if version that can be resolved to 'channel' option is supplied and its major tag is >= 6, it should set type to 'channel' and qualityFlag to 'true' in version object",
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
|
|
||||||
expect(versionObject.qualityFlag).toBe(true);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['3.1.2', '3.1.0-preview1']).test(
|
|
||||||
"if version that can be resolved to 'version' option is supplied, it should set quality flag to 'false' and type to 'version' in version object",
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('version')).toBe(true);
|
|
||||||
expect(versionObject.qualityFlag).toBe(false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['3.1.2', '3.1']).test(
|
|
||||||
'it should create proper line arguments for powershell/bash installation scripts',
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
|
|
||||||
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
expect(windowsRegEx.test(versionObject.type)).toBe(true);
|
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
|
||||||
expect(nonWindowsRegEx.test(versionObject.type)).toBe(false);
|
process.env['https_proxy'] = 'https://proxy.com';
|
||||||
} else {
|
const inputVersion = '6.0.100';
|
||||||
expect(nonWindowsRegEx.test(versionObject.type)).toBe(true);
|
const inputQuality = '' as QualityOptions;
|
||||||
expect(windowsRegEx.test(versionObject.type)).toBe(false);
|
|
||||||
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
|
});
|
||||||
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
inputVersion,
|
||||||
|
inputQuality
|
||||||
|
);
|
||||||
|
|
||||||
|
await dotnetInstaller.installDotnet();
|
||||||
|
|
||||||
|
const scriptArguments = (
|
||||||
|
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||||
|
).join(' ');
|
||||||
|
|
||||||
|
expect(scriptArguments).toContain(
|
||||||
|
`-ProxyAddress ${process.env['https_proxy']}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should supply '-ProxyBypassList' argument to the installation script if env.variable 'no_proxy' is set`, async () => {
|
||||||
|
process.env['no_proxy'] = 'first.url,second.url';
|
||||||
|
const inputVersion = '6.0.100';
|
||||||
|
const inputQuality = '' as QualityOptions;
|
||||||
|
|
||||||
|
getExecOutputSpy.mockImplementation(() => {
|
||||||
|
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||||
|
});
|
||||||
|
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||||
|
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
inputVersion,
|
||||||
|
inputQuality
|
||||||
|
);
|
||||||
|
|
||||||
|
await dotnetInstaller.installDotnet();
|
||||||
|
|
||||||
|
const scriptArguments = (
|
||||||
|
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||||
|
).join(' ');
|
||||||
|
|
||||||
|
expect(scriptArguments).toContain(
|
||||||
|
`-ProxyBypassList ${process.env['no_proxy']}`
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
describe('addToPath() tests', () => {
|
||||||
|
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
|
||||||
|
process.env['DOTNET_INSTALL_DIR'] = 'fictious/dotnet/install/dir';
|
||||||
|
installer.DotnetCoreInstaller.addToPath();
|
||||||
|
const dotnet_root = process.env['DOTNET_ROOT'];
|
||||||
|
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should export value from the DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
|
||||||
|
process.env['DOTNET_INSTALL_DIR'] = 'fictious/dotnet/install/dir';
|
||||||
|
installer.DotnetCoreInstaller.addToPath();
|
||||||
|
const path = process.env['PATH'];
|
||||||
|
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('DotnetVersionResolver tests', () => {
|
||||||
|
describe('createDotNetVersion() tests', () => {
|
||||||
|
each([
|
||||||
|
'3.1',
|
||||||
|
'3.x',
|
||||||
|
'3.1.x',
|
||||||
|
'3.1.*',
|
||||||
|
'3.1.X',
|
||||||
|
'3.1.2',
|
||||||
|
'3.1.0-preview1'
|
||||||
|
]).test(
|
||||||
|
'if valid version is supplied (%s), it should return version object with some value',
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
const versionObject =
|
||||||
|
await dotnetVersionResolver.createDotNetVersion();
|
||||||
|
|
||||||
|
expect(!!versionObject.value).toBe(true);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each([
|
||||||
|
'.',
|
||||||
|
'..',
|
||||||
|
' . ',
|
||||||
|
'. ',
|
||||||
|
' .',
|
||||||
|
' . . ',
|
||||||
|
' .. ',
|
||||||
|
' . ',
|
||||||
|
'-1.-1',
|
||||||
|
'-1',
|
||||||
|
'-1.-1.-1',
|
||||||
|
'..3',
|
||||||
|
'1..3',
|
||||||
|
'1..',
|
||||||
|
'.2.3',
|
||||||
|
'.2.x',
|
||||||
|
'*.',
|
||||||
|
'1.2.',
|
||||||
|
'1.2.-abc',
|
||||||
|
'a.b',
|
||||||
|
'a.b.c',
|
||||||
|
'a.b.c-preview',
|
||||||
|
' 0 . 1 . 2 ',
|
||||||
|
'invalid'
|
||||||
|
]).test(
|
||||||
|
'if invalid version is supplied (%s), it should throw',
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
async () => await dotnetVersionResolver.createDotNetVersion()
|
||||||
|
).rejects.toThrow();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X']).test(
|
||||||
|
"if version that can be resolved to 'channel' option is supplied (%s), it should set type to 'channel' in version object",
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
const versionObject =
|
||||||
|
await dotnetVersionResolver.createDotNetVersion();
|
||||||
|
|
||||||
|
expect(versionObject.type.toLowerCase().includes('channel')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each(['6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
||||||
|
"if version that can be resolved to 'channel' option is supplied and its major tag is >= 6 (%s), it should set type to 'channel' and qualityFlag to 'true' in version object",
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
const versionObject =
|
||||||
|
await dotnetVersionResolver.createDotNetVersion();
|
||||||
|
|
||||||
|
expect(versionObject.type.toLowerCase().includes('channel')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
expect(versionObject.qualityFlag).toBe(true);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each(['3.1.2', '3.1.0-preview1']).test(
|
||||||
|
"if version that can be resolved to 'version' option is supplied (%s), it should set quality flag to 'false' and type to 'version' in version object",
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
const versionObject =
|
||||||
|
await dotnetVersionResolver.createDotNetVersion();
|
||||||
|
|
||||||
|
expect(versionObject.type.toLowerCase().includes('version')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
expect(versionObject.qualityFlag).toBe(false);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each(['3.1.2', '3.1']).test(
|
||||||
|
'it should create proper line arguments for powershell/bash installation scripts',
|
||||||
|
async version => {
|
||||||
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
version
|
||||||
|
);
|
||||||
|
const versionObject =
|
||||||
|
await dotnetVersionResolver.createDotNetVersion();
|
||||||
|
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
|
||||||
|
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(windowsRegEx.test(versionObject.type)).toBe(true);
|
||||||
|
expect(nonWindowsRegEx.test(versionObject.type)).toBe(false);
|
||||||
|
} else {
|
||||||
|
expect(nonWindowsRegEx.test(versionObject.type)).toBe(true);
|
||||||
|
expect(windowsRegEx.test(versionObject.type)).toBe(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user