| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | import { tap, expect } from 'tapbundle' | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | import * as path from 'path' | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | // Setup test
 | 
					
						
							|  |  |  | process.env.NPMTS_TEST = 'true' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | // set up environment
 | 
					
						
							| 
									
										
										
										
											2017-05-15 18:27:13 +02:00
										 |  |  | process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git' | 
					
						
							| 
									
										
										
										
											2017-08-28 01:35:21 +02:00
										 |  |  | process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Docker
 | 
					
						
							|  |  |  | process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // SSH env
 | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01: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 = () => { | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |   return path.join(__dirname, 'assets/') | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // require NPMCI files
 | 
					
						
							| 
									
										
										
										
											2017-08-25 21:07:02 +02:00
										 |  |  | import '../ts/index' | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | import npmciModDocker = require('../ts/mod_docker/index') | 
					
						
							|  |  |  | import npmciModNpm = require('../ts/mod_npm/index') | 
					
						
							|  |  |  | import npmciModNode = require('../ts/mod_node/index') | 
					
						
							|  |  |  | import npmciModSsh = require('../ts/mod_ssh/index') | 
					
						
							|  |  |  | import npmciEnv = require('../ts/npmci.env') | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // ======
 | 
					
						
							|  |  |  | // Docker
 | 
					
						
							|  |  |  | // ======
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let dockerfile1: npmciModDocker.Dockerfile | 
					
						
							|  |  |  | let dockerfile2: npmciModDocker.Dockerfile | 
					
						
							|  |  |  | let sortableArray: npmciModDocker.Dockerfile[] | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | tap.test('should return valid Dockerfiles', async () => { | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |   dockerfile1 = new npmciModDocker.Dockerfile({ filePath: './Dockerfile', read: true }) | 
					
						
							|  |  |  |   dockerfile2 = new npmciModDocker.Dockerfile({ filePath: './Dockerfile_sometag1', read: true }) | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |   expect(dockerfile1.version).to.equal('latest') | 
					
						
							|  |  |  |   return expect(dockerfile2.version).to.equal('sometag1') | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											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 () => { | 
					
						
							| 
									
										
										
										
											2017-08-28 01:03:59 +02:00
										 |  |  |   return npmciModDocker.helpers.readDockerfiles() | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |     .then(async (readDockerfilesArrayArg: npmciModDocker.Dockerfile[]) => { | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |       sortableArray = readDockerfilesArrayArg | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |       return expect(readDockerfilesArrayArg[1].version).to.equal('sometag1') | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											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 () => { | 
					
						
							| 
									
										
										
										
											2017-08-28 01:03:59 +02:00
										 |  |  |   return npmciModDocker.helpers.sortDockerfiles(sortableArray) | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |     .then(async (sortedArrayArg: npmciModDocker.Dockerfile[]) => { | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |       console.log(sortedArrayArg) | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-11-15 00:07:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | tap.test('should build all Dockerfiles', async () => { | 
					
						
							|  |  |  |   return npmciModDocker.handleCli({ | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     _: [ | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |       'docker', | 
					
						
							|  |  |  |       'build' | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-11-15 00:18:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | tap.test('should test all Dockerfiles', async () => { | 
					
						
							|  |  |  |   return await npmciModDocker.handleCli({ | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     _: [ | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |       'docker', | 
					
						
							|  |  |  |       'test' | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tap.test('should test dockerfiles', async () => { | 
					
						
							|  |  |  |   return await npmciModDocker.handleCli({ | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     _: [ | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |       'docker', | 
					
						
							|  |  |  |       'test' | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-28 02:24:06 +02:00
										 |  |  | tap.test('should login docker daemon', async () => { | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |   return await npmciModDocker.handleCli({ | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     _: [ | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |       'docker', | 
					
						
							| 
									
										
										
										
											2017-08-28 02:24:06 +02:00
										 |  |  |       'login' | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  | // ===
 | 
					
						
							|  |  |  | // SSH
 | 
					
						
							|  |  |  | // ===
 | 
					
						
							|  |  |  | tap.test('should prepare SSH keys', async () => { | 
					
						
							|  |  |  |   return await npmciModSsh.handleCli({ | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     _: [ | 
					
						
							| 
									
										
										
										
											2017-08-27 15:24:17 +02:00
										 |  |  |       'ssh', | 
					
						
							|  |  |  |       'prepare' | 
					
						
							| 
									
										
										
										
											2017-07-27 14:20:56 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											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 () => { | 
					
						
							|  |  |  |   await npmciModNode.handleCli({ | 
					
						
							|  |  |  |     _: [ | 
					
						
							|  |  |  |       'node', | 
					
						
							|  |  |  |       'install', | 
					
						
							|  |  |  |       'stable' | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   await npmciModNode.handleCli({ | 
					
						
							|  |  |  |     _: [ | 
					
						
							|  |  |  |       'node', | 
					
						
							|  |  |  |       'install', | 
					
						
							|  |  |  |       'lts' | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   await npmciModNode.handleCli({ | 
					
						
							|  |  |  |     _: [ | 
					
						
							|  |  |  |       'node', | 
					
						
							|  |  |  |       'install', | 
					
						
							|  |  |  |       'legacy' | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											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 = () => { | 
					
						
							|  |  |  |     return path.join(__dirname, '../') | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-05-15 14:19:56 +02:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tap.start() |