From 3ba8f312f1a709977d369d339a9c0b849720f24d Mon Sep 17 00:00:00 2001 From: Dave Eddy Date: Thu, 1 Oct 2015 12:27:05 -0400 Subject: [PATCH] add TRITON_TEST_PROFILE and TRITON_TEST_DESTRUCTIVE_ALLOWED --- test/integration/helpers.js | 70 ++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/test/integration/helpers.js b/test/integration/helpers.js index db12766..3411749 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -17,40 +17,54 @@ var assert = require('assert-plus'); var f = require('util').format; var path = require('path'); -var testcommon = require('../lib/testcommon'); +var mod_config = require('../../lib/config'); +var testcommon = require('../lib/testcommon'); // --- globals -try { - var CONFIG = require('../config.json'); - assert.object(CONFIG, 'test/config.json'); - assert.string(CONFIG.url, 'test/config.json#url'); - assert.string(CONFIG.account, 'test/config.json#account'); - assert.string(CONFIG.keyId, 'test/config.json#keyId'); - if (CONFIG.insecure === undefined) - CONFIG.insecure = false; - if (CONFIG.destructiveAllowed === undefined) - CONFIG.destructiveAllowed = false; - assert.bool(CONFIG.insecure, 'test/config.json#destructiveAllowed'); -} catch (e) { - error('* * *'); - error('node-triton integration tests require a ./test/config.json'); - error(''); - error(' {'); - error(' "url": "",'); - error(' "account": "",'); - error(' "keyId": "",'); - error(' "insecure": true|false, // optional'); - error(' "destructiveAllowed": true|false // optional'); - error(' }'); - error(''); - error('Note: This test suite with create machines, images, et al using'); - error('this CloudAPI and account. That could *cost* you money. :)'); - error('* * *'); - throw e; +var CONFIG; +if (process.env.TRITON_TEST_PROFILE) { + CONFIG = mod_config.loadProfile({ + configDir: path.join(process.env.HOME, '.triton'), + name: process.env.TRITON_TEST_PROFILE + }); + CONFIG.destructiveAllowed = !!process.env.TRITON_TEST_DESTRUCTIVE_ALLOWED; +} else { + CONFIG = require('../config.json'); + try { + assert.object(CONFIG, 'test/config.json'); + assert.string(CONFIG.url, 'test/config.json#url'); + assert.string(CONFIG.account, 'test/config.json#account'); + assert.string(CONFIG.keyId, 'test/config.json#keyId'); + assert.optionalBool(CONFIG.insecure, + 'test/config.json#insecure'); + assert.optionalBool(CONFIG.destrectiveAllowed, + 'test/config.json#destructiveAllowed'); + } catch (e) { + error('* * *'); + error('node-triton integration tests require a ./test/config.json'); + error('or TRITON_TEST_PROFILE to be set to a profile'); + error(''); + error(' {'); + error(' "url": "",'); + error(' "account": "",'); + error(' "keyId": "",'); + error(' "insecure": true|false, // optional'); + error(' "destructiveAllowed": true|false // optional'); + error(' }'); + error(''); + error('Note: This test suite with create machines, images, etc. using'); + error('this CloudAPI and account. That could *cost* you money. :)'); + error('* * *'); + throw e; + } } +if (CONFIG.insecure === undefined) + CONFIG.insecure = false; +if (CONFIG.destructiveAllowed === undefined) + CONFIG.destructiveAllowed = false; var TRITON = [process.execPath, path.resolve(__dirname, '../../bin/triton')]; var UA = 'node-triton-test';