update unit and e2e tests

This commit is contained in:
IvanZosimov 2023-05-18 11:11:51 +02:00
parent 21cf89aa73
commit 2f028bc044
6 changed files with 113 additions and 28 deletions

View File

@ -133,6 +133,27 @@ jobs:
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
test-ABCxx-syntax:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Setup dotnet 6.0.4xx
uses: ./
with:
dotnet-version: '6.0.4xx'
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
test-setup-with-wildcard:
runs-on: ${{ matrix.operating-system }}
strategy:
@ -183,6 +204,31 @@ jobs:
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
test-setup-global-json-only:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Write global.json
shell: bash
run: |
mkdir subdirectory
echo '{"sdk":{"version": "2.2.207","rollForward": "latestFeature"}}' > ./subdirectory/global.json
- name: Setup dotnet
uses: ./
with:
global-json-file: ./subdirectory/global.json
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
test-setup-with-dotnet-quality:
runs-on: ${{ matrix.operating-system }}
strategy:
@ -205,27 +251,6 @@ jobs:
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
test-ABCxx-syntax:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Setup dotnet 6.0.4xx
uses: ./
with:
dotnet-version: '6.0.4xx'
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
test-dotnet-version-output-during-single-version-installation:
runs-on: ${{ matrix.operating-system }}
strategy:

View File

@ -306,7 +306,8 @@ describe('installer tests', () => {
'3.1.*',
'3.1.X',
'3.1.2',
'3.1.0-preview1'
'3.1.0-preview1',
'6.0.2xx'
]).test(
'if valid version is supplied (%s), it should return version object with some value',
async version => {
@ -358,7 +359,16 @@ describe('installer tests', () => {
}
);
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X']).test(
each([
'3',
'3.1',
'3.1.x',
'3.1.*',
'3.1.X',
'6.0.2xx',
'6.0.2XX',
'6.0.2**'
]).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(
@ -373,7 +383,15 @@ describe('installer tests', () => {
}
);
each(['6.0', '6.0.x', '6.0.*', '6.0.X']).test(
each([
'6.0',
'6.0.x',
'6.0.*',
'6.0.X',
'6.0.2xx',
'6.0.2XX',
'6.0.2**'
]).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(
@ -425,6 +443,18 @@ describe('installer tests', () => {
}
}
);
it(`should throw if dotnet-version is supplied in A.B.Cxx syntax with major tag lower that 5`, async () => {
const version = '3.0.1xx';
const dotnetVersionResolver = new installer.DotnetVersionResolver(
version
);
await expect(
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.`
);
});
});
});
});

View File

@ -12,6 +12,7 @@ describe('setup-dotnet tests', () => {
const getInputSpy = jest.spyOn(core, 'getInput');
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
const setFailedSpy = jest.spyOn(core, 'setFailed');
const warningSpy = jest.spyOn(core, 'warning');
const debugSpy = jest.spyOn(core, 'debug');
const infoSpy = jest.spyOn(core, 'info');
const setOutputSpy = jest.spyOn(core, 'setOutput');
@ -133,14 +134,40 @@ describe('setup-dotnet tests', () => {
);
});
it('should call setOutput() after installation complete', async () => {
it('should call setOutput() after installation complete successfully', async () => {
inputs['dotnet-version'] = ['6.0.300'];
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
installDotnetSpy.mockImplementation(() =>
Promise.resolve(`${inputs['dotnet-version']}`)
);
addToPathSpy.mockImplementation(() => {});
await setup.run();
expect(setOutputSpy).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);
expect(setOutputSpy).not.toHaveBeenCalled();
});
it(`shouldn't call setOutput() if actions didn't install .NET`, async () => {
inputs['dotnet-version'] = [];
const warningMessage = `No .NET version was installed. The 'dotnet-version' output will not be set.`;
addToPathSpy.mockImplementation(() => {});
await setup.run();
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
expect(setOutputSpy).not.toHaveBeenCalled();
});
});
});

3
dist/index.js vendored
View File

@ -270,7 +270,7 @@ class DotnetVersionResolver {
}
isLatestPatchSyntax() {
var _b, _c;
const majorTag = (_c = (_b = this.inputVersion.match(/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/)) === null || _b === void 0 ? void 0 : _b.groups) === null || _c === void 0 ? void 0 : _c.majorTag;
const majorTag = (_c = (_b = this.inputVersion.match(/^(?<majorTag>\d+)\.\d+\.\d{1}(x|X|\*){2}$/)) === null || _b === void 0 ? void 0 : _b.groups) === null || _c === void 0 ? void 0 : _c.majorTag;
if (majorTag &&
parseInt(majorTag) <
DotnetInstallerLimits.LatestPatchSyntaxMinimalMajorTag) {
@ -606,6 +606,7 @@ function getVersionFromGlobalJson(globalJsonPath) {
function outputInstalledVersion(installedVersions, globalJsonFileInput) {
if (!installedVersions.length) {
core.info(`No .NET version was installed. The 'dotnet-version' output will not be set.`);
return;
}
if (installedVersions.includes(null)) {
core.warning(`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`);

View File

@ -49,7 +49,7 @@ export class DotnetVersionResolver {
private isLatestPatchSyntax() {
const majorTag = this.inputVersion.match(
/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/
/^(?<majorTag>\d+)\.\d+\.\d{1}(x|X|\*){2}$/
)?.groups?.majorTag;
if (
majorTag &&

View File

@ -112,7 +112,9 @@ function outputInstalledVersion(
core.info(
`No .NET version was installed. The 'dotnet-version' output will not be set.`
);
return;
}
if (installedVersions.includes(null)) {
core.warning(
`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`