Tests: Ruby module.

This commit is contained in:
Andrey Zelenkov
2018-03-21 18:26:40 +03:00
parent 37051b6c15
commit c7e67446a3
33 changed files with 565 additions and 15 deletions

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
at_exit do
env['rack.errors'].puts('At exit called.')
end
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,5 @@
app = Proc.new do |env|
['200', {'Content-Length' => '10'}, ['0123', '4567', '89']]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
io = IO.new(0, 'r')
['200', {'Content-Length' => '0'}, io]
end
run app

View File

@@ -0,0 +1,5 @@
app = Proc.new do |env|
['200', {}, []]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
file = File.open('file', 'r')
['200', {'Content-Length' => '5'}, file]
end
run app

1
test/ruby/body_file/file Normal file
View File

@@ -0,0 +1 @@
body

View File

@@ -0,0 +1,9 @@
app = Proc.new do |env|
body = env['rack.input'].gets
#body += env['rack.input'].gets
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
env['rack.errors'].puts('Error in application')
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
env['rack.errors'].puts(1234567890)
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
env['rack.errors'].write('Error in application')
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
env['rack.errors'].write(1234567890)
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,15 @@
app = Proc.new do |env|
class Custom
def to_s()
nil
end
end
e = Custom.new()
env['rack.errors'].write(e)
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
['200', {
'Content-Length' => '0',
'Custom-Header' => env['rack.input'].read
}, []]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
['200', {
'Content-Length' => '0',
'rack.header' => 'hello'
}, ['']]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
['200', {
'Content-Length' => '0',
'Status' => '200'
}, []]
end
run app

View File

@@ -0,0 +1,11 @@
app = Proc.new do |env|
body = ''
env['rack.input'].each do |value|
body += value
end
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
body = env['rack.input'].gets
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,14 @@
app = Proc.new do |env|
body = ''
buf = ''
loop do
buf = env['rack.input'].gets
break if buf == nil
body += buf
end
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,9 @@
app = Proc.new do |env|
body = ''
env['rack.input'].read(nil, body)
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,9 @@
app = Proc.new do |env|
body = 'blah'
env['rack.input'].read(nil, body)
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,6 @@
app = Proc.new do |env|
body = env['rack.input'].read
['200', {'Content-Length' => body.length.to_s}, [body]]
end
run app

View File

@@ -0,0 +1,10 @@
app = Proc.new do |env|
body = env['rack.input'].read(4)
body += env['rack.input'].read(4)
body += env['rack.input'].read(1)
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
env['rack.input'].read
env['rack.input'].rewind
body = env['rack.input'].read
['200', {'Content-Length' => body.length.to_s}, [body]]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
body = env['rack.input'].read
['200', {
'Content-Length' => body.length.to_s
}, [body]]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
['200', {
'Content-Length' => '0',
'Query-String' => env['QUERY_STRING']
}, ['']]
end
run app

View File

@@ -0,0 +1,8 @@
app = Proc.new do |env|
['200', {
'Content-Length' => '0',
'Server-Port' => env['SERVER_PORT']
}, ['']]
end
run app

View File

@@ -0,0 +1,5 @@
app = Proc.new do |env|
[200, {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,5 @@
app = Proc.new |env|
['200', {'Content-Length' => '0'}, ['']]
end
run app

View File

@@ -0,0 +1,24 @@
app = Proc.new do |env|
body = env['rack.input'].read
version = env['rack.version'].join('')
['200', {
'Content-Type' => env['CONTENT_TYPE'],
'Content-Length' => body.length.to_s,
'Request-Method' => env['REQUEST_METHOD'],
'Request-Uri' => env['REQUEST_URI'],
'Http-Host' => env['HTTP_HOST'],
'Server-Protocol' => env['SERVER_PROTOCOL'],
'Custom-Header' => env['HTTP_CUSTOM_HEADER'],
'Rack-Version' => version,
'Rack-Url-Scheme' => env['rack.url_scheme'],
'Rack-Multithread' => env['rack.multithread'].to_s,
'Rack-Multiprocess' => env['rack.multiprocess'].to_s,
'Rack-Run-Once' => env['rack.run_once'].to_s,
'Rack-Hijack-Q' => env['rack.hijack?'].to_s,
'Rack-Hijack' => env['rack.hijack'].to_s,
'Rack-Hijack-IO' => env['rack.hijack_io'].to_s
}, [body]]
end
run app