From 0e05b0f0a155b58b9f74a261f3bf51b71a797cc0 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 29 Jul 2014 23:04:54 -0700 Subject: [PATCH] updated tests to be compatible with the limited api version available in the browser_client, and updated grunt-saucelabs --- package.json | 64 +++++++++--------- test/browser_unit_tests.html | 31 ++++++++- test/integration/yaml_suite/yaml_doc.js | 89 ++++++++++++++++++------- test/unit/specs/client.js | 8 +-- 4 files changed, 128 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 55d2def60..50f5dca89 100644 --- a/package.json +++ b/package.json @@ -33,41 +33,41 @@ "default_api_branch": "1.3" }, "devDependencies": { - "mocha": "^1.21", - "async": "~0.8.0", - "moment": "~2.4.0", - "js-yaml": "~2.1.3", - "optimist": "~0.6.0", - "browserify": "~2.35.1", - "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.7.1", - "grunt-browserify": "~1.2.11", - "grunt-contrib-clean": "~0.5.0", - "grunt-contrib-uglify": "~0.2.7", - "grunt-contrib-concat": "~0.3.0", - "xmlbuilder": "~0.4.3", - "grunt-contrib-watch": "~0.5.3", - "mocha-lcov-reporter": "0.0.1", - "blanket": "~1.1.5", - "sinon": "~1.7.3", - "nock": "~0.28.1", - "open": "0.0.4", - "load-grunt-tasks": "~0.2.0", - "load-grunt-config": "~0.7.0", - "grunt-s3": "~0.2.0-alpha.3", - "grunt-run": "~0.2.2", - "grunt-contrib-compress": "~0.5.3", - "grunt-contrib-copy": "~0.4.1", - "grunt-prompt": "~0.1.2", - "grunt-mocha-cov": "~0.2.0", - "grunt-open": "~0.2.2", - "glob": "~3.2.7", - "expect.js": "~0.2.0", "aliasify": "~1.2.4", + "async": "~0.8.0", + "blanket": "~1.1.5", + "browserify": "~2.35.1", + "event-stream": "~3.1.0", + "expect.js": "~0.2.0", "express": "~3.4.7", "find-root": "~0.1.1", - "event-stream": "~3.1.0", - "grunt-saucelabs": "~5.1.0" + "glob": "~3.2.7", + "grunt": "~0.4.1", + "grunt-browserify": "~1.2.11", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-compress": "~0.5.3", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-copy": "~0.4.1", + "grunt-contrib-jshint": "~0.7.1", + "grunt-contrib-uglify": "~0.2.7", + "grunt-contrib-watch": "~0.5.3", + "grunt-mocha-cov": "~0.2.0", + "grunt-open": "~0.2.2", + "grunt-prompt": "~0.1.2", + "grunt-run": "~0.2.2", + "grunt-s3": "~0.2.0-alpha.3", + "grunt-saucelabs": "~8.2.0", + "js-yaml": "~2.1.3", + "load-grunt-config": "~0.7.0", + "load-grunt-tasks": "~0.2.0", + "mocha": "^1.21", + "mocha-lcov-reporter": "0.0.1", + "moment": "~2.4.0", + "nock": "~0.28.1", + "open": "0.0.4", + "optimist": "~0.6.0", + "sinon": "~1.7.3", + "xmlbuilder": "~0.4.3" }, "license": "Apache 2.0", "dependencies": { diff --git a/test/browser_unit_tests.html b/test/browser_unit_tests.html index 882967fb1..7a0f5871e 100644 --- a/test/browser_unit_tests.html +++ b/test/browser_unit_tests.html @@ -17,9 +17,34 @@ \ No newline at end of file diff --git a/test/integration/yaml_suite/yaml_doc.js b/test/integration/yaml_suite/yaml_doc.js index 15282c11d..05e929051 100644 --- a/test/integration/yaml_suite/yaml_doc.js +++ b/test/integration/yaml_suite/yaml_doc.js @@ -23,6 +23,13 @@ var ES_VERSION = null; // core expression for finding a version var versionExp = '([\\d\\.]*\\d)(?:\\.\\w+)?'; +// match all whitespace within a "regexp" match arg +var reWhitespace_RE = /\s+/g; + +// match all comments within a "regexp" match arg +var reComments_RE = /([\S\s]?)#[^\n]*\n/g; + + /** * Regular Expression to extract a version number from a string * @type {RegExp} @@ -468,36 +475,68 @@ YamlDoc.prototype = { }, /** - * Test that the response field (arg key) matches the value specified + * Test that the response field (arg key) matches the value specified. + * + * @param {Object} args - Args can be specified in a number of formats: + * + * object{ : } + * - used to match simple values against properties of the last response body + * - keys are "paths" to values in the previous response + * - values are what they should match + * example: + * resp: + * { + * hits: { + * total: 100, + * hits: [ ... ] + * } + * } + * args: + * { + * "hits.total": 100, + * } + * + * + * object{ : } + * - regexp is expressed as a string that starts and ends with a / + * - we have to make several replacements on the string before converting + * it into a regexp because javascript doesn't support the "verbose" mode + * they are written for. * - * @param {Object} args - Hash of fields->values that need to be checked * @return {undefined} */ do_match: function (args) { + var self = this; + + // recursively replace all $var within args + _.forOwn(args, function recurse(val, key, lvl) { + if (_.isObject(val)) { + return _.each(val, recurse); + } + + if (_.isString(val) && val[0] === '$') { + lvl[key] = self.get(val); + } + }); + _.forOwn(args, function (match, path) { - var matchPastRef = _.isString(match) && match[0] === '$'; - if (matchPastRef) { - // we are trying to match against a value stored in the stack - match = this.get(match); - } + var origMatch = match; - if (_.isObject(match)) { - var self = this; - // we need to check all sub values for $var - _.each(match, function recurse(val, key, lvl) { - if (_.isObject(val)) { - return _.each(val, recurse); - } - - if (_.isString(val) && val[0] === '$') { - lvl[key] = self.get(val); - } - }); - } - - var notRE = match; - var maybeRE = _.isString(match) && match.replace(/#[^\n]*\n/g, '\n').replace(/\s+/g, ''); + var maybeRE = false; var usedRE = false; + + if (_.isString(match)) { + maybeRE = match + .replace(reComments_RE, function (match, prevChar) { + if (prevChar === '\\') { + return match; + } else { + return prevChar + '\n'; + } + }) + .replace(reWhitespace_RE, ''); + } + if (maybeRE && maybeRE[0] === '/' && maybeRE[maybeRE.length - 1] === '/') { usedRE = true; // replace anymore than one space with a single space @@ -521,8 +560,8 @@ YamlDoc.prototype = { inspect(path), 'and value', inspect(val), - 'and original RE', - '|' + notRE, + 'and original matcher', + '|' + origMatch, '' ]; throw new Error(msg.slice(0, usedRE ? void 0 : -3).join('\n')); diff --git a/test/unit/specs/client.js b/test/unit/specs/client.js index 57cdbba65..2e9aa135e 100644 --- a/test/unit/specs/client.js +++ b/test/unit/specs/client.js @@ -27,13 +27,13 @@ describe('Client instances creation', function () { expect(client.nodes.stats).to.be(apis[def].nodes.prototype.stats); }); - it('inherits the 1.0 API when specified', function () { + it('inherits the 1.2 API when specified', function () { client.close(); client = es.Client({ - apiVersion: '1.0' + apiVersion: '1.2' }); - expect(client.bulk).to.be(apis['1.0'].bulk); - expect(client.cluster.nodeStats).to.be(apis['1.0'].cluster.prototype.nodeStats); + expect(client.bulk).to.be(apis['1.2'].bulk); + expect(client.cluster.nodeStats).to.be(apis['1.2'].cluster.prototype.nodeStats); }); it('closing the client causes it\'s transport to be closed', function () {