From 7281e4deb63fa5632850a0c15333c7fae1507a4a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 11 Mar 2016 22:58:11 +0000 Subject: [PATCH] Add zero-length flow file tests --- .../runtime/storage/localfilesystem_spec.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/red/runtime/storage/localfilesystem_spec.js b/test/red/runtime/storage/localfilesystem_spec.js index c708a07b0..15f8ea9c1 100644 --- a/test/red/runtime/storage/localfilesystem_spec.js +++ b/test/red/runtime/storage/localfilesystem_spec.js @@ -106,6 +106,45 @@ describe('LocalFileSystem', function() { }); }); + it('should handle empty flow file, no backup',function(done) { + localfilesystem.init({userDir:userDir}).then(function() { + var flowFile = 'flows_'+require('os').hostname()+'.json'; + var flowFilePath = path.join(userDir,flowFile); + var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); + fs.closeSync(fs.openSync(flowFilePath, 'w')); + fs.existsSync(flowFilePath).should.be.true; + localfilesystem.getFlows().then(function(flows) { + flows.should.eql([]); + done(); + }).otherwise(function(err) { + done(err); + }); + }).otherwise(function(err) { + done(err); + }); + }); + + it('should handle empty flow file, restores backup',function(done) { + localfilesystem.init({userDir:userDir}).then(function() { + var flowFile = 'flows_'+require('os').hostname()+'.json'; + var flowFilePath = path.join(userDir,flowFile); + var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); + fs.closeSync(fs.openSync(flowFilePath, 'w')); + fs.existsSync(flowFilePath).should.be.true; + fs.existsSync(flowFileBackupPath).should.be.false; + fs.writeFileSync(flowFileBackupPath,JSON.stringify(testFlow)); + fs.existsSync(flowFileBackupPath).should.be.true; + localfilesystem.getFlows().then(function(flows) { + flows.should.eql(testFlow); + done(); + }).otherwise(function(err) { + done(err); + }); + }).otherwise(function(err) { + done(err); + }); + }); + it('should save flows to the default file',function(done) { localfilesystem.init({userDir:userDir}).then(function() { var flowFile = 'flows_'+require('os').hostname()+'.json';