mirror of
				https://github.com/docker/login-action.git
				synced 2025-10-31 18:20:10 +08:00 
			
		
		
		
	Add context tests
This commit is contained in:
		
							parent
							
								
									b4915282a8
								
							
						
					
					
						commit
						f3c2e45637
					
				
							
								
								
									
										16
									
								
								__tests__/context.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								__tests__/context.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | import osm = require('os'); | ||||||
|  | 
 | ||||||
|  | import {getInputs} from '../src/context'; | ||||||
|  | 
 | ||||||
|  | test('without password getInputs throws errors', async () => { | ||||||
|  |   expect(() => { | ||||||
|  |     getInputs(); | ||||||
|  |   }).toThrowError('Input required and not supplied: password'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test('with password getInputs does not error', async () => { | ||||||
|  |   process.env['INPUT_PASSWORD'] = 'groundcontrol'; | ||||||
|  |   expect(() => { | ||||||
|  |     getInputs(); | ||||||
|  |   }).not.toThrowError(); | ||||||
|  | }); | ||||||
| @ -7,7 +7,7 @@ export interface Inputs { | |||||||
|   logout: string; |   logout: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getInputs(): Promise<Inputs> { | export function getInputs(): Inputs { | ||||||
|   return { |   return { | ||||||
|     registry: core.getInput('registry'), |     registry: core.getInput('registry'), | ||||||
|     username: core.getInput('username'), |     username: core.getInput('username'), | ||||||
|  | |||||||
| @ -11,10 +11,10 @@ async function run(): Promise<void> { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let inputs: Inputs = await getInputs(); |     const {registry, username, password, logout} = getInputs(); | ||||||
|     stateHelper.setRegistry(inputs.registry); |     stateHelper.setRegistry(registry); | ||||||
|     stateHelper.setLogout(inputs.logout); |     stateHelper.setLogout(logout); | ||||||
|     await docker.login(inputs.registry, inputs.username, inputs.password); |     await docker.login(registry, username, password); | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|     core.setFailed(error.message); |     core.setFailed(error.message); | ||||||
|   } |   } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Bryan Clark
						Bryan Clark