From 2ecdf1626f0f97f473440a769ababea4705a8c1c Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Mon, 29 Feb 2016 11:24:48 +0100 Subject: [PATCH 1/3] Add possibility to jslint individual js files. --- utils/jslint.sh | 78 ++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/utils/jslint.sh b/utils/jslint.sh index 0ba14aeb9d..bc220363e3 100755 --- a/utils/jslint.sh +++ b/utils/jslint.sh @@ -1,42 +1,46 @@ #!/bin/bash -JAVASCRIPT_JSLINT="\ - `find ./js/actions -name "*.js"` \ - `find ./js/common/bootstrap -name "*.js"` \ - `find ./js/client/bootstrap -name "*.js"` \ - `find ./js/server/bootstrap -name "*.js"` \ - \ - `find ./js/common/modules/@arangodb -name "*.js"` \ - `find ./js/client/modules/@arangodb -name "*.js"` \ - `find ./js/server/modules/@arangodb -name "*.js"` \ - `find ./js/server/tests -name "*.js" | grep -v "ranges-combined"` \ - `find ./js/common/tests -name "*.js"` \ - `find ./js/client/tests -name "*.js"` \ - \ - `find ./js/apps/system/_system/cerberus/APP -name "*.js"` \ - `find ./js/apps/system/_api/gharial/APP -name "*.js"` \ - `find ./js/apps/system/_system/sessions/APP -name "*.js"` \ - `find ./js/apps/system/_system/simple-auth/APP -name "*.js"` \ - `find ./js/apps/system/_system/users/APP -name "*.js"` \ - \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/models -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/views -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/collections -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/routers -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/arango -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/frontend/js/shell -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/test/specs -name "*.js"` \ - `find ./js/apps/system/_admin/aardvark/APP/test/clusterSpecs -name "*.js"` \ - \ - `find ./scripts -name "*.js"` \ - \ - ./js/common/modules/jsunity.js \ - ./js/client/client.js \ - ./js/server/server.js \ - ./js/server/upgrade-database.js \ - \ - ./js/apps/system/_admin/aardvark/APP/frontend/js/shell/browser.js \ -" +if [ "x$@" == "x" ] ; then + JAVASCRIPT_JSLINT="\ + `find ./js/actions -name "*.js"` \ + `find ./js/common/bootstrap -name "*.js"` \ + `find ./js/client/bootstrap -name "*.js"` \ + `find ./js/server/bootstrap -name "*.js"` \ + \ + `find ./js/common/modules/@arangodb -name "*.js"` \ + `find ./js/client/modules/@arangodb -name "*.js"` \ + `find ./js/server/modules/@arangodb -name "*.js"` \ + `find ./js/server/tests -name "*.js" | grep -v "ranges-combined"` \ + `find ./js/common/tests -name "*.js"` \ + `find ./js/client/tests -name "*.js"` \ + \ + `find ./js/apps/system/_system/cerberus/APP -name "*.js"` \ + `find ./js/apps/system/_api/gharial/APP -name "*.js"` \ + `find ./js/apps/system/_system/sessions/APP -name "*.js"` \ + `find ./js/apps/system/_system/simple-auth/APP -name "*.js"` \ + `find ./js/apps/system/_system/users/APP -name "*.js"` \ + \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/models -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/views -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/collections -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/routers -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/arango -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/shell -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/test/specs -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/test/clusterSpecs -name "*.js"` \ + \ + `find ./scripts -name "*.js"` \ + \ + ./js/common/modules/jsunity.js \ + ./js/client/client.js \ + ./js/server/server.js \ + ./js/server/upgrade-database.js \ + \ + ./js/apps/system/_admin/aardvark/APP/frontend/js/shell/browser.js \ + " +else + JAVASCRIPT_JSLINT="$@" +fi FILELIST="" From f1f53079d4fb9ee01e76af0671b26e097a6aacca Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Mon, 29 Feb 2016 11:25:23 +0100 Subject: [PATCH 2/3] Start writing actual tests. --- js/client/tests/agency/agency-test.js | 51 ++++++++++++++++++--------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/js/client/tests/agency/agency-test.js b/js/client/tests/agency/agency-test.js index 2158c2fc79..956bdf691a 100644 --- a/js/client/tests/agency/agency-test.js +++ b/js/client/tests/agency/agency-test.js @@ -1,5 +1,5 @@ /*jshint globalstrict:false, strict:true */ -/*global assertEqual, assertNotEqual, ARGUMENTS */ +/*global assertEqual, ARGUMENTS */ //////////////////////////////////////////////////////////////////////////////// /// @brief tests for client-specific functionality @@ -29,7 +29,6 @@ //////////////////////////////////////////////////////////////////////////////// var jsunity = require("jsunity"); -var console = require("console"); //////////////////////////////////////////////////////////////////////////////// /// @brief test suite @@ -45,16 +44,37 @@ function agencyTestSuite () { var agencyServers = ARGUMENTS; var whoseTurn = 0; // used to do round robin on agencyServers - let request = require("@arangodb/request"); + var request = require("@arangodb/request"); function readAgency(list) { // We simply try all agency servers in turn until one gives us an HTTP // response: - while (true) { - var res = request({url: agencyServers[whoseTurn], method: "POST", - followRedirects: true, body: JSON.stringify(list)}); - console.log(res); - } + var res = request({url: agencyServers[whoseTurn] + "/read", method: "POST", + followRedirects: true, body: JSON.stringify(list), + headers: {"Content-Type": "application/json"}}); + res.bodyParsed = JSON.parse(res.body); + return res; + } + + function writeAgency(list) { + // We simply try all agency servers in turn until one gives us an HTTP + // response: + var res = request({url: agencyServers[whoseTurn] + "/write", method: "POST", + followRedirects: true, body: JSON.stringify(list), + headers: {"Content-Type": "application/json"}}); + res.bodyParsed = JSON.parse(res.body); + return res; + } + + function readAndCheck(list) { + var res = readAgency(list); + assertEqual(res.statusCode, 200); + return res.bodyParsed; + } + + function writeAndCheck(list) { + var res = writeAgency(list); + assertEqual(res.statusCode, 200); } return { @@ -75,16 +95,15 @@ function agencyTestSuite () { }, //////////////////////////////////////////////////////////////////////////////// -/// @brief test global help function +/// @brief test to write a single top level key //////////////////////////////////////////////////////////////////////////////// - testWait : function () { - require("internal").print("Hallo1", agencyServers); - require("internal").wait(5); - require("internal").print("Hallo1"); - readAgency(); - assertEqual(1, 1); - assertNotEqual(1, 2); + testSingleTopLevel : function () { + assertEqual(readAndCheck([["x"]]), [{}]); + writeAndCheck([[{x:12}]]); + assertEqual(readAndCheck([["x"]]), [{x:12}]); + writeAndCheck([[{x:{"op":"delete"}}]]); + assertEqual(readAndCheck([["x"]]), [{}]); } }; From c2d3352b94363ce1424f584460cf9d54e0d2251d Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Mon, 29 Feb 2016 11:41:47 +0100 Subject: [PATCH 3/3] Add first few tests. --- js/client/tests/agency/agency-test.js | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/js/client/tests/agency/agency-test.js b/js/client/tests/agency/agency-test.js index 956bdf691a..33b848a274 100644 --- a/js/client/tests/agency/agency-test.js +++ b/js/client/tests/agency/agency-test.js @@ -104,6 +104,35 @@ function agencyTestSuite () { assertEqual(readAndCheck([["x"]]), [{x:12}]); writeAndCheck([[{x:{"op":"delete"}}]]); assertEqual(readAndCheck([["x"]]), [{}]); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test to write a single non-top level key +//////////////////////////////////////////////////////////////////////////////// + + testSingleNonTopLevel : function () { + assertEqual(readAndCheck([["x/y"]]), [{}]); + writeAndCheck([[{"x/y":12}]]); + assertEqual(readAndCheck([["x/y"]]), [{x:{y:12}}]); + writeAndCheck([[{"x/y":{"op":"delete"}}]]); + assertEqual(readAndCheck([["x"]]), [{x:{}}]); + writeAndCheck([[{"x":{"op":"delete"}}]]); + assertEqual(readAndCheck([["x"]]), [{}]); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test a precondition +//////////////////////////////////////////////////////////////////////////////// + + testPrecondition : function () { + writeAndCheck([[{"a":12}]]); + assertEqual(readAndCheck([["a"]]), [{a:12}]); + writeAndCheck([[{"a":13},{"a":12}]]); + assertEqual(readAndCheck([["a"]]), [{a:13}]); + var res = writeAgency([[{"a":14},{"a":12}]]); + assertEqual(res.statusCode, 412); + assertEqual(res.bodyParsed, {error:true, successes:[]}); + writeAndCheck([[{a:{op:"delete"}}]]); } };