forked from avalanche123/uvrb
- Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilesystem_spec.rb
270 lines (241 loc) · 5.88 KB
/
filesystem_spec.rb
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
require'libuv'
require'thread'
describeLibuv::Filesystemdo
before:eachdo
@log=[]
@general_failure=[]
@reactor=Libuv::Reactor.default
@filesystem=@reactor.filesystem
@timeout=@reactor.timerdo
@reactor.stop
@general_failure << "test timed out"
end
@timeout.start(4000)
@reactor.notifierdo |error,context|
begin
@general_failure << "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n")iferror.backtrace}\n"
rescueException=>e
@general_failure << "error in logger #{e.inspect}"
end
end
@thefile="test-file.txt"
@reactor.all(@filesystem,@timeout).catchdo |reason|
@general_failure << reason.inspect
end
end
describe'directory navigation'do
it"should list the contents of a folder"do
@reactor.run{ |reactor|
currentDir=Dir.pwd
listing=@filesystem.readdir(currentDir,wait: false)
listing.thendo |result|
@log=result
end
listing.catchdo |error|
@general_failure << error
end
listing.finallydo
@timeout.close
@reactor.stop
end
}
expect(@general_failure).toeq([])
expect((@log.length > 0)).toeq(true)
end
end
describe'file manipulation'do
it"should create and write to a file"do
@reactor.run{ |reactor|
file=@reactor.file(@thefile,File::CREAT|File::WRONLY)
begin
file.write('write some data to a file')
file.chmod(777)
@timeout.close
@reactor.stop
@log=:success
rescue=>error
@general_failure << error
@timeout.close
@reactor.stop
ensure
file.close
end
}
expect(@general_failure).toeq([])
expect(@log).toeq(:success)
end
it"should return stats on the file"do
@reactor.run{ |reactor|
file=@reactor.file(@thefile,File::RDONLY)
begin
stats=file.stat
@timeout.close
@reactor.stop
@log << stats[:st_mtim][:tv_sec]
rescue=>error
@general_failure << error
@timeout.close
@reactor.stop
ensure
file.close
end
}
expect(@general_failure).toeq([])
expect(@log[0]).tobe_kind_of(Integer)
expect(@log.length).toeql(1)
end
it"should read from a file"do
@reactor.run{ |reactor|
file=@reactor.file(@thefile,File::RDONLY)
begin
result=file.read(100)
@timeout.close
@reactor.stop
@log=result
rescue=>error
@general_failure << error
@timeout.close
file.close
@reactor.stop
ensure
file.close
end
}
expect(@general_failure).toeq([])
expect(@log).toeq('write some data to a file')
end
it"should delete a file"do
@reactor.run{ |reactor|
op=@reactor.filesystem.unlink(@thefile,wait: false)
op.thendo
@timeout.close
@reactor.stop
@log=:success
end
op.catchdo |error|
@general_failure << error
@timeout.close
@reactor.stop
end
}
expect(@general_failure).toeq([])
expect(@log).toeq(:success)
end
end
describe'file streaming'do
it"should send a file over a stream",:network=>truedo
@reactor.run{ |reactor|
@server=@reactor.tcp
@client=@reactor.tcp
@server.bind('127.0.0.1',34570)do |client|
client.progressdo |data|
file=@reactor.file('.rspec',File::RDONLY)do
file.send_file(client,wait: false).then(proc{
file.close
client.close
},proc{ |error|
@general_failure << error
})
end
file.catchdo |error|
@general_failure << error.inspect
file.close
client.close
end
end
client.start_read
client.finallydo
@timeout.close
@server.close
@reactor.stop
end
end
# catch errors
@server.catchdo |reason|
@general_failure << reason.inspect
@reactor.stop
end
# start listening
@server.listen(5)
# connect client to server
@client.connect('127.0.0.1',34570)do |client|
client.progressdo |data|
@log << data
end
@client.start_read
@client.write('send file')
end
# catch errors
@client.catchdo |reason|
@general_failure << reason.inspect
@server.close
@reactor.stop
end
}
expect(@general_failure).toeq([])
# Windows GIT adds the carriage return
ifFFI::Platform.windows?
expect(@log).toeq(["--format progress\r\n"])
else
expect(@log).toeq(["--format progress\n"])
end
end
it"should send a file as a HTTP chunked response",:network=>truedo
@reactor.run{ |reactor|
@server=@reactor.tcp
@client=@reactor.tcp
@server.bind('127.0.0.1',34568)do |client|
client.progressdo |data|
file=@reactor.file('.rspec',File::RDONLY)do
file.send_file(client,using: :http,wait: false).then(proc{
file.close
client.close
},proc{ |error|
@general_failure << error
})
end
file.catchdo |error|
@general_failure << error.inspect
file.close
client.close
end
end
client.start_read
client.finallydo
@timeout.close
@server.close
@reactor.stop
end
end
# catch errors
@server.catchdo |reason|
@general_failure << reason.inspect
@reactor.stop
end
# start listening
@server.listen(5)
# connect client to server
@client.connect('127.0.0.1',34568)do |client|
client.progressdo |data|
@log << data
end
@client.start_read
@client.write('send file')
end
# catch errors
@client.catchdo |reason|
@general_failure << reason.inspect
@server.close
@reactor.stop
end
}
expect(@general_failure).toeq([])
# Windows GIT adds the carriage return
ifFFI::Platform.windows?
expect(@log.join('')).toeq("13\r\n--format progress\r\n\r\n0\r\n\r\n")
else
expect(@log.join('')).toeq("12\r\n--format progress\n\r\n0\r\n\r\n")
end
end
end
end