This repository has been archived by the owner on Feb 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
105 lines (90 loc) · 1.69 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var tape = require('tape')
var random = require('./')
tape('open before read', function (t) {
t.plan(3)
var storage = random({
open: function (cb) {
t.pass('opened')
cb()
},
read: function (offset, length, cb) {
t.pass('reading')
cb(null, Buffer.alloc(length))
}
})
storage.read(0, 10, function (err) {
t.error(err)
t.end()
})
})
tape('open before write', function (t) {
t.plan(3)
var storage = random({
open: function (cb) {
t.pass('opened')
cb()
},
write: function (offset, buf, cb) {
t.pass('writing')
cb()
}
})
storage.write(0, Buffer.alloc(10), function (err) {
t.error(err)
t.end()
})
})
tape('open only fires once', function (t) {
t.plan(7)
var opened = 0
var storage = random({
open: function (cb) {
opened++
setTimeout(function () {
cb()
}, 100)
},
read: function (offset, length, cb) {
cb(null, Buffer.alloc(length))
}
})
storage.open(function (err) {
t.error(err)
})
storage.read(0, 10, function (err, buf) {
t.same(opened, 1)
t.error(err)
t.ok(buf)
})
storage.read(10, 5, function (err, buf) {
t.same(opened, 1)
t.error(err)
t.ok(buf)
})
})
tape('close', function (t) {
t.plan(2)
var storage = random({
open: function (cb) {
t.pass('opened')
cb(null)
},
close: function (cb) {
t.pass('closed')
cb(null)
}
})
storage.close(function () {
t.end()
})
})
tape('end', function (t) {
var storage = random()
storage.end({}, function (err) {
t.error(err)
storage.end(function (err) {
t.error(err)
t.end()
})
})
})