-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
69 lines (54 loc) · 1.71 KB
/
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
require 'minitest/autorun'
require 'rack/test'
require_relative './server'
class ServerTest < Minitest::Test
include Rack::Test::Methods
def app
$data = {}
Server.new
end
def test_put
put '/data/my-repo', 'something'
res1 = JSON.parse(last_response.body)
assert_equal 201, last_response.status
assert_equal 'application/json', last_response.content_type
assert_equal 9, res1['size']
assert res1['oid'].is_a?(String)
assert res1['oid'].length > 0
put '/data/my-repo', 'other'
res2 = JSON.parse(last_response.body)
assert_equal 201, last_response.status
assert_equal 'application/json', last_response.content_type
assert res2['oid'].is_a?(String)
assert res2['oid'].length > 0
refute_equal res1['oid'], res2['oid']
end
def test_get
put '/data/my-repo', 'something'
res1 = JSON.parse(last_response.body)
get "/data/my-repo/#{res1['oid']}"
assert_equal 200, last_response.status
assert_equal 'something', last_response.body
end
def test_get_not_found
get '/data/my-repo/missing'
assert_equal 404, last_response.status
end
def test_delete
put '/data/my-repo', 'something'
res = JSON.parse(last_response.body)
put '/data/other-repo', 'something'
dup_res = JSON.parse(last_response.body)
delete "/data/my-repo/#{res['oid']}"
assert_equal 200, last_response.status
get "/data/my-repo/#{res['oid']}"
assert_equal 404, last_response.status
get "/data/other-repo/#{dup_res['oid']}"
assert_equal 200, last_response.status
assert_equal 'something', last_response.body
end
def test_delete_not_found
delete '/data/my-repo/missing'
assert_equal 404, last_response.status
end
end