Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 39609
1
expect = require('expect')
2
3
{Client} = require('../client')
4
5
async = require('async')
6
7
PATH = '.file' # TODO: very sloppy choice
8
9
describe 'reading and writing to a file', ->
10
C = new Client()
11
it 'writes to a file', (done) ->
12
C.write_file
13
path : PATH
14
data : 'stuff'
15
cb : done
16
17
it 'reads from the file', (done) ->
18
C.path_read
19
path : PATH
20
cb : (err, content) ->
21
if err
22
done(err)
23
else
24
expect(content.toString()).toBe('stuff')
25
done()
26
27
it 'writes to a file twice at the same time', (done) ->
28
async.parallel([
29
(cb) ->
30
C.write_file
31
path : PATH
32
data : 'stuff1'
33
cb : cb
34
(cb) ->
35
C.write_file
36
path : PATH
37
data : 'stuff2'
38
cb : cb
39
], done)
40
41
it 'reads from the twice at the same time', (done) ->
42
async.parallel([
43
(cb) ->
44
C.path_read
45
path : PATH
46
cb : cb
47
(cb) ->
48
C.path_read
49
path : PATH
50
cb : cb
51
], (err, content) ->
52
if err
53
done(err)
54
else
55
expect(content.toString().slice(0,5)).toBe('stuff')
56
done()
57
)
58
59
60
61
62
63
64
65