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