From e9b5cb967a6fe22255b43687cfd2a8ae9f3e8726 Mon Sep 17 00:00:00 2001 From: Marcel Kilian Date: Tue, 24 May 2016 17:17:22 +0200 Subject: [PATCH 1/3] fixed not using decorators of created recipe --- src/models/projects/list.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/projects/list.coffee b/src/models/projects/list.coffee index 45b9c76..26ae113 100644 --- a/src/models/projects/list.coffee +++ b/src/models/projects/list.coffee @@ -53,9 +53,6 @@ model.installProject = (project, callback) -> _r.fromNodeCallback (cb) -> return model.patternPostInstall project, cb if pattern model.projectPostInstall project, cb - .flatMap -> - _r.fromNodeCallback (cb) -> - customModel.clearCustomization project.id, cb .flatMap -> # reload projects to enforce view update _r.fromNodeCallback (cb) -> model.loadProjects cb @@ -100,6 +97,9 @@ model.patternPostInstall = (project, callback) -> .flatMap -> # remove .git folder _r.fromNodeCallback (cb) -> utilModel.removeFileAsync projectDir.path('.git'), cb + .flatMap -> + _r.fromNodeCallback (cb) -> + customModel.clearCustomization project.id, cb .onError callback .onValue -> callback null, true From ebe19dde44ddace7d01c1af2cc7820627dcc27b6 Mon Sep 17 00:00:00 2001 From: Marcel Kilian Date: Mon, 6 Jun 2016 14:15:31 +0200 Subject: [PATCH 2/3] fixed startup error when no .eintopf folder exists --- src/models/vagrant/virtualbox.coffee | 7 +- .../models/vagrant/virtualbox-spec.coffee | 575 ++++++++++-------- 2 files changed, 317 insertions(+), 265 deletions(-) diff --git a/src/models/vagrant/virtualbox.coffee b/src/models/vagrant/virtualbox.coffee index d441063..3ae0786 100644 --- a/src/models/vagrant/virtualbox.coffee +++ b/src/models/vagrant/virtualbox.coffee @@ -5,6 +5,8 @@ utilModel = require "../util/index.coffee" winVBoxManagePath = 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe' # keep slashes +messageNoMachinesFound = 'Vagrant machines not found' + model = {} # wrapper for VBoxManage execution. @@ -66,6 +68,7 @@ model.getOnlyVirtualBoxDir = (callback) -> _r.fromPromise jetpack.findAsync configDir.path(), {matching: ["./.vagrant/machines/*"]}, "inspect" .flatMap (folders) -> + return _r.constantError new Error messageNoMachinesFound if folders.length == 0 _r.fromNodeCallback (cb) -> return cb new Error "can't maintain integrity with multiple machine folders" if folders.length != 1 cb null, folders[0] @@ -126,7 +129,9 @@ model.getGuestStatus = (callback) -> .map (dir) -> regEx = new RegExp('"' + dir.name + '"') return regEx.test runningVms - .onError callback + .onError (err) -> + return callback null, false if err.message == messageNoMachinesFound + callback err .onValue (val) -> callback null, val diff --git a/tests/specs/models/vagrant/virtualbox-spec.coffee b/tests/specs/models/vagrant/virtualbox-spec.coffee index 1d0bfcd..5f30df8 100644 --- a/tests/specs/models/vagrant/virtualbox-spec.coffee +++ b/tests/specs/models/vagrant/virtualbox-spec.coffee @@ -28,347 +28,394 @@ fromPromise = (value) -> failFromPromise = (error) -> return new Promise (resolve, reject) -> reject new Error error -describe "checkAndRestoreMachineId", -> +describe 'virtualbox', -> beforeEach -> model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - spyOn(model, 'restoreIdFromMachineFolder').andCallFake (callback) -> - process.nextTick -> callback null, true - spyOn(model, 'getMachine').andCallFake (machineId, callback) -> - process.nextTick -> callback null, samples.vmInfoMapped - it 'should return true in callback', (done) -> - model.checkAndRestoreMachineId samples.id, (err, result) -> - expect(result).toBeTruthy() - done() + describe "checkAndRestoreMachineId", -> - it 'should fail when getMachine fails', (done) -> - expected = new Error 'something went wrong' + beforeEach -> + spyOn(model, 'restoreIdFromMachineFolder').andCallFake (callback) -> + process.nextTick -> callback null, true + spyOn(model, 'getMachine').andCallFake (machineId, callback) -> + process.nextTick -> callback null, samples.vmInfoMapped - model.getMachine.andCallFake (machineId, callback) -> - process.nextTick -> callback expected + it 'should return true in callback', (done) -> + model.checkAndRestoreMachineId samples.id, (err, result) -> + expect(result).toBeTruthy() + done() - model.checkAndRestoreMachineId samples.id, (err) -> - expect(err).toBe(expected) - done() + it 'should fail when getMachine fails', (done) -> + expected = new Error 'something went wrong' - it 'should not call restoreIdFromMachineFolder on non virtualbox error', (done) -> - model.getMachine.andCallFake (machineId, callback) -> - process.nextTick -> callback new Error 'something went wrong' + model.getMachine.andCallFake (machineId, callback) -> + process.nextTick -> callback expected - model.checkAndRestoreMachineId samples.id, -> - expect(model.restoreIdFromMachineFolder.callCount).toBe(0) - done() + model.checkAndRestoreMachineId samples.id, (err) -> + expect(err).toBe(expected) + done() - it 'should call restoreIdFromMachineFolder with own callback when err is a virtualbox error', (done) -> - callback = -> - expect(model.restoreIdFromMachineFolder).toHaveBeenCalledWith(callback) - done() + it 'should not call restoreIdFromMachineFolder on non virtualbox error', (done) -> + model.getMachine.andCallFake (machineId, callback) -> + process.nextTick -> callback new Error 'something went wrong' - model.getMachine.andCallFake (machineId, callback) -> - process.nextTick -> callback new Error samples.virtualBoxError + model.checkAndRestoreMachineId samples.id, -> + expect(model.restoreIdFromMachineFolder.callCount).toBe(0) + done() - model.checkAndRestoreMachineId samples.id, callback + it 'should call restoreIdFromMachineFolder with own callback when err is a virtualbox error', (done) -> + callback = -> + expect(model.restoreIdFromMachineFolder).toHaveBeenCalledWith(callback) + done() + model.getMachine.andCallFake (machineId, callback) -> + process.nextTick -> callback new Error samples.virtualBoxError -describe "getMachine", -> + model.checkAndRestoreMachineId samples.id, callback - beforeEach -> - this.originalPlatform = process.platform; - Object.defineProperty process, 'platform', - value: 'MockOS' - model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - model.__set__ 'utilModel', - runCmd: jasmine.createSpy('runCmd').andCallFake (cmd, config, logName, logAction, callback) -> - process.nextTick -> callback null, samples.vmInfoRaw + describe "getMachine", -> - afterEach -> - Object.defineProperty process, 'platform', - value: this.originalPlatform + beforeEach -> + this.originalPlatform = process.platform; + Object.defineProperty process, 'platform', + value: 'MockOS' - it 'should return object in callback', (done) -> - model.getMachine samples.id, (err, result) -> - expect(result).toEqual(jasmine.any(Object)) - done() + model.__set__ 'utilModel', + runCmd: jasmine.createSpy('runCmd').andCallFake (cmd, config, logName, logAction, callback) -> + process.nextTick -> callback null, samples.vmInfoRaw - it 'should run cmd only once', (done) -> - model.getMachine samples.id, -> - expect(model.__get__('utilModel').runCmd.callCount).toBe(1) - done() + afterEach -> + Object.defineProperty process, 'platform', + value: this.originalPlatform - it 'should fail when runCmd fails', (done) -> - expected = new Error 'something went wrong' + it 'should return object in callback', (done) -> + model.getMachine samples.id, (err, result) -> + expect(result).toEqual(jasmine.any(Object)) + done() - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - process.nextTick -> callback expected + it 'should run cmd only once', (done) -> + model.getMachine samples.id, -> + expect(model.__get__('utilModel').runCmd.callCount).toBe(1) + done() - model.getMachine samples.id, (err) -> - expect(err).toBe(expected) - done() + it 'should fail when runCmd fails', (done) -> + expected = new Error 'something went wrong' - it 'should call runCmd only once when it fails on linux', (done) -> - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - if cmd.match(/^"C:/) - return process.nextTick -> callback new Error 'something went wrong' - process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + process.nextTick -> callback expected - model.getMachine samples.id, -> - expect(model.__get__('utilModel').runCmd.callCount).toBe(1) - done() + model.getMachine samples.id, (err) -> + expect(err).toBe(expected) + done() - it 'should call runCmd twice when first fails on windows', (done) -> - Object.defineProperty process, 'platform', - value: 'win32' + it 'should call runCmd only once when it fails on linux', (done) -> + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + if cmd.match(/^"C:/) + return process.nextTick -> callback new Error 'something went wrong' + process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - if cmd.match(/^"C:/) - return process.nextTick -> callback null, samples.vmInfoRaw - process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' + model.getMachine samples.id, -> + expect(model.__get__('utilModel').runCmd.callCount).toBe(1) + done() - model.getMachine samples.id, -> - expect(model.__get__('utilModel').runCmd.callCount).toBe(2) - done() + it 'should call runCmd twice when first fails on windows', (done) -> + Object.defineProperty process, 'platform', + value: 'win32' - it 'should call runCmd with fixed vbox manage after first fail on windows', (done) -> - Object.defineProperty process, 'platform', - value: 'win32' + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + if cmd.match(/^"C:/) + return process.nextTick -> callback null, samples.vmInfoRaw + process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' + model.getMachine samples.id, -> + expect(model.__get__('utilModel').runCmd.callCount).toBe(2) + done() - model.getMachine samples.id, -> - expect(model.__get__('utilModel.runCmd').argsForCall[1][0]).toContain('C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe') - done() + it 'should call runCmd with fixed vbox manage after first fail on windows', (done) -> + Object.defineProperty process, 'platform', + value: 'win32' - it 'should return empty object when runCmd returns nothing', (done) -> - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - process.nextTick -> callback null, null + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + process.nextTick -> callback new Error 'sh: 1: VBoxManage: not found' - model.getMachine samples.id, (err, result) -> - expect(result).toEqual({}) - done() + model.getMachine samples.id, -> + expect(model.__get__('utilModel.runCmd').argsForCall[1][0]).toContain('C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe') + done() - it 'should map cmd result into correct properties', (done) -> - model.getMachine samples.id, (err, result) -> - expect(result).toEqual(samples.vmInfoMapped) - done() + it 'should return empty object when runCmd returns nothing', (done) -> + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + process.nextTick -> callback null, null - it 'should map windows cmd result into correct properties', (done) -> - model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> - process.nextTick -> callback null, samples.vmInfoRawWin + model.getMachine samples.id, (err, result) -> + expect(result).toEqual({}) + done() - model.getMachine samples.id, (err, result) -> - expect(result).toEqual(samples.vmInfoMapped) - done() + it 'should map cmd result into correct properties', (done) -> + model.getMachine samples.id, (err, result) -> + expect(result).toEqual(samples.vmInfoMapped) + done() + it 'should map windows cmd result into correct properties', (done) -> + model.__get__('utilModel').runCmd.andCallFake (cmd, config, logName, logAction, callback) -> + process.nextTick -> callback null, samples.vmInfoRawWin -describe "getMachineFromMachineFolder", -> + model.getMachine samples.id, (err, result) -> + expect(result).toEqual(samples.vmInfoMapped) + done() - beforeEach -> - model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - spyOn(model, 'getMachine').andCallFake (machineId, callback) -> - process.nextTick -> callback null, samples.vmInfoMapped - spyOn(model, 'getOnlyVirtualBoxDir').andCallFake (callback) -> - process.nextTick -> callback null, {absolutePath: samples.path, name: samples.vmInfoMapped.name } - afterEach -> # cleanup when properties were changed - delete samples.vmInfoMapped.absolutePath if samples.vmInfoMapped.absolutePath - delete samples.vmInfoMapped.idFilePath if samples.vmInfoMapped.idFilePath + describe "getMachineFromMachineFolder", -> - it 'should return object in callback', (done) -> - model.getMachineFromMachineFolder (err, result) -> - expect(result).toEqual(jasmine.any(Object)) - done() + beforeEach -> + spyOn(model, 'getMachine').andCallFake (machineId, callback) -> + process.nextTick -> callback null, samples.vmInfoMapped + spyOn(model, 'getOnlyVirtualBoxDir').andCallFake (callback) -> + process.nextTick -> callback null, {absolutePath: samples.path, name: samples.vmInfoMapped.name } - it 'should fail when getOnlyVirtualBoxDir fails', (done) -> - expected = new Error 'some random error' + afterEach -> # cleanup when properties were changed + delete samples.vmInfoMapped.absolutePath if samples.vmInfoMapped.absolutePath + delete samples.vmInfoMapped.idFilePath if samples.vmInfoMapped.idFilePath - model.getOnlyVirtualBoxDir.andCallFake (callback) -> - process.nextTick -> callback expected + it 'should return object in callback', (done) -> + model.getMachineFromMachineFolder (err, result) -> + expect(result).toEqual(jasmine.any(Object)) + done() - model.getMachineFromMachineFolder (err) -> - expect(err).toBe(expected) - done() + it 'should fail when getOnlyVirtualBoxDir fails', (done) -> + expected = new Error 'some random error' - it 'should fail when getMachine fails', (done) -> - expected = new Error 'some random error' + model.getOnlyVirtualBoxDir.andCallFake (callback) -> + process.nextTick -> callback expected - model.getMachine.andCallFake (machineId, callback) -> - process.nextTick -> callback expected + model.getMachineFromMachineFolder (err) -> + expect(err).toBe(expected) + done() - model.getMachineFromMachineFolder (err) -> - expect(err).toBe(expected) - done() + it 'should fail when getMachine fails', (done) -> + expected = new Error 'some random error' - it 'should call getMachine with with correct parameter', (done) -> - model.getMachineFromMachineFolder -> - expect(model.getMachine).toHaveBeenCalledWith(samples.vmInfoMapped.name, jasmine.any(Function)) - done() + model.getMachine.andCallFake (machineId, callback) -> + process.nextTick -> callback expected - it 'should add additional properties', (done) -> - model.getMachineFromMachineFolder (err, result) -> - expect(result).toEqual(samples.vmInfoMappedExt) - done() + model.getMachineFromMachineFolder (err) -> + expect(err).toBe(expected) + done() + it 'should call getMachine with with correct parameter', (done) -> + model.getMachineFromMachineFolder -> + expect(model.getMachine).toHaveBeenCalledWith(samples.vmInfoMapped.name, jasmine.any(Function)) + done() -describe "getOnlyVirtualBoxDir", -> + it 'should add additional properties', (done) -> + model.getMachineFromMachineFolder (err, result) -> + expect(result).toEqual(samples.vmInfoMappedExt) + done() - beforeEach -> - jetpackMock = - cwd: jasmine.createSpy('cwd').andCallFake -> jetpackMock - path: jasmine.createSpy('cwd').andCallFake -> samples.path - findAsync: jasmine.createSpy('findAsync').andCallFake -> fromPromise [{absolutePath: samples.path}] - model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - model.__set__ 'utilModel', - getConfigModulePath: jasmine.createSpy('getConfigModulePath').andCallFake () -> samples.path - model.__set__ 'jetpack', jetpackMock + describe "getOnlyVirtualBoxDir", -> - it 'should return only dir object with correct absolutePath property callback', (done) -> - model.getOnlyVirtualBoxDir (err, result) -> - expect(result).toEqual({absolutePath: samples.path}) - done() + beforeEach -> + jetpackMock = + cwd: jasmine.createSpy('cwd').andCallFake -> jetpackMock + path: jasmine.createSpy('cwd').andCallFake -> samples.path + findAsync: jasmine.createSpy('findAsync').andCallFake -> fromPromise [{absolutePath: samples.path}] - it 'should fail when getConfigModulePath returns nothing', (done) -> - model.__get__('utilModel').getConfigModulePath.andCallFake -> null + model.__set__ 'utilModel', + getConfigModulePath: jasmine.createSpy('getConfigModulePath').andCallFake () -> samples.path + model.__set__ 'jetpack', jetpackMock - model.getOnlyVirtualBoxDir (err) -> - expect(err).toBeTruthy() - done() + it 'should return only dir object with correct absolutePath property callback', (done) -> + model.getOnlyVirtualBoxDir (err, result) -> + expect(result).toEqual({absolutePath: samples.path}) + done() - it 'should fail when findAsync fails', (done) -> - model.__get__('jetpack.findAsync').andCallFake -> return failFromPromise new Error "something went wrong" + it 'should fail when getConfigModulePath returns nothing', (done) -> + model.__get__('utilModel').getConfigModulePath.andCallFake -> null - model.getOnlyVirtualBoxDir (err) -> - expect(err).toBeTruthy() - done() + model.getOnlyVirtualBoxDir (err) -> + expect(err).toBeTruthy() + done() - it 'should fail when findAsync returns empty array', (done) -> - model.__get__('jetpack.findAsync').andCallFake -> return fromPromise [] + it 'should fail when findAsync fails', (done) -> + model.__get__('jetpack.findAsync').andCallFake -> return failFromPromise new Error "something went wrong" - model.getOnlyVirtualBoxDir (err) -> - expect(err).toBeTruthy() - done() + model.getOnlyVirtualBoxDir (err) -> + expect(err).toBeTruthy() + done() - it 'should fail when findAsync returns more than one result', (done) -> - model.__get__('jetpack.findAsync').andCallFake -> return fromPromise [{absolutePath: samples.path}, {absolutePath: samples.path}] + it 'should fail with specific error when findAsync returns empty array', (done) -> + model.__get__('jetpack.findAsync').andCallFake -> return fromPromise [] - model.getOnlyVirtualBoxDir (err) -> - expect(err).toBeTruthy() - done() + model.getOnlyVirtualBoxDir (err) -> + expect(err).toBeTruthy() + expect(err.message).toEqual('Vagrant machines not found') + done() - it 'should call findAsync with correct parameters', (done) -> - model.getOnlyVirtualBoxDir -> - expect(model.__get__ 'jetpack.findAsync').toHaveBeenCalledWith(samples.path, {matching: ["./.vagrant/machines/*"]}, "inspect") - done() + it 'should fail with specific error when findAsync returns more than one result', (done) -> + model.__get__('jetpack.findAsync').andCallFake -> return fromPromise [{absolutePath: samples.path}, {absolutePath: samples.path}] -describe "restoreIdFromMachineFolder", -> + model.getOnlyVirtualBoxDir (err) -> + expect(err).toBeTruthy() + expect(err.message).toEqual("can't maintain integrity with multiple machine folders") + done() - beforeEach -> - model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - model.__set__ 'utilModel', - writeFile: jasmine.createSpy('writeFile').andCallFake (path, content, callback) -> - process.nextTick -> callback null, true - spyOn(model, 'getMachineFromMachineFolder').andCallFake (callback) -> - process.nextTick -> callback null, samples.vmInfoMappedExt + it 'should call findAsync with correct parameters', (done) -> + model.getOnlyVirtualBoxDir -> + expect(model.__get__ 'jetpack.findAsync').toHaveBeenCalledWith(samples.path, {matching: ["./.vagrant/machines/*"]}, "inspect") + done() + + describe "restoreIdFromMachineFolder", -> + + beforeEach -> + model.__set__ 'utilModel', + writeFile: jasmine.createSpy('writeFile').andCallFake (path, content, callback) -> + process.nextTick -> callback null, true + spyOn(model, 'getMachineFromMachineFolder').andCallFake (callback) -> + process.nextTick -> callback null, samples.vmInfoMappedExt + + it 'should return true in callback', (done) -> + model.restoreIdFromMachineFolder (err, result) -> + expect(result).toBeTruthy() + done() + + it 'should fail when getMachineFromMachineFolder fails', (done) -> + expected = new Error 'something went totally wrong this time' + + model.getMachineFromMachineFolder.andCallFake (callback) -> + process.nextTick -> callback expected + + model.restoreIdFromMachineFolder (err) -> + expect(err).toBe(expected) + done() - it 'should return true in callback', (done) -> - model.restoreIdFromMachineFolder (err, result) -> - expect(result).toBeTruthy() - done() + it 'should fail when writeFile fails', (done) -> + expected = new Error 'something went totally wrong this time' - it 'should fail when getMachineFromMachineFolder fails', (done) -> - expected = new Error 'something went totally wrong this time' + model.__get__('utilModel.writeFile').andCallFake (path, content, callback) -> + process.nextTick -> callback expected - model.getMachineFromMachineFolder.andCallFake (callback) -> - process.nextTick -> callback expected + model.restoreIdFromMachineFolder (err) -> + expect(err).toBe(expected) + done() - model.restoreIdFromMachineFolder (err) -> - expect(err).toBe(expected) - done() + it 'should fail when machine does not have the idFilePath property', (done) -> + model.getMachineFromMachineFolder.andCallFake (callback) -> + process.nextTick -> callback null, samples.vmInfoMapped - it 'should fail when writeFile fails', (done) -> - expected = new Error 'something went totally wrong this time' + model.restoreIdFromMachineFolder (err) -> + expect(err).toBeTruthy() + done() - model.__get__('utilModel.writeFile').andCallFake (path, content, callback) -> + it 'should call writeFile with correct parameters', (done) -> + model.restoreIdFromMachineFolder -> + expect(model.__get__('utilModel').writeFile) + .toHaveBeenCalledWith(samples.vmInfoMappedExt.absolutePath + "/virtualbox/id", + samples.vmInfoMappedExt.UUID, jasmine.any(Function)) + done() + + + describe "checkMachineConsistency", -> + + beforeEach -> + jetpackMock = + cwd: jasmine.createSpy('cwd').andCallFake -> jetpackMock + path: jasmine.createSpy('cwd').andCallFake -> samples.vmInfoMappedExt.idFilePath + readAsync: jasmine.createSpy('readAsync').andCallFake -> fromPromise samples.vmInfoMappedExt.UUID + + spyOn(model, 'getOnlyVirtualBoxDir').andCallFake (callback) -> + process.nextTick -> callback null, {absolutePath: samples.path, name: samples.vmInfoMapped.name } + spyOn(model, 'checkAndRestoreMachineId').andCallFake (id, callback) -> + process.nextTick -> callback null, true + spyOn(model, 'restoreIdFromMachineFolder').andCallFake (callback) -> + process.nextTick -> callback null, true + model.__set__ 'jetpack', jetpackMock + + it 'should return true in callback', (done) -> + model.checkMachineConsistency (err, result) -> + expect(result).toBeTruthy() + done() + + it 'should fail when getOnlyVirtualBoxDir fails', (done) -> + expected = new Error 'some random error' + + model.getOnlyVirtualBoxDir.andCallFake (callback) -> process.nextTick -> callback expected - model.restoreIdFromMachineFolder (err) -> - expect(err).toBe(expected) - done() + model.checkMachineConsistency (err) -> + expect(err).toBe(expected) + done() - it 'should fail when machine does not have the idFilePath property', (done) -> - model.getMachineFromMachineFolder.andCallFake (callback) -> - process.nextTick -> callback null, samples.vmInfoMapped + it 'should fail when readAsync fails', (done) -> + model.__get__('jetpack.readAsync').andCallFake -> return failFromPromise new Error "something went wrong" - model.restoreIdFromMachineFolder (err) -> - expect(err).toBeTruthy() - done() + model.checkMachineConsistency (err) -> + expect(err).toBeTruthy() + done() - it 'should call writeFile with correct parameters', (done) -> - model.restoreIdFromMachineFolder -> - expect(model.__get__('utilModel').writeFile) - .toHaveBeenCalledWith(samples.vmInfoMappedExt.absolutePath + "/virtualbox/id", - samples.vmInfoMappedExt.UUID, jasmine.any(Function)) - done() + #@todo for some reason the mock of checkAndRestoreMachineId is not used here +# it 'should call checkAndRestoreMachineId with correct parameters if id exists', -> +# model.checkMachineConsistency -> +# expect(model.checkAndRestoreMachineId).toHaveBeenCalledWith(samples.vmInfoMappedExt.UUID, jasmine.any(Function)) +# done() + it 'should call restoreIdFromMachineFolder with correct parameters if no id', -> + model.__get__('jetpack.readAsync').andCallFake -> return fromPromise null -describe "checkMachineConsistency", -> + model.checkMachineConsistency -> + expect(model.restoreIdFromMachineFolder).toHaveBeenCalledWith() + done() - beforeEach -> - jetpackMock = - cwd: jasmine.createSpy('cwd').andCallFake -> jetpackMock - path: jasmine.createSpy('cwd').andCallFake -> samples.vmInfoMappedExt.idFilePath - readAsync: jasmine.createSpy('readAsync').andCallFake -> fromPromise samples.vmInfoMappedExt.UUID +# @todo test is somehow not persistent it stops randomly.... +# it 'should call readAsync with with correct parameter', (done) -> +# model.checkMachineConsistency -> +# expect(model.__get__('jetpack.readAsync')).toHaveBeenCalledWith(samples.vmInfoMappedExt.idFilePath) +# done() - model = rewire "../../../../src/models/vagrant/virtualbox.coffee" - spyOn(model, 'getOnlyVirtualBoxDir').andCallFake (callback) -> - process.nextTick -> callback null, {absolutePath: samples.path, name: samples.vmInfoMapped.name } - spyOn(model, 'checkAndRestoreMachineId').andCallFake (id, callback) -> - process.nextTick -> callback null, true - spyOn(model, 'restoreIdFromMachineFolder').andCallFake (callback) -> - process.nextTick -> callback null, true - model.__set__ 'jetpack', jetpackMock - - it 'should return true in callback', (done) -> - model.checkMachineConsistency (err, result) -> - expect(result).toBeTruthy() - done() - - it 'should fail when getOnlyVirtualBoxDir fails', (done) -> - expected = new Error 'some random error' - - model.getOnlyVirtualBoxDir.andCallFake (callback) -> - process.nextTick -> callback expected - - model.checkMachineConsistency (err) -> - expect(err).toBe(expected) - done() - - it 'should fail when readAsync fails', (done) -> - model.__get__('jetpack.readAsync').andCallFake -> return failFromPromise new Error "something went wrong" - - model.checkMachineConsistency (err) -> - expect(err).toBeTruthy() - done() - -#@todo for some reason the mock of checkAndRestoreMachineId is not used here -# it 'should call checkAndRestoreMachineId with correct parameters if id exists', -> -# model.checkMachineConsistency -> -# expect(model.checkAndRestoreMachineId).toHaveBeenCalledWith(samples.vmInfoMappedExt.UUID, jasmine.any(Function)) -# done() - - it 'should call restoreIdFromMachineFolder with correct parameters if no id', -> - model.__get__('jetpack.readAsync').andCallFake -> return fromPromise null - - model.checkMachineConsistency -> - expect(model.restoreIdFromMachineFolder).toHaveBeenCalledWith() - done() - -#@todo test is somehow not persistent it stops randomly.... -# it 'should call readAsync with with correct parameter', (done) -> -# model.checkMachineConsistency -> -# expect(model.__get__('jetpack.readAsync')).toHaveBeenCalledWith(samples.vmInfoMappedExt.idFilePath) -# done() + describe "getGuestStatus", -> + + beforeEach -> + spyOn(model, 'runVBoxCmd').andCallFake (cmd, callback) -> + process.nextTick -> callback null, '"vm1" {das213....}\r\n"vm2" {sa213....}\r\n"' + samples.vmInfoMapped.name + '" {8646....}\r\n"vm3" {1231dsa....}' + + spyOn(model, 'getOnlyVirtualBoxDir').andCallFake (callback) -> + process.nextTick -> callback null, {absolutePath: samples.path, name: samples.vmInfoMapped.name } + + it 'should return true', (done) -> + model.getGuestStatus (err, result) -> + expect(err).toBeNull(); + expect(result).toBeTruthy(); + done() + + it 'should return false', (done) -> + model.runVBoxCmd.andCallFake (cmd, callback) -> + process.nextTick -> callback null, '"vm1" {das213....}\r\n"vm2" {sa213....}\r\n"vm3" {1231dsa....}' + + model.getGuestStatus (err, result) -> + expect(err).toBeNull(); + expect(result).toBeFalsy(); + done() + + it 'should call runVBoxCmd with correct params', (done) -> + model.getGuestStatus (err, result) -> + expect(model.runVBoxCmd).toHaveBeenCalledWith 'list runningvms', jasmine.any(Function) + done() + + it 'should return false on no machines found error', (done) -> + model.getOnlyVirtualBoxDir.andCallFake (callback) -> + process.nextTick -> callback new Error model.__get__ 'messageNoMachinesFound' + + model.getGuestStatus (err, result) -> + expect(err).toBeNull(); + expect(result).toBeFalsy(); + done() + + it 'should fail error', (done) -> + model.getOnlyVirtualBoxDir.andCallFake (callback) -> + process.nextTick -> callback new Error 'some random error' + + model.getGuestStatus (err) -> + expect(err).toBeTruthy(); + done() From 1cc3460c61bd200ecc96b991aa71377f9ce17162 Mon Sep 17 00:00:00 2001 From: Marcel Kilian Date: Mon, 6 Jun 2016 14:37:46 +0200 Subject: [PATCH 3/3] increased version to 1.3.2 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b173632..458a4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.3.2 + +Fixed: + +- fixed startup error when no .eintopf folder exists +- fixed not using decorators of created recipe + ## 1.3.1 Changed: diff --git a/package.json b/package.json index 30a4fc7..947a3f5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "productName": "Eintopf", "identifier": "com.mazehall.eintopf", "description": "The smartest way to share and administrate docker projects.", - "version": "1.3.1", + "version": "1.3.2", "author": "Jens Klose ", "maintainers": [ "jens klose ",