From b89524c43bb59b95d2137ead6f540d43b6d7a700 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 2 Dec 2014 11:28:49 -0400 Subject: [PATCH] Implement os module --- lib/resin/index.coffee | 1 + lib/resin/os/os.coffee | 7 +++++++ lib/resin/os/os.spec.coffee | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/resin/os/os.coffee create mode 100644 lib/resin/os/os.spec.coffee diff --git a/lib/resin/index.coffee b/lib/resin/index.coffee index a81685b7..bbf9db04 100644 --- a/lib/resin/index.coffee +++ b/lib/resin/index.coffee @@ -9,4 +9,5 @@ module.exports = device: require('./device/device') ui: require('./ui') cli: require('./cli/cli') + os: require('./os/os') config: require('./config') diff --git a/lib/resin/os/os.coffee b/lib/resin/os/os.coffee new file mode 100644 index 00000000..18294c8c --- /dev/null +++ b/lib/resin/os/os.coffee @@ -0,0 +1,7 @@ +exports.generateCacheName = (id, connectionParams) -> + result = "#{id}-#{connectionParams.network}" + + if connectionParams.wifiSsid? + result += "-#{connectionParams.wifiSsid}" + + return "#{result}-#{Date.now()}" diff --git a/lib/resin/os/os.spec.coffee b/lib/resin/os/os.spec.coffee new file mode 100644 index 00000000..c81cd5f0 --- /dev/null +++ b/lib/resin/os/os.spec.coffee @@ -0,0 +1,36 @@ +_ = require('lodash') +chai = require('chai') +expect = chai.expect +os = require('./os') + +APPS = + validEthernet: + id: 91 + params: + network: 'ethernet' + invalidNetworkType: + id: 91 + params: + network: 'foobar' + validWifi: + id: 91 + params: + network: 'wifi' + wifiSsid: 'MYSSID' + +describe 'OS:', -> + + describe '#generateCacheName()', -> + + describe 'given network is ethernet', -> + + it 'should construct a correct name', -> + application = APPS.validEthernet + result = os.generateCacheName(application.id, application.params) + expect(result).to.equal("#{application.id}-ethernet-#{Date.now()}") + + describe 'given network is wifi', -> + it 'should construct a correct name', -> + application = APPS.validWifi + result = os.generateCacheName(application.id, application.params) + expect(result).to.equal("#{application.id}-wifi-#{application.params.wifiSsid}-#{Date.now()}")