From fa12aa2d5582986442b65c91c3a453d4aaea9bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Fri, 15 May 2015 18:02:22 +0200 Subject: [PATCH] rpcd has some bug that makes it crash when we do uci.revert. So reverts will always fail --- luciexpress/htdocs/js/uci.js | 8 +++--- luciexpress/tests/test-uci.js | 47 ++++++++++++++++------------------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/luciexpress/htdocs/js/uci.js b/luciexpress/htdocs/js/uci.js index 0725bc42f..1d57b5307 100644 --- a/luciexpress/htdocs/js/uci.js +++ b/luciexpress/htdocs/js/uci.js @@ -405,10 +405,10 @@ if(self[x].constructor == UCI.Section) to_delete[x] = self[x]; }); //console.log("To delete: "+Object.keys(to_delete)); - $rpc.uci.rollback({ + /*$rpc.uci.rollback({ config: self[".name"], ubus_rpc_session: $rpc.$sid() - }).done(function(){ + }).done(function(){*/ $rpc.uci.state({ config: self[".name"] }).done(function(data){ @@ -433,9 +433,9 @@ }).fail(function(){ deferred.reject(); }); - }).fail(function(){ + /*}).fail(function(){ deferred.reject("Could not revert config before sync!"); - }); + }); */ return deferred.promise(); } // set object values on objects that match search criteria diff --git a/luciexpress/tests/test-uci.js b/luciexpress/tests/test-uci.js index 2f5f25956..56a4c2136 100644 --- a/luciexpress/tests/test-uci.js +++ b/luciexpress/tests/test-uci.js @@ -4,7 +4,21 @@ require("./lib-juci"); describe("UCI", function(){ beforeEach(function(done){ $uci.sync().done(function(){ - done(); + var to_delete = $uci.juci["@test"].map(function(x){ + return x; + }); + // have to use a copy of the array because deletion modifies the array + async.eachSeries(to_delete, function(section, next){ + section.$delete().done(function(){ + next(); + }).fail(function(){ + throw new Error("Was unable to delete section "+section[".name"]+" from config juci!"); + }); + }, function(){ + $uci.save().done(function(){ + done(); + }); + }); }); }); it("should have schema definition for each data field found in each defined uci config", function(done){ @@ -43,29 +57,6 @@ describe("UCI", function(){ }); //}); }); - // deletes all sections that have type "test" from juci config and commits the changes - it("should be able to delete unused test sections in juci config", function(done){ // this is just to get to a known state, but we can do it as a test :) - $uci.sync("juci").done(function(){ - expect($uci.juci["@test"]).to.be.an(Array); - var to_delete = $uci.juci["@test"].map(function(x){ - return x; - }); - // have to use a copy of the array because deletion modifies the array - async.eachSeries(to_delete, function(section, next){ - expect(section).to.be.ok(); - section.$delete().done(function(){ - next(); - }).fail(function(){ - throw new Error("Was unable to delete section "+section[".name"]+" from config juci!"); - }); - }, function(){ - expect($uci.juci["@test"]).to.be.empty(); - $uci.save().done(function(){ - done(); - }); - }); - }); - }); // will create an anonymous 'test' section and then delete it, commiting the changes it("should be able to add and delete an anonymous section", function(done){ expect($uci.juci["@test"]).to.be.empty(); @@ -147,10 +138,14 @@ describe("UCI", function(){ it("should not be able to add a section that already exists", function(done){ expect($uci.juci["@test"]).to.be.empty(); $uci.juci.create({".type": "test", ".name": "testname"}).done(function(section){ - $uci.juci.create({".type": "test", ".name": "testname"}).done(function(section){ + $uci.juci.create({".type": "test", ".name": "testname"}).done(function(section2){ throw new Error("Creating a section that already exists returned success when it should fail!"); }).fail(function(){ - done(); + section.$delete().done(function(){ + $uci.save().done(function(){ + done(); + }); + }); }); }).fail(function(){ throw new Error("Failed to create section testname when it was supposed to work fine!");