Skip to content

Commit

Permalink
update unit and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanZosimov committed May 18, 2023
1 parent 21cf89a commit 2f028bc
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 17 deletions.
45 changes: 35 additions & 10 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -183,7 +204,7 @@ jobs:
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"

test-setup-with-dotnet-quality:
test-setup-global-json-only:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
Expand All @@ -195,17 +216,20 @@ jobs:
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}

- name: Setup dotnet 7.0 with preview quality
- 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:
dotnet-version: '7.0'
dotnet-quality: 'preview'
global-json-file: ./subdirectory/global.json
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"

test-ABCxx-syntax:
test-setup-with-dotnet-quality:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
Expand All @@ -218,13 +242,14 @@ jobs:
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}

- name: Setup dotnet 6.0.4xx
- name: Setup dotnet 7.0 with preview quality
uses: ./
with:
dotnet-version: '6.0.4xx'
dotnet-version: '7.0'
dotnet-quality: 'preview'
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"

test-dotnet-version-output-during-single-version-installation:
runs-on: ${{ matrix.operating-system }}
Expand Down
36 changes: 33 additions & 3 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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.`
);
});
});
});
});
31 changes: 29 additions & 2 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.`);
Expand Down
2 changes: 1 addition & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 2 additions & 0 deletions src/setup-dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
Expand Down

0 comments on commit 2f028bc

Please sign in to comment.