| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  | /* | 
					
						
							|  |  |  |  * This Source Code Form is subject to the terms of the Mozilla Public | 
					
						
							|  |  |  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
					
						
							|  |  |  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Copyright (c) 2015, Joyent, Inc. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Test subcommands existence and usage | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var f = require('util').format; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var h = require('./helpers'); | 
					
						
							|  |  |  | var test = require('tape'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var common = require('../../lib/common'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var subs = [ | 
					
						
							|  |  |  |     ['info'], | 
					
						
							| 
									
										
										
										
											2015-09-25 14:16:16 -07:00
										 |  |  |     ['profile'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['profile list', 'profile ls', 'profiles'], | 
					
						
							|  |  |  |     ['profile get'], | 
					
						
							|  |  |  |     ['profile set-current'], | 
					
						
							|  |  |  |     ['profile create'], | 
					
						
							|  |  |  |     ['profile edit'], | 
					
						
							|  |  |  |     ['profile delete', 'profile rm'], | 
					
						
							| 
									
										
										
										
											2016-04-22 12:55:32 -07:00
										 |  |  |     ['env'], | 
					
						
							|  |  |  |     ['completion'], | 
					
						
							| 
									
										
										
										
											2016-01-04 22:57:24 -08:00
										 |  |  |     ['account'], | 
					
						
							|  |  |  |     ['account get'], | 
					
						
							| 
									
										
										
										
											2016-01-14 22:56:38 -08:00
										 |  |  |     ['account update'], | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |     ['services'], | 
					
						
							|  |  |  |     ['datacenters'], | 
					
						
							|  |  |  |     ['instance', 'inst'], | 
					
						
							| 
									
										
										
										
											2016-01-04 10:45:13 -08:00
										 |  |  |     ['instance list', 'instance ls', 'instances', 'insts', 'ls'], | 
					
						
							|  |  |  |     ['instance get'], | 
					
						
							|  |  |  |     ['instance create', 'create'], | 
					
						
							| 
									
										
										
										
											2016-01-04 13:08:16 -08:00
										 |  |  |     ['instance start', 'start'], | 
					
						
							|  |  |  |     ['instance stop', 'stop'], | 
					
						
							|  |  |  |     ['instance reboot', 'reboot'], | 
					
						
							|  |  |  |     ['instance delete', 'instance rm', 'delete', 'rm'], | 
					
						
							| 
									
										
										
										
											2016-03-12 01:07:11 +11:00
										 |  |  |     ['instance enable-firewall'], | 
					
						
							|  |  |  |     ['instance disable-firewall'], | 
					
						
							| 
									
										
										
										
											2016-11-01 13:54:07 +09:00
										 |  |  |     ['instance rename'], | 
					
						
							| 
									
										
										
										
											2016-03-11 15:21:19 -08:00
										 |  |  |     ['instance ssh'], | 
					
						
							|  |  |  |     ['instance ip'], | 
					
						
							| 
									
										
										
										
											2016-01-04 13:08:16 -08:00
										 |  |  |     ['instance wait'], | 
					
						
							| 
									
										
										
										
											2016-01-04 10:45:13 -08:00
										 |  |  |     ['instance audit'], | 
					
						
							| 
									
										
										
										
											2016-02-05 00:39:50 +11:00
										 |  |  |     ['instance fwrules'], | 
					
						
							|  |  |  |     ['instance snapshot'], | 
					
						
							|  |  |  |     ['instance snapshot create'], | 
					
						
							|  |  |  |     ['instance snapshot list', 'instance snapshot ls', 'instance snapshots'], | 
					
						
							|  |  |  |     ['instance snapshot get'], | 
					
						
							|  |  |  |     ['instance snapshot delete', 'instance snapshot rm'], | 
					
						
							| 
									
										
										
										
											2016-03-11 15:21:19 -08:00
										 |  |  |     ['ip'], | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |     ['ssh'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['network'], | 
					
						
							| 
									
										
										
										
											2016-01-04 21:53:52 -08:00
										 |  |  |     ['network list', 'networks'], | 
					
						
							|  |  |  |     ['network get'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['key'], | 
					
						
							|  |  |  |     ['key add'], | 
					
						
							|  |  |  |     ['key list', 'key ls', 'keys'], | 
					
						
							|  |  |  |     ['key get'], | 
					
						
							|  |  |  |     ['key delete', 'key rm'], | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |     ['image', 'img'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['image get'], | 
					
						
							|  |  |  |     ['image list', 'images', 'imgs'], | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |     ['package', 'pkg'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['package get'], | 
					
						
							|  |  |  |     ['package list', 'packages', 'pkgs'], | 
					
						
							| 
									
										
										
										
											2016-12-21 13:22:23 +09:00
										 |  |  |     ['fwrules'], | 
					
						
							| 
									
										
										
										
											2016-02-05 00:39:50 +11:00
										 |  |  |     ['fwrule'], | 
					
						
							|  |  |  |     ['fwrule create'], | 
					
						
							|  |  |  |     ['fwrule list', 'fwrule ls'], | 
					
						
							|  |  |  |     ['fwrule get'], | 
					
						
							|  |  |  |     ['fwrule update'], | 
					
						
							|  |  |  |     ['fwrule delete', 'fwrule rm'], | 
					
						
							|  |  |  |     ['fwrule enable'], | 
					
						
							|  |  |  |     ['fwrule disable'], | 
					
						
							|  |  |  |     ['fwrule instances', 'fwrule insts'], | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |     ['rbac'], | 
					
						
							|  |  |  |     ['rbac info'], | 
					
						
							|  |  |  |     ['rbac apply'], | 
					
						
							|  |  |  |     ['rbac users'], | 
					
						
							|  |  |  |     ['rbac user'], | 
					
						
							|  |  |  |     ['rbac keys'], | 
					
						
							|  |  |  |     ['rbac key'], | 
					
						
							|  |  |  |     ['rbac policies'], | 
					
						
							|  |  |  |     ['rbac policy'], | 
					
						
							|  |  |  |     ['rbac roles'], | 
					
						
							|  |  |  |     ['rbac role'], | 
					
						
							|  |  |  |     ['rbac instance-role-tags'], | 
					
						
							|  |  |  |     ['rbac image-role-tags'], | 
					
						
							|  |  |  |     ['rbac network-role-tags'], | 
					
						
							|  |  |  |     ['rbac package-role-tags'], | 
					
						
							| 
									
										
										
										
											2017-02-21 15:42:07 -08:00
										 |  |  |     ['rbac role-tags'], | 
					
						
							|  |  |  |     ['volume', 'vol'], | 
					
						
							|  |  |  |     ['volume list', 'volume ls', 'volumes', 'vols'], | 
					
						
							|  |  |  |     ['volume delete', 'volume rm'], | 
					
						
							|  |  |  |     ['volume create'], | 
					
						
							|  |  |  |     ['volume get'] | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --- Tests
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('triton subcommands', function (ttt) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // loop each sub command group
 | 
					
						
							|  |  |  |     subs.forEach(function (subcmds) { | 
					
						
							|  |  |  |         ttt.test(f('  [%s]', subcmds), function (tt) { | 
					
						
							|  |  |  |             var out = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // loop each individual subcommand to test
 | 
					
						
							|  |  |  |             // triton help <subcmd>
 | 
					
						
							|  |  |  |             // triton <subcmd> -h
 | 
					
						
							|  |  |  |             subcmds.forEach(function (subcmd) { | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |                 var helpArgs = subcmd.split(' '); | 
					
						
							|  |  |  |                 helpArgs.splice(helpArgs.length - 1, 0, 'help'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 tt.test(f('    triton %s', helpArgs.join(' ')), function (t) { | 
					
						
							|  |  |  |                     h.triton(helpArgs, function (err, stdout, stderr) { | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |                         if (h.ifErr(t, err, 'no error')) | 
					
						
							|  |  |  |                             return t.end(); | 
					
						
							|  |  |  |                         t.equal(stderr, '', 'stderr produced'); | 
					
						
							|  |  |  |                         t.notEqual(stdout, '', 'stdout empty'); | 
					
						
							|  |  |  |                         out.push(stdout); | 
					
						
							|  |  |  |                         t.end(); | 
					
						
							|  |  |  |                     }); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 13:43:46 +11:00
										 |  |  |                 var flagArgs = subcmd.split(' ').concat('-h'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 tt.test(f('    triton %s', flagArgs.join(' ')), function (t) { | 
					
						
							|  |  |  |                     h.triton(flagArgs, function (err, stdout, stderr) { | 
					
						
							| 
									
										
										
										
											2015-09-22 13:55:42 -04:00
										 |  |  |                         if (h.ifErr(t, err, 'no error')) | 
					
						
							|  |  |  |                             return t.end(); | 
					
						
							|  |  |  |                         t.equal(stderr, '', 'stderr produced'); | 
					
						
							|  |  |  |                         t.notEqual(stdout, '', 'stdout empty'); | 
					
						
							|  |  |  |                         out.push(stdout); | 
					
						
							|  |  |  |                         t.end(); | 
					
						
							|  |  |  |                     }); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // ensure all stdout output is the same
 | 
					
						
							|  |  |  |             out.forEach(function (stdout) { | 
					
						
							|  |  |  |                 tt.equal(stdout, out[0], 'stdout mismatch'); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             tt.end(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ttt.end(); | 
					
						
							|  |  |  | }); |