mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Cleanup tests
This commit is contained in:
parent
8143fa3ab3
commit
58cc0be0c9
@ -3,11 +3,18 @@ nock = require('nock')
|
||||
async = require('async')
|
||||
auth = require('./auth')
|
||||
config = require('../../config')
|
||||
mock = require('../../../tests/utils/mock')
|
||||
johnDoeFixture = require('../../../tests/fixtures/johndoe')
|
||||
janeDoeFixture = require('../../../tests/fixtures/janedoe')
|
||||
|
||||
describe 'Auth:', ->
|
||||
|
||||
beforeEach ->
|
||||
mock.fs.init()
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
||||
describe 'given valid credentials', ->
|
||||
|
||||
beforeEach ->
|
||||
|
@ -2,3 +2,4 @@ module.exports =
|
||||
|
||||
# TODO: Should be configurable
|
||||
baseUrl: 'https://staging.resin.io'
|
||||
dataPrefix: '~/.resin'
|
||||
|
@ -1,11 +1,12 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
dataPrefix = require('./data-prefix')
|
||||
config = require('../config')
|
||||
|
||||
PREFIXES =
|
||||
main: '~/.resin'
|
||||
new: '~/.resin-new'
|
||||
invalid: { path: '~/.resin' }
|
||||
main: config.dataPrefix
|
||||
new: "#{config.dataPrefix}-new"
|
||||
invalid: { path: '/abc' }
|
||||
|
||||
describe 'DataPrefix:', ->
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
fsUtils = require('../fs-utils/fs-utils')
|
||||
mock = require('../../tests/utils/mock')
|
||||
async = require('async')
|
||||
mockFs = require('mock-fs')
|
||||
config = require('../config')
|
||||
data = require('./data')
|
||||
|
||||
PREFIX = '~/.resin'
|
||||
|
||||
FILES_FIXTURES =
|
||||
hello:
|
||||
filename: 'hello_world.test'
|
||||
@ -17,15 +16,15 @@ FILES_FIXTURES =
|
||||
|
||||
FILESYSTEM =
|
||||
text:
|
||||
name: "#{PREFIX}/text"
|
||||
name: "#{config.dataPrefix}/text"
|
||||
contents: 'Hello World'
|
||||
key: 'text'
|
||||
directory:
|
||||
name: "#{PREFIX}/directory"
|
||||
contents: mockFs.directory()
|
||||
name: "#{config.dataPrefix}/directory"
|
||||
contents: {}
|
||||
key: 'directory'
|
||||
nested:
|
||||
name: "#{PREFIX}/nested/text"
|
||||
name: "#{config.dataPrefix}/nested/text"
|
||||
contents: 'Nested Hello World'
|
||||
key: 'nested/text'
|
||||
|
||||
@ -60,15 +59,11 @@ describe 'Data:', ->
|
||||
describe 'given a prefix', ->
|
||||
|
||||
beforeEach ->
|
||||
mockFsOptions = {}
|
||||
for key, value of FILESYSTEM
|
||||
mockFsOptions[value.name] = value.contents
|
||||
mockFs(mockFsOptions)
|
||||
|
||||
data.prefix.set(PREFIX)
|
||||
mock.fs.init(FILESYSTEM)
|
||||
data.prefix.set(config.dataPrefix)
|
||||
|
||||
afterEach ->
|
||||
mockFs.restore()
|
||||
mock.fs.restore()
|
||||
data.prefix.clear()
|
||||
|
||||
describe '#get()', ->
|
||||
|
@ -1,6 +1,8 @@
|
||||
expect = require('chai').expect
|
||||
mockFs = require('mock-fs')
|
||||
mock = require('../../tests/utils/mock')
|
||||
fsUtils = require('./fs-utils')
|
||||
config = require('../config')
|
||||
data = require('../data/data')
|
||||
|
||||
FILESYSTEM =
|
||||
text:
|
||||
@ -8,7 +10,7 @@ FILESYSTEM =
|
||||
contents: 'Hello World'
|
||||
directory:
|
||||
name: '/tmp/directory'
|
||||
contents: mockFs.directory()
|
||||
contents: {}
|
||||
|
||||
describe 'FsUtils:', ->
|
||||
|
||||
@ -28,8 +30,8 @@ describe 'FsUtils:', ->
|
||||
it 'should return true for valid paths', ->
|
||||
|
||||
for validPath in [
|
||||
config.dataPrefix
|
||||
'/Users/johndoe'
|
||||
'~/.resin'
|
||||
'../parent'
|
||||
'./file/../file2'
|
||||
]
|
||||
@ -38,13 +40,11 @@ describe 'FsUtils:', ->
|
||||
describe '#isDirectory()', ->
|
||||
|
||||
beforeEach ->
|
||||
mockFsOptions = {}
|
||||
for key, value of FILESYSTEM
|
||||
mockFsOptions[value.name] = value.contents
|
||||
mockFs(mockFsOptions)
|
||||
mock.fs.init(FILESYSTEM)
|
||||
data.prefix.set(config.dataPrefix)
|
||||
|
||||
afterEach ->
|
||||
mockFs.restore()
|
||||
mock.fs.restore()
|
||||
|
||||
it 'should return true if directory', (done) ->
|
||||
fsUtils.isDirectory FILESYSTEM.directory.name, (error, isDirectory) ->
|
||||
|
@ -3,6 +3,7 @@ nock = require('nock')
|
||||
server = require('./server')
|
||||
config = require('../config')
|
||||
token = require('../token/token')
|
||||
mock = require('../../tests/utils/mock')
|
||||
johnDoeFixture = require('../../tests/fixtures/johndoe.json')
|
||||
|
||||
TEST_URI = config.baseUrl
|
||||
@ -38,6 +39,11 @@ describe 'Server:', ->
|
||||
lowercaseMethod = method.toLowerCase()
|
||||
nock(TEST_URI)[lowercaseMethod](URI.ok).reply(200, status: STATUS.ok)
|
||||
|
||||
mock.fs.init()
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
||||
describe '#request()', ->
|
||||
|
||||
it 'should make a real HTTP request', (done) ->
|
||||
|
@ -1,12 +1,19 @@
|
||||
expect = require('chai').expect
|
||||
async = require('async')
|
||||
token = require('./token')
|
||||
mock = require('../../tests/utils/mock')
|
||||
|
||||
johnDoeFixture = require('../../tests/fixtures/johndoe.json')
|
||||
janeDoeFixture = require('../../tests/fixtures/janedoe.json')
|
||||
|
||||
describe 'Token:', ->
|
||||
|
||||
beforeEach ->
|
||||
mock.fs.init()
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
||||
describe 'given a user that is logged in', ->
|
||||
|
||||
beforeEach (done) ->
|
||||
|
18
tests/utils/mock.coffee
Normal file
18
tests/utils/mock.coffee
Normal file
@ -0,0 +1,18 @@
|
||||
mockFs = require('mock-fs')
|
||||
config = require('../../lib/config')
|
||||
|
||||
exports.fs =
|
||||
|
||||
init: (filesystemConfig = {}) ->
|
||||
mockFsOptions = {}
|
||||
|
||||
# Mock data prefix automatically to remove
|
||||
# duplication in most of the tests
|
||||
mockFsOptions[config.dataPrefix] = mockFs.directory()
|
||||
|
||||
for key, value of filesystemConfig
|
||||
mockFsOptions[value.name] = value.contents
|
||||
mockFs(mockFsOptions)
|
||||
|
||||
restore: ->
|
||||
mockFs.restore()
|
Loading…
Reference in New Issue
Block a user