Skip to content

Commit 2f028bc

Browse files
author
IvanZosimov
committed
update unit and e2e tests
1 parent 21cf89a commit 2f028bc

File tree

6 files changed

+102
-17
lines changed

6 files changed

+102
-17
lines changed

.github/workflows/e2e-tests.yml

+35-10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ jobs:
133133
shell: pwsh
134134
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
135135

136+
test-ABCxx-syntax:
137+
runs-on: ${{ matrix.operating-system }}
138+
strategy:
139+
fail-fast: false
140+
matrix:
141+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
142+
steps:
143+
- name: Checkout
144+
uses: actions/checkout@v3
145+
- name: Clear toolcache
146+
shell: pwsh
147+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
148+
149+
- name: Setup dotnet 6.0.4xx
150+
uses: ./
151+
with:
152+
dotnet-version: '6.0.4xx'
153+
- name: Verify dotnet
154+
shell: pwsh
155+
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
156+
136157
test-setup-with-wildcard:
137158
runs-on: ${{ matrix.operating-system }}
138159
strategy:
@@ -183,7 +204,7 @@ jobs:
183204
shell: pwsh
184205
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
185206

186-
test-setup-with-dotnet-quality:
207+
test-setup-global-json-only:
187208
runs-on: ${{ matrix.operating-system }}
188209
strategy:
189210
fail-fast: false
@@ -195,17 +216,20 @@ jobs:
195216
- name: Clear toolcache
196217
shell: pwsh
197218
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
198-
199-
- name: Setup dotnet 7.0 with preview quality
219+
- name: Write global.json
220+
shell: bash
221+
run: |
222+
mkdir subdirectory
223+
echo '{"sdk":{"version": "2.2.207","rollForward": "latestFeature"}}' > ./subdirectory/global.json
224+
- name: Setup dotnet
200225
uses: ./
201226
with:
202-
dotnet-version: '7.0'
203-
dotnet-quality: 'preview'
227+
global-json-file: ./subdirectory/global.json
204228
- name: Verify dotnet
205229
shell: pwsh
206-
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
230+
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
207231

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

221-
- name: Setup dotnet 6.0.4xx
245+
- name: Setup dotnet 7.0 with preview quality
222246
uses: ./
223247
with:
224-
dotnet-version: '6.0.4xx'
248+
dotnet-version: '7.0'
249+
dotnet-quality: 'preview'
225250
- name: Verify dotnet
226251
shell: pwsh
227-
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
252+
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
228253

229254
test-dotnet-version-output-during-single-version-installation:
230255
runs-on: ${{ matrix.operating-system }}

