1
0
Fork 0

Cherry picked bug-fix for GharialAPI to return name in LIST (#10545)

This commit is contained in:
Michael Hackstein 2019-11-26 15:30:21 +01:00 committed by KVS85
parent a7b64bd815
commit bc752a28c7
3 changed files with 107 additions and 1 deletions

View File

@ -1,6 +1,11 @@
v3.5.3 (XXXX-XX-XX)
-------------------
* Fixed GET _api/gharial to also include the name property in every returned
graph. This is a consistency fix within the API as all other APIs include the
name. As a work around the returned _key can be used, which is identical to
the name.
* The _users collection is now properly restored when using arangorestore.
* Allow the optimizer to use indexes when a collection attribute is compared to

View File

@ -579,7 +579,8 @@ Result GraphManager::ensureCollections(Graph const* graph, bool waitForSync) con
OperationResult GraphManager::readGraphs(velocypack::Builder& builder,
aql::QueryPart const queryPart) const {
std::string const queryStr{"FOR g IN _graphs RETURN g"};
std::string const queryStr{
"FOR g IN _graphs RETURN MERGE(g, {name: g._key})"};
return readGraphByQuery(builder, queryPart, queryStr);
}

View File

@ -26,6 +26,7 @@
// //////////////////////////////////////////////////////////////////////////////
const chai = require('chai');
const Joi = require('joi');
const expect = chai.expect;
chai.Assertion.addProperty('does', function () {
return this;
@ -87,6 +88,28 @@ describe('_api/gharial', () => {
}
};
const validateGraphFormat = (graph) => {
const edgeDefinition = Joi.object({
collection: Joi.string().required(),
from: Joi.array().items(Joi.string()).required(),
to: Joi.array().items(Joi.string()).required()
});
const schema = Joi.object({
"_key": Joi.string().required(),
"_rev": Joi.string().required(),
"_id": Joi.string().required(),
name: Joi.string().required(),
numberOfShards: Joi.number().integer().min(1).required(),
replicationFactor: Joi.number().integer().min(1).required(),
minReplicationFactor: Joi.number().integer().min(1).required(),
isSmart: Joi.boolean().required(),
orphanCollections: Joi.array().items(Joi.string()).required(),
edgeDefinitions: Joi.array().items(edgeDefinition).required()
});
const res = schema.validate(graph);
expect(res.error).to.be.null;
};
beforeEach(cleanup);
afterEach(cleanup);
@ -106,7 +129,10 @@ describe('_api/gharial', () => {
expect(db._collection(eColName)).to.be.null;
expect(db._collection(vColName)).to.be.null;
let req = arango.POST(url, graphDef);
expect(req).to.have.keys("error", "code", "graph");
expect(req.code).to.equal(202);
expect(req.error).to.be.false;
validateGraphFormat(req.graph);
// This is all async give it some time
do {
@ -116,6 +142,11 @@ describe('_api/gharial', () => {
expect(db._collection(eColName)).to.not.be.null;
expect(db._collection(vColName)).to.not.be.null;
expect(req).to.have.keys("error", "code", "graph");
expect(req.code).to.equal(200);
expect(req.error).to.be.false;
validateGraphFormat(req.graph);
});
it('should create a graph with orphans', () => {
@ -138,7 +169,10 @@ describe('_api/gharial', () => {
expect(db._collection(oColName)).to.be.null;
expect(db._collection(oColName2)).to.be.null;
let req = arango.POST(url, graphDef);
expect(req).to.have.keys("error", "code", "graph");
expect(req.code).to.equal(202);
expect(req.error).to.be.false;
validateGraphFormat(req.graph);
// This is all async give it some time
do {
@ -150,6 +184,72 @@ describe('_api/gharial', () => {
expect(db._collection(vColName)).to.not.be.null;
expect(db._collection(oColName)).to.not.be.null;
expect(db._collection(oColName2)).to.not.be.null;
expect(req).to.have.keys("error", "code", "graph");
expect(req.code).to.equal(200);
expect(req.error).to.be.false;
validateGraphFormat(req.graph);
});
});
describe('graph modification test suite', function () {
const vertexUrl = `${url}/${graphName}/vertex`;
const edgeUrl = `${url}/${graphName}/edge`;
beforeEach(() => {
const graphDef = {
"name": graphName,
"edgeDefinitions": [{
"collection": eColName,
"from": [vColName],
"to": [vColName]
}
],
"isSmart": false
};
expect(db._collection(eColName)).to.be.null;
expect(db._collection(vColName)).to.be.null;
let req = arango.POST(url, graphDef);
// Just make sure the graph exists
do {
wait(0.1);
req = arango.GET(url + "/" + graphName);
} while (req.code !== 200);
});
it('should list all graphs in correct format', () => {
const res = arango.GET(url);
expect(res).to.have.keys("error", "code", "graphs");
expect(res.code).to.equal(200);
expect(res.error).to.be.false;
res.graphs.map(validateGraphFormat);
});
it('should be able to add an orphan', () => {
const res = arango.POST(vertexUrl, {collection: oColName});
expect(res).to.have.keys("error", "code", "graph");
expect(res.code).to.equal(202);
expect(res.error).to.be.false;
validateGraphFormat(res.graph);
expect(db._collection(oColName)).to.not.be.null;
});
it('should be able to modify edge definition', () => {
const res = arango.PUT(`${edgeUrl}/${eColName}`, {
"collection": eColName,
"from": [vColName, oColName],
"to": [vColName]
});
expect(res).to.have.keys("error", "code", "graph");
expect(res.code).to.equal(202);
expect(res.error).to.be.false;
validateGraphFormat(res.graph);
expect(db._collection(oColName)).to.not.be.null;
});
});