mirror of https://gitee.com/bigwinds/arangodb
Add a trivial quickie test and a convenience script.
This commit is contained in:
parent
1d8c7e4515
commit
b5c87fba33
|
@ -0,0 +1,150 @@
|
|||
/*jshint globalstrict:false, strict:false, sub: true */
|
||||
/*global fail, assertTrue, assertEqual */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief very quick test for basic functionality
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2016-2016 ArangoDB 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 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Max Neunhoeffer
|
||||
/// @author Copyright 2016, ArangoDB GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var jsunity = require("jsunity");
|
||||
var arangodb = require("@arangodb");
|
||||
var ERRORS = arangodb.errors;
|
||||
var db = arangodb.db;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test attributes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function QuickieSuite () {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief quickly create a collection and do some operations:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testACollection: function () {
|
||||
|
||||
try {
|
||||
db._drop("UnitTestCollection");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
// Create a collection:
|
||||
var c = db._create("UnitTestCollection", {numberOfShards:2});
|
||||
|
||||
// Do a bunch of operations:
|
||||
var r = c.insert({"Hallo":12});
|
||||
var d = c.document(r._key);
|
||||
assertEqual(12, d.Hallo);
|
||||
c.replace(r._key, {"Hallo":13});
|
||||
d = c.document(r._key);
|
||||
assertEqual(13, d.Hallo);
|
||||
c.update(r._key, {"Hallo":14});
|
||||
d = c.document(r._key);
|
||||
assertEqual(14, d.Hallo);
|
||||
c.remove(r._key);
|
||||
try {
|
||||
d = c.document(r._key);
|
||||
fail();
|
||||
}
|
||||
catch (e) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, e.errorNum);
|
||||
}
|
||||
|
||||
// Drop the collection again:
|
||||
c.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief quickly create a database and a collection and do some operations:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testADatabase: function () {
|
||||
try {
|
||||
db._dropDatabase("UnitTestDatabase");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
db._createDatabase("UnitTestDatabase");
|
||||
db._useDatabase("UnitTestDatabase");
|
||||
|
||||
// Create a collection:
|
||||
var c = db._create("UnitTestCollection", {numberOfShards:2});
|
||||
|
||||
// Do a bunch of operations:
|
||||
var r = c.insert({"Hallo":12});
|
||||
var d = c.document(r._key);
|
||||
assertEqual(12, d.Hallo);
|
||||
c.replace(r._key, {"Hallo":13});
|
||||
d = c.document(r._key);
|
||||
assertEqual(13, d.Hallo);
|
||||
c.update(r._key, {"Hallo":14});
|
||||
d = c.document(r._key);
|
||||
assertEqual(14, d.Hallo);
|
||||
c.remove(r._key);
|
||||
try {
|
||||
d = c.document(r._key);
|
||||
fail();
|
||||
}
|
||||
catch (e) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, e.errorNum);
|
||||
}
|
||||
|
||||
// Drop the collection again:
|
||||
c.drop();
|
||||
|
||||
// Drop the database again:
|
||||
db._useDatabase("_system");
|
||||
db._dropDatabase("UnitTestDatabase");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(QuickieSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
scripts/unittest shell_server --test js/common/tests/shell/shell-quickie.js
|
||||
scripts/unittest shell_server --test js/common/tests/shell/shell-quickie.js --cluster true
|
||||
scripts/unittest shell_client --test js/common/tests/shell/shell-quickie.js
|
||||
scripts/unittest shell_client --test js/common/tests/shell/shell-quickie.js --cluster true
|
Loading…
Reference in New Issue