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
|
# File 'lib/turd/assert.rb', line 4
def self.assert(request_definition, response, response_definition)
case request_definition[:type]
when "tcp"
response_definition.each do |option, value|
if option == :response
value.each do |v|
if response[:response].include?(v)
return response
else
response.store(:failed, option)
raise AssertionFailure.new(response), "#{option} substring failure. expected #{v}, got #{response}"
end
end
elsif option == :total_time
if response[:total_time] > value
response.store(:failed, option)
raise AssertionFailure.new(response), "#{option} timing value was greater than allowed. expected #{value}, got #{response[:total_time]}"
else
return response
end
end
end
when "http"
response_definition.each do |option, value|
if option == :response_headers || option == :response_body
value.each do |v|
if !response.options[option].include?(v)
response.options.store(:failed, option)
raise AssertionFailure.new(return_http_response(response)), "#{option} substring failure. expected #{v}, got #{response.options[option]}"
end
end
elsif option.to_s.include?("_time")
if response.options[option] > value
response.options.store(:failed, option)
raise AssertionFailure.new(return_http_response(response)), "#{option} timing value was greater than allowed. expected #{value}, got #{response.options[option]}"
end
else
if response.options[option] != value
response.options.store(:failed, option)
raise AssertionFailure.new(return_http_response(response)), "#{option} did not match response definition. expected #{value}, got #{response.options[option]}"
end
end
end
when "ssh"
response_definition.each do |option, value|
case option
when :exit_status
if response[:exit_status] != value
response.store(:failed, option)
raise AssertionFailure.new(response), "Expected exit status of #{value} but got #{response[:exit_status].inspect}"
end
when :stdout
value.each do |v|
if !response[:stdout].include?(v)
response.store(:failed, option)
raise AssertionFailure.new(response), "Expected stdout to include #{v.inspect}"
end
end
end
end
return response
end
return return_http_response(response)
end
|