forked from totemstech/node-dynamodb
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.coffee
102 lines (91 loc) · 2.26 KB
/
util.coffee
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
magneto = require 'magneto'
# check if function threw an error
# call done with error when exception is not thrown
# use when task contains async function calls
exports.didThrow = (done, task) =>
try
task()
done new Error "did not throw: #{task.toString()}"
catch e
return
# use when task does not contain async function calls
exports.didThrowDone = (task) =>
return (done) =>
try
task()
done new Error "did not throw: #{task.toString()}"
catch e
done()
# check if function did not throw an error
# call done with error when exception is thrown
# use when task contains async function calls
exports.didNotThrow = (done, task) =>
try
task()
return
catch e
done new Error "did throw: #{task.toString()}"
# use when task does not contain async function calls
exports.didNotThrowDone = (task) =>
return (done) =>
try
task()
done()
catch e
done new Error "did throw: #{task.toString()}"
# execute task in try/catch block
# call done on error
# use when task contains async function calls
exports.tryCatch = (done, task) =>
try
task()
return
catch e
done e
# execute task in try/catch block and follow by done
# call done on error
# use when task does not contain async function calls
exports.tryCatchDone = (done, task) =>
try
task()
done()
catch e
done e
exports.expectError = (done) =>
return (err, res) =>
if err
done()
else
done new Error 'did not return error'
exports.expectNoError = (done) =>
return (err, res) =>
if err
done new Error 'did return error'
else
done()
# start magneto, then execute task followed by done
ddb = null
exports.before = (done, task) =>
set = (ddb) =>
exports.ddb = ddb
task?()
done? null, ddb
if ddb then set ddb
else
port = 4567
magneto.listen port, (err) =>
if err? then done? err
else
spec =
apiVersion: '2011-12-05' #'2012-08-10'
sslEnabled: false
accessKeyId: 'x'
secretAccessKey: 'x'
region: 'x'
endpoint: "http://localhost:#{port}"
ddb = require('../lib/ddb').ddb spec
set ddb
# perform cleanup, then execute task followed by done
exports.after = (done, task) =>
task?()
done?()