mirror of https://gitee.com/bigwinds/arangodb
issue #178: added test cases for arangoimp
This commit is contained in:
parent
601858fb5f
commit
b8f694ec0a
31
Makefile.in
31
Makefile.in
|
@ -5332,7 +5332,8 @@ unittests-brief: \
|
|||
unittests-shell-server-ahuacatl \
|
||||
unittests-http-server \
|
||||
unittests-ssl-server \
|
||||
unittests-shell-client
|
||||
unittests-shell-client \
|
||||
unittests-import
|
||||
|
||||
unittests-verbose:
|
||||
@echo "################################################################################"
|
||||
|
@ -5475,6 +5476,34 @@ unittests-shell-client:
|
|||
################################################################################
|
||||
################################################################################
|
||||
|
||||
.PHONY: unittests-import
|
||||
|
||||
unittests-import:
|
||||
$(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint unix://$(VOCDIR)/arango.sock --server.disable-authentication true" PROTO=unix
|
||||
|
||||
@echo
|
||||
@echo "================================================================================"
|
||||
@echo "<< IMPORT TESTS >>"
|
||||
@echo "================================================================================"
|
||||
@echo
|
||||
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1"
|
||||
for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.json --collection UnitTestsImportJson$$i --create-collection true --type json || test "x$(FORCE)" == "x1"; done
|
||||
for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.csv --collection UnitTestsImportCsv$$i --create-collection true --type csv || test "x$(FORCE)" == "x1"; done
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import.js || test "x$(FORCE)" == "x1"
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1"
|
||||
|
||||
kill `cat $(PIDFILE)`
|
||||
|
||||
while test -f $(PIDFILE); do sleep 1; done
|
||||
@if [ "$(VALGRIND)" != "" ]; then sleep 60; fi
|
||||
|
||||
@rm -rf "$(VOCDIR)"
|
||||
@echo
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
.PHONY: unittests-http-server
|
||||
|
||||
unittests-http-server:
|
||||
|
|
|
@ -33,7 +33,8 @@ unittests-brief: \
|
|||
unittests-shell-server-ahuacatl \
|
||||
unittests-http-server \
|
||||
unittests-ssl-server \
|
||||
unittests-shell-client
|
||||
unittests-shell-client \
|
||||
unittests-import
|
||||
|
||||
unittests-verbose:
|
||||
@echo "################################################################################"
|
||||
|
@ -322,6 +323,35 @@ unittests-shell-client:
|
|||
@rm -rf "$(VOCDIR)"
|
||||
@echo
|
||||
|
||||
################################################################################
|
||||
## IMPORT TESTS
|
||||
################################################################################
|
||||
|
||||
.PHONY: unittests-import
|
||||
|
||||
unittests-import:
|
||||
$(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint unix://$(VOCDIR)/arango.sock --server.disable-authentication true" PROTO=unix
|
||||
|
||||
@echo
|
||||
@echo "================================================================================"
|
||||
@echo "<< IMPORT TESTS >>"
|
||||
@echo "================================================================================"
|
||||
@echo
|
||||
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1"
|
||||
for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.json --collection UnitTestsImportJson$$i --create-collection true --type json || test "x$(FORCE)" == "x1"; done
|
||||
for i in 1 2; do $(VALGRIND) @builddir@/bin/arangoimp --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --file UnitTests/import-$$i.csv --collection UnitTestsImportCsv$$i --create-collection true --type csv || test "x$(FORCE)" == "x1"; done
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import.js || test "x$(FORCE)" == "x1"
|
||||
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --javascript.unit-tests @top_srcdir@/js/server/tests/import-setup.js || test "x$(FORCE)" == "x1"
|
||||
|
||||
kill `cat $(PIDFILE)`
|
||||
|
||||
while test -f $(PIDFILE); do sleep 1; done
|
||||
@if [ "$(VALGRIND)" != "" ]; then sleep 60; fi
|
||||
|
||||
@rm -rf "$(VOCDIR)"
|
||||
@echo
|
||||
|
||||
################################################################################
|
||||
## HTTP SERVER TESTS
|
||||
################################################################################
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
"id","a","b","c","d","e"
|
||||
|
||||
1,"1",1,"1.3",null,-5
|
||||
2,null,"",3.1,-2.5,"ddd "" ' ffd"
|
||||
3,"this","is"
|
||||
4,let's,see,what,happens
|
Can't render this file because it has a wrong number of fields in line 5.
|
|
@ -0,0 +1,12 @@
|
|||
{"id": 1, "one":1, "two": 2, "three": 3}
|
||||
{"id": 2, "a" : 1234, "b": "the quick fox", "jumped": "over the fox", "null": null }
|
||||
|
||||
|
||||
{"id": 3, "spacing" : "is", "not": "important" }
|
||||
{"id": 4, "a": true, "b": false, " c " : "h\"'ihi", "d" : "" }
|
||||
{"id" : 5 }
|
||||
|
||||
{"id": 6, "this \" should be enough'"}
|
||||
{"id": 7, "a" : 1234, "b": "the quick fox", "jumped: "over the fox", "null": null }
|
||||
|
||||
{"id" : 8, "i am" : broken }
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
1,2,3,4,5,6
|
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
{"id": 1, "value" : -445.4 }
|
||||
|
||||
{"id": 2, "value" : 3.4e4 }
|
||||
|
||||
|
||||
{"id": 3, "value" : null }
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief setup stuff for import tests
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var internal = require("internal");
|
||||
|
||||
internal.db._drop("UnitTestsImportJson1");
|
||||
internal.db._drop("UnitTestsImportJson2");
|
||||
internal.db._drop("UnitTestsImportCsv1");
|
||||
internal.db._drop("UnitTestsImportCsv2");
|
||||
|
||||
return true;
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
|
@ -0,0 +1,148 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tests for query language, arithmetic operators
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var internal = require("internal");
|
||||
var jsunity = require("jsunity");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function importTestSuite () {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief execute a given query
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function executeQuery (query) {
|
||||
var statement = internal.db._createStatement({"query": query});
|
||||
var cursor = statement.execute();
|
||||
return cursor;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief execute a given query and return the results as an array
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function getQueryResults (query) {
|
||||
var result = executeQuery(query);
|
||||
var results = [ ];
|
||||
|
||||
while (result.hasNext()) {
|
||||
var keys = [ ];
|
||||
var row = result.next();
|
||||
for (var k in row) {
|
||||
if (row.hasOwnProperty(k) && k != '_id' && k != '_rev') {
|
||||
keys.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
keys.sort();
|
||||
var resultRow = { };
|
||||
for (var k in keys) {
|
||||
if (keys.hasOwnProperty(k)) {
|
||||
resultRow[keys[k]] = row[keys[k]];
|
||||
}
|
||||
}
|
||||
|
||||
results.push(resultRow);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test json import
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testJsonImport1 : function () {
|
||||
var expected = [ { "id": 1, "one": 1, "three": 3, "two": 2 }, { "a": 1234, "b": "the quick fox", "id": 2, "jumped": "over the fox", "null": null }, { "id": 3, "not": "important", "spacing": "is" }, { " c ": "h\"'ihi", "a": true, "b": false, "d": "", "id": 4 }, { "id": 5 } ];
|
||||
var actual = getQueryResults("FOR i IN UnitTestsImportJson1 SORT i.id RETURN i");
|
||||
assertEqual(expected, actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test json import
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testJsonImport2 : function () {
|
||||
var expected = [ { "id": 1, "value": -445.4 }, { "id": 2, "value": 34000 }, { "id": 3, "value": null } ];
|
||||
var actual = getQueryResults("FOR i IN UnitTestsImportJson2 SORT i.id RETURN i");
|
||||
assertEqual(expected, actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test csv import
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCsvImport1 : function () {
|
||||
var expected = [ { "a": "1", "b": 1, "c": "1.3", "d": null, "e": -5, "id": 1 }, { "a": null, "b": "", "c": 3.1, "d": -2.5, "e": "ddd \" ' ffd", "id": 2 } ];
|
||||
var actual = getQueryResults("FOR i IN UnitTestsImportCsv1 SORT i.id RETURN i");
|
||||
assertEqual(expected, actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test csv import
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCsvImport2 : function () {
|
||||
var expected = [ ]; // should be empty!
|
||||
var actual = getQueryResults("FOR i IN UnitTestsImportCsv2 SORT i.id RETURN i");
|
||||
assertEqual(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(importTestSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
Loading…
Reference in New Issue