__tests__/installer.test.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ describe('installer tests', () => {
306306
'3.1.*',
307307
'3.1.X',
308308
'3.1.2',
309-
'3.1.0-preview1'
309+
'3.1.0-preview1',
310+
'6.0.2xx'
310311
]).test(
311312
'if valid version is supplied (%s), it should return version object with some value',
312313
async version => {
@@ -358,7 +359,16 @@ describe('installer tests', () => {
358359
}
359360
);
360361

361-
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X']).test(
362+
each([
363+
'3',
364+
'3.1',
365+
'3.1.x',
366+
'3.1.*',
367+
'3.1.X',
368+
'6.0.2xx',
369+
'6.0.2XX',
370+
'6.0.2**'
371+
]).test(
362372
"if version that can be resolved to 'channel' option is supplied (%s), it should set type to 'channel' in version object",
363373
async version => {
364374
const dotnetVersionResolver = new installer.DotnetVersionResolver(
@@ -373,7 +383,15 @@ describe('installer tests', () => {
373383
}
374384
);
375385

376-
each(['6.0', '6.0.x', '6.0.*', '6.0.X']).test(
386+
each([
387+
'6.0',
388+
'6.0.x',
389+
'6.0.*',
390+
'6.0.X',
391+
'6.0.2xx',
392+
'6.0.2XX',
393+
'6.0.2**'
394+
]).test(
377395
"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",
378396
async version => {
379397
const dotnetVersionResolver = new installer.DotnetVersionResolver(
@@ -425,6 +443,18 @@ describe('installer tests', () => {
425443
}
426444
}
427445
);
446+
447+
it(`should throw if dotnet-version is supplied in A.B.Cxx syntax with major tag lower that 5`, async () => {
448+
const version = '3.0.1xx';
449+
const dotnetVersionResolver = new installer.DotnetVersionResolver(
450+
version
451+
);
452+
await expect(
453+
async () => await dotnetVersionResolver.createDotNetVersion()
454+
).rejects.toThrow(
455+
`'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
456+
);
457+
});
428458
});
429459
});
430460
});

__tests__/setup-dotnet.test.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('setup-dotnet tests', () => {
1212
const getInputSpy = jest.spyOn(core, 'getInput');
1313
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
1414
const setFailedSpy = jest.spyOn(core, 'setFailed');
15+
const warningSpy = jest.spyOn(core, 'warning');
1516
const debugSpy = jest.spyOn(core, 'debug');
1617
const infoSpy = jest.spyOn(core, 'info');
1718
const setOutputSpy = jest.spyOn(core, 'setOutput');
@@ -133,14 +134,40 @@ describe('setup-dotnet tests', () => {
133134
);
134135
});
135136

136-
it('should call setOutput() after installation complete', async () => {
137+
it('should call setOutput() after installation complete successfully', async () => {
137138
inputs['dotnet-version'] = ['6.0.300'];
138139

139-
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
140+
installDotnetSpy.mockImplementation(() =>
141+
Promise.resolve(`${inputs['dotnet-version']}`)
142+
);
140143
addToPathSpy.mockImplementation(() => {});
141144

142145
await setup.run();
143146
expect(setOutputSpy).toHaveBeenCalledTimes(1);
144147
});
148+
149+
it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
150+
inputs['dotnet-version'] = ['6.0.300'];
151+
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;
152+
153+
installDotnetSpy.mockImplementation(() => Promise.resolve(null));
154+
addToPathSpy.mockImplementation(() => {});
155+
156+
await setup.run();
157+
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
158+
expect(setOutputSpy).not.toHaveBeenCalled();
159+
});
160+
161+
it(`shouldn't call setOutput() if actions didn't install .NET`, async () => {
162+
inputs['dotnet-version'] = [];
163+
const warningMessage = `No .NET version was installed. The 'dotnet-version' output will not be set.`;
164+
165+
addToPathSpy.mockImplementation(() => {});
166+
167+
await setup.run();
168+
169+
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
170+
expect(setOutputSpy).not.toHaveBeenCalled();
171+
});
145172
});
146173
});

dist/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class DotnetVersionResolver {
270270
}
271271
isLatestPatchSyntax() {
272272
var _b, _c;
273-
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;
273+
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;
274274
if (majorTag &&
275275
parseInt(majorTag) <
276276
DotnetInstallerLimits.LatestPatchSyntaxMinimalMajorTag) {
@@ -606,6 +606,7 @@ function getVersionFromGlobalJson(globalJsonPath) {
606606
function outputInstalledVersion(installedVersions, globalJsonFileInput) {
607607
if (!installedVersions.length) {
608608
core.info(`No .NET version was installed. The 'dotnet-version' output will not be set.`);
609+
return;
609610
}
610611
if (installedVersions.includes(null)) {
611612
core.warning(`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`);

src/installer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class DotnetVersionResolver {
4949

5050
private isLatestPatchSyntax() {
5151
const majorTag = this.inputVersion.match(
52-
/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/
52+
/^(?<majorTag>\d+)\.\d+\.\d{1}(x|X|\*){2}$/
5353
)?.groups?.majorTag;
5454
if (
5555
majorTag &&

src/setup-dotnet.ts

+2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ function outputInstalledVersion(
112112
core.info(
113113
`No .NET version was installed. The 'dotnet-version' output will not be set.`
114114
);
115+
return;
115116
}
117+
116118
if (installedVersions.includes(null)) {
117119
core.warning(
118120
`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`

0 commit comments

Comments
 (0)