-
Notifications
You must be signed in to change notification settings - Fork 42
/
simple_test.rb
79 lines (66 loc) · 2.37 KB
/
simple_test.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
require 'test/unit'
require 'digest/sha1'
require File.join(File.dirname(__FILE__), 'http_test_helper.rb')
require File.join(File.dirname(__FILE__), 'zlib_helper.rb')
class Simple < Test::Unit::TestCase
include HttpTestHelper
def setup
init_http "localhost:8087"
@put_domain = "test01.net.put"
@std_domain = "test01.net"
@put_domain2 = "test02.net.put"
@std_domain2 = "test02.net"
end
def assert_stored
assert_last_response "200", "text/plain", "STORED"
end
def test_simple
put '/toto', 'this content', @put_domain
assert_stored
get '/toto', @std_domain
assert_last_response "200", "application/octet-stream", 'this content'
assert_not_nil @resp['Date']
end
def test_simple_multi_domain
delete '/toto', @put_domain
delete '/toto', @put_domain2
put '/toto', 'this content', @put_domain
assert_stored
get '/toto', @std_domain
assert_last_response "200", "application/octet-stream", 'this content'
get '/toto', @std_domain2
assert_last_response "200", "application/octet-stream", 'this content'
end
def test_specific_headers
put '/toto', 'myTest', @put_domain
assert_stored
get '/toto', @std_domain
assert_last_response "200", "application/octet-stream", 'myTest'
get '/toto', @std_domain, {"Pragma" => "no-cache;"}
assert_not_equal "200", @resp.code
get '/toto', @std_domain, {"Cache-Control" => "no-cache;"}
assert_not_equal "200", @resp.code
head '/toto', @std_domain
assert_not_equal "200", @resp.code
assert_not_equal "405", @resp.code
get '/toto', @std_domain
assert_last_response "200", "application/octet-stream", 'myTest'
end
def test_image
png = load_bin_file('show_48.png')
assert_equal Digest::SHA1.hexdigest(png), '15ad4ab1b2b651cfd04aa83ae251a5ff06e2bf05'
put '/png', "EXTRACT_HEADERS\r\nContent-Type: image/png\r\n\r\n" + png, @put_domain
assert_stored
get '/png', @std_domain
assert_last_response "200", "image/png", png
assert_equal Digest::SHA1.hexdigest(@resp.body), '15ad4ab1b2b651cfd04aa83ae251a5ff06e2bf05'
assert_equal nil, @resp['Content-Encoding']
assert_not_nil @resp['Date']
end
def test_serve_static
get '/small.html', @std_domain
assert_last_response "200", "text/html", load_bin_file('small.html')
get '/small2.html', @std_domain
assert_last_response "404", "text/html"
end
end