From bc752a28c7a82981325b3cccbdae4933ae7746a7 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 26 Nov 2019 15:30:21 +0100 Subject: [PATCH] Cherry picked bug-fix for GharialAPI to return name in LIST (#10545) --- CHANGELOG | 5 ++ arangod/Graph/GraphManager.cpp | 3 +- tests/js/client/http/api-gharial-spec.js | 100 +++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index ca60bb00ba..69bea786c9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/arangod/Graph/GraphManager.cpp b/arangod/Graph/GraphManager.cpp index c84d7a3d18..df7d8d424c 100644 --- a/arangod/Graph/GraphManager.cpp +++ b/arangod/Graph/GraphManager.cpp @@ -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); } diff --git a/tests/js/client/http/api-gharial-spec.js b/tests/js/client/http/api-gharial-spec.js index 3d1b95e6ac..0825a19827 100644 --- a/tests/js/client/http/api-gharial-spec.js +++ b/tests/js/client/http/api-gharial-spec.js @@ -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; }); });