From 4c2feae3f4f8baadbdc989a04bbc026c278b3e8c Mon Sep 17 00:00:00 2001 From: Nathan Weber Date: Thu, 14 Apr 2016 11:35:46 -0500 Subject: [PATCH 1/6] Add ability to ignore names. --- docs/usage.md | 2 ++ src/apply-configuration.coffee | 2 ++ src/options.coffee | 7 ++++++- src/transaction-runner.coffee | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index 879c17229..8b80c62ff 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -44,6 +44,8 @@ Options: [default: false] --only, -x Run only specified transaction name. Can be used multiple times [default: []] + --ignore, -z Exclude specified transaction name. Can + be used multiple times [default: []] --reporter, -r Output additional report format. This option can be used multiple times to add multiple reporters. Options: junit, nyan, diff --git a/src/apply-configuration.coffee b/src/apply-configuration.coffee index e5ed7d07d..421403384 100644 --- a/src/apply-configuration.coffee +++ b/src/apply-configuration.coffee @@ -36,6 +36,7 @@ applyConfiguration = (config) -> details: false method: [] only: [] + ignore: [] color: true level: 'info' timestamp: false @@ -70,6 +71,7 @@ applyConfiguration = (config) -> configuration.options.header = coerceToArray(configuration.options.header) configuration.options.method = coerceToArray(configuration.options.method) configuration.options.only = coerceToArray(configuration.options.only) + configuration.options.ignore = coerceToArray(configuration.options.ignore) configuration.options.path = coerceToArray(configuration.options.path) # support for legacy JS API options diff --git a/src/options.coffee b/src/options.coffee index 265c1bef5..d34b5866f 100644 --- a/src/options.coffee +++ b/src/options.coffee @@ -45,7 +45,12 @@ options = only: alias: "x" - description: "Run only specified transaction name. Can be used multiple times" + description: "Run only specified transaction name. Can be used multiple times." + default: [] + + ignore: + alias: "z" + description: "Skip the specified transaction name. Can be used multiple times." default: [] reporter: diff --git a/src/transaction-runner.coffee b/src/transaction-runner.coffee index 55c669b22..d49bdd001 100644 --- a/src/transaction-runner.coffee +++ b/src/transaction-runner.coffee @@ -461,6 +461,10 @@ class TransactionRunner @configuration.emitter.emit 'test skip', test, () -> transaction.skip = true return callback() + else if @configuration.options.ignore.length > 0 and (transaction.name in @configuration.options.ignore) + @configuration.emitter.emit 'test skip', test, () -> + transaction.skip = true + return callback() else return @performRequestAndValidate(test, transaction, hooks, callback) From 37b62b736aaa1f42b06c271aaae99238fe16773e Mon Sep 17 00:00:00 2001 From: Nathan Weber Date: Thu, 14 Apr 2016 11:41:04 -0500 Subject: [PATCH 2/6] Making this match how it was originally, and bringing ignore doc in line. --- src/options.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/options.coffee b/src/options.coffee index d34b5866f..0eb9e336f 100644 --- a/src/options.coffee +++ b/src/options.coffee @@ -45,12 +45,12 @@ options = only: alias: "x" - description: "Run only specified transaction name. Can be used multiple times." + description: "Run only specified transaction name. Can be used multiple times" default: [] ignore: alias: "z" - description: "Skip the specified transaction name. Can be used multiple times." + description: "Skip the specified transaction name. Can be used multiple times" default: [] reporter: From 5f60137775341a100e744194fcbf643b52cc00a9 Mon Sep 17 00:00:00 2001 From: Nathan Weber Date: Fri, 15 Apr 2016 14:33:07 -0500 Subject: [PATCH 3/6] Change 'ignore' to 'skip'. --- src/apply-configuration.coffee | 4 ++-- src/options.coffee | 2 +- src/transaction-runner.coffee | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apply-configuration.coffee b/src/apply-configuration.coffee index 421403384..0db7ca845 100644 --- a/src/apply-configuration.coffee +++ b/src/apply-configuration.coffee @@ -36,7 +36,7 @@ applyConfiguration = (config) -> details: false method: [] only: [] - ignore: [] + skip: [] color: true level: 'info' timestamp: false @@ -71,7 +71,7 @@ applyConfiguration = (config) -> configuration.options.header = coerceToArray(configuration.options.header) configuration.options.method = coerceToArray(configuration.options.method) configuration.options.only = coerceToArray(configuration.options.only) - configuration.options.ignore = coerceToArray(configuration.options.ignore) + configuration.options.skip = coerceToArray(configuration.options.skip) configuration.options.path = coerceToArray(configuration.options.path) # support for legacy JS API options diff --git a/src/options.coffee b/src/options.coffee index 0eb9e336f..675692a9a 100644 --- a/src/options.coffee +++ b/src/options.coffee @@ -48,7 +48,7 @@ options = description: "Run only specified transaction name. Can be used multiple times" default: [] - ignore: + skip: alias: "z" description: "Skip the specified transaction name. Can be used multiple times" default: [] diff --git a/src/transaction-runner.coffee b/src/transaction-runner.coffee index d49bdd001..a1b0747e5 100644 --- a/src/transaction-runner.coffee +++ b/src/transaction-runner.coffee @@ -461,7 +461,7 @@ class TransactionRunner @configuration.emitter.emit 'test skip', test, () -> transaction.skip = true return callback() - else if @configuration.options.ignore.length > 0 and (transaction.name in @configuration.options.ignore) + else if @configuration.options.skip.length > 0 and (transaction.name in @configuration.options.skip) @configuration.emitter.emit 'test skip', test, () -> transaction.skip = true return callback() From dc6af0d143170a2548ce2aafdf53a299d986dbc5 Mon Sep 17 00:00:00 2001 From: Nathan Weber Date: Fri, 15 Apr 2016 15:53:21 -0500 Subject: [PATCH 4/6] fix tests --- test/unit/config-utils-test.coffee | 2 ++ test/unit/dredd-command-test.coffee | 1 + test/unit/transaction-runner-test.coffee | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/test/unit/config-utils-test.coffee b/test/unit/config-utils-test.coffee index 63be2d14c..d3c6e4aaf 100644 --- a/test/unit/config-utils-test.coffee +++ b/test/unit/config-utils-test.coffee @@ -33,6 +33,7 @@ argvData = names: false n: false only: [] + skip: [] x: [] reporter: [] r: [] @@ -152,6 +153,7 @@ describe 'configUtils', () -> custom: [] names: false only: [] + skip: [] reporter: [] output: [] header: [] diff --git a/test/unit/dredd-command-test.coffee b/test/unit/dredd-command-test.coffee index a3b10e724..baae4dbeb 100644 --- a/test/unit/dredd-command-test.coffee +++ b/test/unit/dredd-command-test.coffee @@ -370,6 +370,7 @@ describe "DreddCommand class", () -> custom: [] names: false only: [] + skip: [] reporter: [] output: [] header: [] diff --git a/test/unit/transaction-runner-test.coffee b/test/unit/transaction-runner-test.coffee index b9f0229b3..54084f422 100644 --- a/test/unit/transaction-runner-test.coffee +++ b/test/unit/transaction-runner-test.coffee @@ -35,6 +35,7 @@ describe 'TransactionRunner', ()-> 'dry-run': false method: [] only: [] + skip: [] header: [] reporter: [] transaction = {} @@ -73,6 +74,7 @@ describe 'TransactionRunner', ()-> 'dry-run': false method: [] only: [] + skip: [] header: [] reporter: [] @@ -91,6 +93,7 @@ describe 'TransactionRunner', ()-> 'dry-run': false method: [] only: [] + skip: [] header: [] reporter: [] runner = new Runner(configuration) @@ -1100,6 +1103,7 @@ describe 'TransactionRunner', ()-> header: [] reporter: [] only: [] + skip: [] # do not actually search & load hookfiles from disk # hookfiles: './**/*_hooks.*' From 9f0629d39fbc72c7fc41289658362719bea418dd Mon Sep 17 00:00:00 2001 From: Nathan Weber Date: Mon, 18 Apr 2016 11:45:42 -0500 Subject: [PATCH 5/6] Add initial tests for skip functionality. --- test/integration/cli/cli-test.coffee | 41 ++++++++++++++++++++++++ test/unit/transaction-runner-test.coffee | 30 +++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/test/integration/cli/cli-test.coffee b/test/integration/cli/cli-test.coffee index 55ba3ba46..b96cc83b4 100644 --- a/test/integration/cli/cli-test.coffee +++ b/test/integration/cli/cli-test.coffee @@ -588,6 +588,47 @@ describe 'CLI', () -> it 'exit status should be 0', () -> assert.equal exitStatus, 0 + describe "when filtering transaction to particular name with -z or --skip", () -> + + machineHit = false + messageHit = false + before (done) -> + cmd = "#{DREDD_BIN} ./test/fixtures/single-get.apib http://localhost:#{PORT} --path=./test/fixtures/multifile/*.apib --skip=\"Message API > /message > GET\" --no-color" + + app = express() + + app.get '/machines', (req, res) -> + machineHit = true + res.setHeader 'Content-Type', 'application/json; charset=utf-8' + machine = + type: 'bulldozer' + name: 'willy' + response = [machine] + res.status(200).send response + + app.get '/message', (req, res) -> + messageHit = true + res.setHeader 'Content-Type', 'text/plain; charset=utf-8' + res.status(200).send "Hello World!\n" + + server = app.listen PORT, () -> + execCommand cmd, () -> + server.close() + + server.on 'close', done + + it 'should not send the request', () -> + assert.isFalse messageHit + + it 'should notify skipping to the stdout', () -> + assert.include stdout, 'skip: GET /message' + + it 'should hit the only transaction', () -> + assert.isTrue machineHit + + it 'exit status should be 0', () -> + assert.equal exitStatus, 0 + describe 'when suppressing color with --no-color', () -> before (done) -> cmd = "#{DREDD_BIN} ./test/fixtures/single-get.apib http://localhost:#{PORT} --no-color" diff --git a/test/unit/transaction-runner-test.coffee b/test/unit/transaction-runner-test.coffee index 54084f422..24b946d4e 100644 --- a/test/unit/transaction-runner-test.coffee +++ b/test/unit/transaction-runner-test.coffee @@ -330,6 +330,36 @@ describe 'TransactionRunner', ()-> assert.ok configuration.emitter.emit.calledWith 'test skip' done() + describe 'when skipping certain names by the configuration', () -> + + beforeEach () -> + server = nock('http://localhost:3000'). + post('/machines', {"type":"bulldozer","name":"willy"}). + reply transaction['expected']['status'], + transaction['expected']['body'], + {'Content-Type': 'application/json'} + + configuration.options['skip'] = ['Group Machine > Machine > Delete Message > Bogus example name'] + sinon.stub configuration.emitter, 'emit' + runner = new Runner(configuration) + + afterEach () -> + configuration.emitter.emit.restore() + configuration.options['skip'] = [] + nock.cleanAll() + + it 'should not skip transactions with different names', (done) -> + runner.executeTransaction transaction, () -> + assert.notOk configuration.emitter.emit.calledWith 'test skip' + done() + + it 'should skip transactions with matching names', (done) -> + transaction['name'] = 'Group Machine > Machine > Delete Message > Bogus different example name' + runner.executeTransaction transaction, () -> + assert.ok configuration.emitter.emit.calledWith 'test skip' + done() + + describe 'when a test has been manually set to skip in a hook', () -> clonedTransaction = null From 521fec0b0c1d5a7cf9ec14742eb70c6caa898b0c Mon Sep 17 00:00:00 2001 From: Jason Rayles Date: Tue, 7 Jun 2016 09:29:45 -0400 Subject: [PATCH 6/6] Allows proxy server configuration --- src/reporters/apiary-reporter.coffee | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/reporters/apiary-reporter.coffee b/src/reporters/apiary-reporter.coffee index d4ce7863c..ff5b3f1ee 100644 --- a/src/reporters/apiary-reporter.coffee +++ b/src/reporters/apiary-reporter.coffee @@ -31,6 +31,9 @@ class ApiaryReporter apiUrl: @_get 'apiaryApiUrl', 'APIARY_API_URL', 'https://api.apiary.io' apiToken: @_get 'apiaryApiKey', 'APIARY_API_KEY', null apiSuite: @_get 'apiaryApiName', 'APIARY_API_NAME', null + proxyHost: @_get 'proxyHost', 'PROXY_HOST', null + proxyPort: @_get 'proxyPort', 'PROXY_PORT', null + proxyProtocol: @_get 'proxyProtocol', 'PROXY_PROTOCOL', null logger.info 'Using apiary reporter.' if not @configuration.apiToken? and not @configuration.apiSuite? @@ -228,16 +231,21 @@ class ApiaryReporter return callback(undefined, res, parsedBody) parsedUrl = url.parse @configuration['apiUrl'] + hostToUse = @configuration['proxyHost'] || parsedUrl['hostname'] + portToUse = @configuration['proxyPort'] || parsedUrl['port'] + protocolToUse = @configuration['proxyProtocol'] || parsedUrl['protocol '] + pathToUse = @configuration['apiUrl'] + path system = os.type() + ' ' + os.release() + '; ' + os.arch() postData = JSON.stringify body options = - host: parsedUrl['hostname'] - port: parsedUrl['port'] - path: path + host: hostToUse + port: portToUse + path: pathToUse method: method headers: + 'Host': parsedUrl['hostname'], 'User-Agent': "Dredd REST Reporter/" + packageConfig['version'] + " (" + system + ")" 'Content-Type': 'application/json' 'Content-Length': Buffer.byteLength(postData, 'utf8') @@ -258,7 +266,7 @@ class ApiaryReporter else return callback error, req, null - if @configuration.apiUrl?.indexOf('https') is 0 + if protocolToUse?.indexOf('https') is 0 if @verbose logger.log 'Starting REST Reporter HTTPS Request' req = https.request options, handleResponse