| 
									
										
										
										
											2018-07-15 23:58:43 +02:00
										 |  |  | import { tap, expect } from '@pushrocks/tapbundle'; | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | import * as path from 'path'; | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | process.env.NPMTS_TEST = 'true'; | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | // set up environment
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git'; | 
					
						
							|  |  |  | process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs'; | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Docker
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass'; | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // SSH env
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##'; | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | process.cwd = () => { | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |   return path.join(__dirname, 'assets/'); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  | import * as npmci from '../ts'; | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // ======
 | 
					
						
							|  |  |  | // Docker
 | 
					
						
							|  |  |  | // ======
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  | let dockerfile1: npmci.Dockerfile; | 
					
						
							|  |  |  | let dockerfile2: npmci.Dockerfile; | 
					
						
							|  |  |  | let sortableArray: npmci.Dockerfile[]; | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | tap.test('should return valid Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   dockerfile1 = new npmci.Dockerfile(npmciInstance.dockerManager, { filePath: './Dockerfile', read: true }); | 
					
						
							|  |  |  |   dockerfile2 = new npmci.Dockerfile(npmciInstance.dockerManager, { filePath: './Dockerfile_sometag1', read: true }); | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |   expect(dockerfile1.version).to.equal('latest'); | 
					
						
							|  |  |  |   return expect(dockerfile2.version).to.equal('sometag1'); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | tap.test('should read a directory of Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   return npmci.Dockerfile | 
					
						
							|  |  |  |     .readDockerfiles(npmciInstance.dockerManager) | 
					
						
							|  |  |  |     .then(async (readDockerfilesArrayArg: npmci.Dockerfile[]) => { | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |       sortableArray = readDockerfilesArrayArg; | 
					
						
							|  |  |  |       return expect(readDockerfilesArrayArg[1].version).to.equal('sometag1'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | tap.test('should sort an array of Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   return npmci.Dockerfile | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     .sortDockerfiles(sortableArray) | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |     .then(async (sortedArrayArg: npmci.Dockerfile[]) => { | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |       console.log(sortedArrayArg); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | tap.test('should build all Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   return npmciInstance.dockerManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['docker', 'build'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-11-15 00:18:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | tap.test('should test all Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   return npmciInstance.dockerManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['docker', 'test'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | tap.test('should test dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   return npmciInstance.dockerManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['docker', 'test'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-28 02:24:06 +02:00
										 |  |  | tap.test('should login docker daemon', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   return npmciInstance.dockerManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['docker', 'login'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // ===
 | 
					
						
							|  |  |  | // SSH
 | 
					
						
							|  |  |  | // ===
 | 
					
						
							|  |  |  | tap.test('should prepare SSH keys', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciModSsh = await import('../ts/mod_ssh'); | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |   return await npmciModSsh.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['ssh', 'prepare'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // ====
 | 
					
						
							|  |  |  | // node
 | 
					
						
							|  |  |  | // ====
 | 
					
						
							|  |  |  | tap.test('should install a certain version of node', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   const npmciInstance = new npmci.Npmci(); | 
					
						
							|  |  |  |   await npmciInstance.nodejsManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['node', 'install', 'stable'] | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   await npmciInstance.nodejsManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['node', 'install', 'lts'] | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-08-29 20:26:23 +02:00
										 |  |  |   await npmciInstance.nodejsManager.handleCli({ | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     _: ['node', 'install', 'legacy'] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // make sure test ends all right
 | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | tap.test('reset paths', async () => { | 
					
						
							|  |  |  |   process.cwd = () => { | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  |     return path.join(__dirname, '../'); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:25:13 +02:00
										 |  |  | tap.start(); |