mirror of
				https://github.com/actions/setup-dotnet.git
				synced 2025-10-31 22:43:44 +00:00 
			
		
		
		
	update unit and e2e tests
This commit is contained in:
		
							parent
							
								
									21cf89aa73
								
							
						
					
					
						commit
						2f028bc044
					
				
							
								
								
									
										67
									
								
								.github/workflows/e2e-tests.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										67
									
								
								.github/workflows/e2e-tests.yml
									
									
									
									
										vendored
									
									
								
							| @ -133,6 +133,27 @@ jobs: | |||||||
|         shell: pwsh |         shell: pwsh | ||||||
|         run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1" |         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: |   test-setup-with-wildcard: | ||||||
|     runs-on: ${{ matrix.operating-system }} |     runs-on: ${{ matrix.operating-system }} | ||||||
|     strategy: |     strategy: | ||||||
| @ -183,6 +204,31 @@ jobs: | |||||||
|         shell: pwsh |         shell: pwsh | ||||||
|         run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1" |         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: |   test-setup-with-dotnet-quality: | ||||||
|     runs-on: ${{ matrix.operating-system }} |     runs-on: ${{ matrix.operating-system }} | ||||||
|     strategy: |     strategy: | ||||||
| @ -205,27 +251,6 @@ jobs: | |||||||
|         shell: pwsh |         shell: pwsh | ||||||
|         run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-" |         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: |   test-dotnet-version-output-during-single-version-installation: | ||||||
|     runs-on: ${{ matrix.operating-system }} |     runs-on: ${{ matrix.operating-system }} | ||||||
|     strategy: |     strategy: | ||||||
|  | |||||||
| @ -306,7 +306,8 @@ describe('installer tests', () => { | |||||||
|         '3.1.*', |         '3.1.*', | ||||||
|         '3.1.X', |         '3.1.X', | ||||||
|         '3.1.2', |         '3.1.2', | ||||||
|         '3.1.0-preview1' |         '3.1.0-preview1', | ||||||
|  |         '6.0.2xx' | ||||||
|       ]).test( |       ]).test( | ||||||
|         'if valid version is supplied (%s), it should return version object with some value', |         'if valid version is supplied (%s), it should return version object with some value', | ||||||
|         async version => { |         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", |         "if version that can be resolved to 'channel' option is supplied (%s), it should set type to 'channel' in version object", | ||||||
|         async version => { |         async version => { | ||||||
|           const dotnetVersionResolver = new installer.DotnetVersionResolver( |           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", |         "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 => { |         async version => { | ||||||
|           const dotnetVersionResolver = new installer.DotnetVersionResolver( |           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.` | ||||||
|  |         ); | ||||||
|  |       }); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ describe('setup-dotnet tests', () => { | |||||||
|   const getInputSpy = jest.spyOn(core, 'getInput'); |   const getInputSpy = jest.spyOn(core, 'getInput'); | ||||||
|   const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput'); |   const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput'); | ||||||
|   const setFailedSpy = jest.spyOn(core, 'setFailed'); |   const setFailedSpy = jest.spyOn(core, 'setFailed'); | ||||||
|  |   const warningSpy = jest.spyOn(core, 'warning'); | ||||||
|   const debugSpy = jest.spyOn(core, 'debug'); |   const debugSpy = jest.spyOn(core, 'debug'); | ||||||
|   const infoSpy = jest.spyOn(core, 'info'); |   const infoSpy = jest.spyOn(core, 'info'); | ||||||
|   const setOutputSpy = jest.spyOn(core, 'setOutput'); |   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']; |       inputs['dotnet-version'] = ['6.0.300']; | ||||||
| 
 | 
 | ||||||
|       installDotnetSpy.mockImplementation(() => Promise.resolve('')); |       installDotnetSpy.mockImplementation(() => | ||||||
|  |         Promise.resolve(`${inputs['dotnet-version']}`) | ||||||
|  |       ); | ||||||
|       addToPathSpy.mockImplementation(() => {}); |       addToPathSpy.mockImplementation(() => {}); | ||||||
| 
 | 
 | ||||||
|       await setup.run(); |       await setup.run(); | ||||||
|       expect(setOutputSpy).toHaveBeenCalledTimes(1); |       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
									
									
								
							
							
						
						
									
										3
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @ -270,7 +270,7 @@ class DotnetVersionResolver { | |||||||
|     } |     } | ||||||
|     isLatestPatchSyntax() { |     isLatestPatchSyntax() { | ||||||
|         var _b, _c; |         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 && |         if (majorTag && | ||||||
|             parseInt(majorTag) < |             parseInt(majorTag) < | ||||||
|                 DotnetInstallerLimits.LatestPatchSyntaxMinimalMajorTag) { |                 DotnetInstallerLimits.LatestPatchSyntaxMinimalMajorTag) { | ||||||
| @ -606,6 +606,7 @@ function getVersionFromGlobalJson(globalJsonPath) { | |||||||
| function outputInstalledVersion(installedVersions, globalJsonFileInput) { | function outputInstalledVersion(installedVersions, globalJsonFileInput) { | ||||||
|     if (!installedVersions.length) { |     if (!installedVersions.length) { | ||||||
|         core.info(`No .NET version was installed. The 'dotnet-version' output will not be set.`); |         core.info(`No .NET version was installed. The 'dotnet-version' output will not be set.`); | ||||||
|  |         return; | ||||||
|     } |     } | ||||||
|     if (installedVersions.includes(null)) { |     if (installedVersions.includes(null)) { | ||||||
|         core.warning(`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`); |         core.warning(`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`); | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ export class DotnetVersionResolver { | |||||||
| 
 | 
 | ||||||
|   private isLatestPatchSyntax() { |   private isLatestPatchSyntax() { | ||||||
|     const majorTag = this.inputVersion.match( |     const majorTag = this.inputVersion.match( | ||||||
|       /^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/ |       /^(?<majorTag>\d+)\.\d+\.\d{1}(x|X|\*){2}$/ | ||||||
|     )?.groups?.majorTag; |     )?.groups?.majorTag; | ||||||
|     if ( |     if ( | ||||||
|       majorTag && |       majorTag && | ||||||
|  | |||||||
| @ -112,7 +112,9 @@ function outputInstalledVersion( | |||||||
|     core.info( |     core.info( | ||||||
|       `No .NET version was installed. The 'dotnet-version' output will not be set.` |       `No .NET version was installed. The 'dotnet-version' output will not be set.` | ||||||
|     ); |     ); | ||||||
|  |     return; | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|   if (installedVersions.includes(null)) { |   if (installedVersions.includes(null)) { | ||||||
|     core.warning( |     core.warning( | ||||||
|       `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.` |       `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.` | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user