jaune-fs
Version:
file system for jaune framework
103 lines (68 loc) • 2.02 kB
text/coffeescript
{
equal
ok
} = require 'assert'
{
GoogleStorageClient
} = require '../../lib/filesystem-google-storage'
{
PassThrough
} = require 'stream'
{
mockFile
stopMocks
} = require './mock'
connection =
bucketName: 'free-fair-core'
projectId: 'free-fair'
credentials:
project_id: 'proj-id'
private_key: 'the-key'
FileNameOrigin = 'writeFile.txt'
FileNameOriginNonExisting = 'writeFile.123.txt'
FileData = 'this is the data !@# \u1F607'
describe 'filesystem-google-storage-fs', ->
describe 'readFile', ->
describe 'successfuly', ->
before ->
mockFile connection, FileNameOrigin, {
createReadStream: (opts) ->
= s = new PassThrough()
s.write(FileData)
s.end()
s
readFile: (target, cb) ->
equal target, FileNameTarget
cb null,
}
= new GoogleStorageClient connection
after stopMocks
it 'should read an existing file', (cb) ->
.readFile FileNameOrigin
.then (stream) ->
stream
.on 'data', (data) ->
equal data.toString('utf-8'), FileData
.on 'end', cb
.on 'error', (err) -> cb equal null, err
describe 'failing', ->
before ->
mockFile connection, FileNameOriginNonExisting, {
createReadStream: (opts) ->
= s = new PassThrough()
s.write(FileData)
s.on 'pipe', -> s.emit 'error', code: 500
s
readFile: (target, cb) ->
equal target, FileNameOriginNonExisting
cb null,
}
= new GoogleStorageClient connection
after stopMocks
it 'should fail to read non existing file', (cb) ->
.readFile FileNameOriginNonExisting
.then (stream) ->
new PassThrough().pipe(
stream.on 'error', ({code}) -> cb equal code, 500)