From a67341b1b02e5b37ff6edc055a5d5eb6f7fceba3 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 5 Oct 2015 07:31:45 -0700 Subject: [PATCH] 'make test' now runs unit and integration tests. 'make test-unit' just the unit tests (pre-commit updated to just the latter Fix one typo in destructiveAllowed. --- Makefile | 5 ++++- README.md | 36 ++++++++++++++++++++++++++++++++++-- test/integration/helpers.js | 23 ++++++++++++++++------- tools/pre-commit.sh | 2 +- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ad86a8d..bf07b95 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,10 @@ all: npm install .PHONY: test -test: +test: test-unit test-integration + +.PHONY: test-unit +test-unit: NODE_NDEBUG= ./node_modules/.bin/tape test/unit/*.test.js .PHONY: test-integration diff --git a/README.md b/README.md index f51ed8e..416069b 100644 --- a/README.md +++ b/README.md @@ -252,16 +252,48 @@ differences and backward incompatibilities are discussed here. ## Development Hooks -Before commiting be sure to: +Before commiting be sure to, at least: make check # lint and style checks - make test # run unit tests + make test-unit # run unit tests A good way to do that is to install the stock pre-commit hook in your clone via: make git-hooks +Also please run the full (longer) test suite (`make test`). See the next +section. + + +## Test suite + +node-triton has both unit tests (`make test-unit`) and integration tests (`make +test-integration`). Integration tests require either: + +1. environment variables like: + + TRITON_TEST_PROFILE= + TRITON_TEST_DESTRUCTIVE_ALLOWED=1 # Optional + +2. or, a "./test/config.json" like this: + + { + "url": "", + "account": "", + "keyId": "", + "insecure": true|false, // optional + "destructiveAllowed": true|false // optional + } + +For example, a possible run could be: + + TRITON_TEST_PROFILE=coal TRITON_TEST_DESTRUCTIVE_ALLOWED=1 make test + +Where "coal" here refers to a development Triton (a.k.a SDC) ["Cloud On A +Laptop"](https://github.com/joyent/sdc#getting-started). + + ## License MPL 2.0 diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 85de69c..b590c16 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -17,8 +17,8 @@ var assert = require('assert-plus'); var f = require('util').format; var path = require('path'); +var common = require('../../lib/common'); var mod_config = require('../../lib/config'); - var testcommon = require('../lib/testcommon'); @@ -30,7 +30,8 @@ if (process.env.TRITON_TEST_PROFILE) { configDir: path.join(process.env.HOME, '.triton'), name: process.env.TRITON_TEST_PROFILE }); - CONFIG.destructiveAllowed = !!process.env.TRITON_TEST_DESTRUCTIVE_ALLOWED; + CONFIG.destructiveAllowed = common.boolFromString( + process.env.TRITON_TEST_DESTRUCTIVE_ALLOWED); } else { try { CONFIG = require('../config.json'); @@ -40,12 +41,18 @@ if (process.env.TRITON_TEST_PROFILE) { assert.string(CONFIG.keyId, 'test/config.json#keyId'); assert.optionalBool(CONFIG.insecure, 'test/config.json#insecure'); - assert.optionalBool(CONFIG.destrectiveAllowed, + assert.optionalBool(CONFIG.destructiveAllowed, '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('node-triton integration tests require either:'); + error(''); + error('1. environment variables like:'); + error(''); + error(' TRITON_TEST_PROFILE='); + error(' TRITON_TEST_DESTRUCTIVE_ALLOWED=1 # Optional'); + error(''); + error('2. or, a "./test/config.json" like this:'); error(''); error(' {'); error(' "url": "",'); @@ -55,8 +62,10 @@ if (process.env.TRITON_TEST_PROFILE) { 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('Note: This test suite will create machines, images, etc. '); + error('using this CloudAPI and account. While it will do its best'); + error('to clean up all resources, running the test suite against'); + error('a public cloud could *cost* you money. :)'); error('* * *'); throw e; } diff --git a/tools/pre-commit.sh b/tools/pre-commit.sh index 48f2d61..15b4806 100755 --- a/tools/pre-commit.sh +++ b/tools/pre-commit.sh @@ -19,4 +19,4 @@ set -o errexit set -o pipefail make check -make test +make test-unit