mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-14 20:55:11 +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
|
||||
shell: pwsh
|
||||
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: ./
|
||||
with:
|
||||
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 () => {
|
||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -107,7 +107,7 @@ describe('authutil tests', () => {
|
||||
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
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 () => {
|
||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||
process.env['INPUT_OWNER'] = 'otherorg';
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/otherorg/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -141,7 +141,7 @@ describe('authutil tests', () => {
|
||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -159,7 +159,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -177,7 +177,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -195,7 +195,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -213,7 +213,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -231,7 +231,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -251,7 +251,7 @@ describe('authutil tests', () => {
|
||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -274,7 +274,7 @@ describe('authutil tests', () => {
|
||||
);
|
||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'subfolder/nuget.config',
|
||||
fakeSourcesDirForTesting
|
||||
@ -292,7 +292,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
@ -310,7 +310,7 @@ describe('authutil tests', () => {
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
auth.configAuthentication(
|
||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||
'',
|
||||
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 () => {
|
||||
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',
|
||||
'',
|
||||
fakeSourcesDirForTesting
|
||||
|
@ -32,12 +32,13 @@ describe('csc tests', () => {
|
||||
}
|
||||
];
|
||||
|
||||
stringsToMatch.forEach((string, index) => {
|
||||
const matchedResult = string.match(regex);
|
||||
for (const name in expectedResults[index]) {
|
||||
expect(matchedResult![regexResultsMap[name]]).toEqual(
|
||||
expectedResults[index][name]
|
||||
);
|
||||
stringsToMatch.map((string, index) => {
|
||||
const matchedResultsArray = string.match(regex);
|
||||
for (const propName in expectedResults[index]) {
|
||||
const propertyIndex = regexResultsMap[propName];
|
||||
const expectedPropValue = expectedResults[index][propName];
|
||||
const matchedPropValue = matchedResultsArray![propertyIndex];
|
||||
expect(matchedPropValue).toEqual(expectedPropValue);
|
||||
}
|
||||
});
|
||||
}, 10000);
|
||||
|
@ -8,6 +8,7 @@ import * as installer from '../src/installer';
|
||||
import {IS_WINDOWS} from '../src/utils';
|
||||
import {QualityOptions} from '../src/setup-dotnet';
|
||||
|
||||
describe('installer tests', () => {
|
||||
const env = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -33,7 +34,11 @@ describe('DotnetCoreInstaller tests', () => {
|
||||
const inputQuality = '' as QualityOptions;
|
||||
const errorMessage = 'Fictious error message!';
|
||||
getExecOutputSpy.mockImplementation(() => {
|
||||
return Promise.resolve({exitCode: 1, stdout: '', stderr: errorMessage});
|
||||
return Promise.resolve({
|
||||
exitCode: 1,
|
||||
stdout: '',
|
||||
stderr: errorMessage
|
||||
});
|
||||
});
|
||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||
inputVersion,
|
||||
@ -130,12 +135,16 @@ describe('DotnetCoreInstaller tests', () => {
|
||||
});
|
||||
|
||||
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`,
|
||||
`should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`,
|
||||
async inputVersion => {
|
||||
const inputQuality = 'ga' as QualityOptions;
|
||||
const exitCode = 0;
|
||||
getExecOutputSpy.mockImplementation(() => {
|
||||
return Promise.resolve({exitCode: exitCode, stdout: '', stderr: ''});
|
||||
return Promise.resolve({
|
||||
exitCode: exitCode,
|
||||
stdout: '',
|
||||
stderr: ''
|
||||
});
|
||||
});
|
||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||
|
||||
@ -158,12 +167,16 @@ describe('DotnetCoreInstaller tests', () => {
|
||||
);
|
||||
|
||||
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
||||
`should supply 'channel' argument to the installation script if version isn't in A.B.C syntax`,
|
||||
`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: ''});
|
||||
return Promise.resolve({
|
||||
exitCode: exitCode,
|
||||
stdout: '',
|
||||
stderr: ''
|
||||
});
|
||||
});
|
||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
||||
|
||||
@ -177,7 +190,9 @@ describe('DotnetCoreInstaller tests', () => {
|
||||
const scriptArguments = (
|
||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
||||
).join(' ');
|
||||
const expectedArgument = IS_WINDOWS ? `-Channel 6.0` : `--channel 6.0`;
|
||||
const expectedArgument = IS_WINDOWS
|
||||
? `-Channel 6.0`
|
||||
: `--channel 6.0`;
|
||||
|
||||
expect(scriptArguments).toContain(expectedArgument);
|
||||
}
|
||||
@ -255,6 +270,7 @@ describe('DotnetCoreInstaller tests', () => {
|
||||
});
|
||||
|
||||
describe('DotnetVersionResolver tests', () => {
|
||||
describe('createDotNetVersion() tests', () => {
|
||||
each([
|
||||
'3.1',
|
||||
'3.x',
|
||||
@ -264,12 +280,13 @@ describe('DotnetVersionResolver tests', () => {
|
||||
'3.1.2',
|
||||
'3.1.0-preview1'
|
||||
]).test(
|
||||
'if valid version is supplied, it should return version object with some value',
|
||||
'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();
|
||||
const versionObject =
|
||||
await dotnetVersionResolver.createDotNetVersion();
|
||||
|
||||
expect(!!versionObject.value).toBe(true);
|
||||
}
|
||||
@ -300,48 +317,62 @@ describe('DotnetVersionResolver tests', () => {
|
||||
'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);
|
||||
]).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, it should set type to 'channel' in version object",
|
||||
"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();
|
||||
const versionObject =
|
||||
await dotnetVersionResolver.createDotNetVersion();
|
||||
|
||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
|
||||
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",
|
||||
"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();
|
||||
const versionObject =
|
||||
await dotnetVersionResolver.createDotNetVersion();
|
||||
|
||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
|
||||
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",
|
||||
"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();
|
||||
const versionObject =
|
||||
await dotnetVersionResolver.createDotNetVersion();
|
||||
|
||||
expect(versionObject.type.toLowerCase().includes('version')).toBe(true);
|
||||
expect(versionObject.type.toLowerCase().includes('version')).toBe(
|
||||
true
|
||||
);
|
||||
expect(versionObject.qualityFlag).toBe(false);
|
||||
}
|
||||
);
|
||||
@ -352,7 +383,8 @@ describe('DotnetVersionResolver tests', () => {
|
||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||
version
|
||||
);
|
||||
const versionObject = await dotnetVersionResolver.createDotNetVersion();
|
||||
const versionObject =
|
||||
await dotnetVersionResolver.createDotNetVersion();
|
||||
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
|
||||
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);
|
||||
|
||||
@ -366,3 +398,5 @@ describe('DotnetVersionResolver tests', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user