Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
agruss committed Jun 3, 2015
1 parent daa6d02 commit eb71178
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
44 changes: 44 additions & 0 deletions features/step_definitions/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
When /^I request post I should get$/ do |table|
reprocess
actual = []
OSRMLoader.load(self,"#{prepared_file}.osrm") do
table.hashes.each_with_index do |row,ri|
request_string = row['request'].split("?")
got = {'request' => row['request'] }
response = request_post_url request_string[0], request_string[1]

row.each_pair do |k,v|
if k =~ /param:(.*)/
if v=='(nil)'
params[$1]=nil
elsif v!=nil
params[$1]=v
end
got[k]=v
end
end

if table.headers.include? 'status_code'
# the only thing we want to test is
# an accepted request
got['status_code'] = response.code.to_s
end

ok = true
row.keys.each do |key|
if FuzzyMatch.match got[key], row[key]
got[key] = row[key]
else
ok = false
end
end

unless ok
log_fail row,got, { 'route' => {:query => @query, :response => response} }
end

actual << got
end
end
table.diff! actual
end
23 changes: 23 additions & 0 deletions features/support/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'net/http'

HOST = "http://127.0.0.1:#{OSRM_PORT}"

def request_post_url service, param_string
uri = URI.parse"#{HOST}/#{service}"
@query = uri.to_s
Timeout.timeout(OSRM_TIMEOUT) do
params = {}
values = param_string.split("loc=")
locs = []
values.each do |value|
locs << "#{value}".gsub(/[&]/, '')
end
locs.reject! { |c| c.empty? }
params.merge!(loc: locs)
Net::HTTP.post_form uri, params
end
rescue Errno::ECONNREFUSED => e
raise "*** osrm-routed is not running."
rescue Timeout::Error
raise "*** osrm-routed did not respond."
end
23 changes: 23 additions & 0 deletions features/testbot/post.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@post @testbot
Feature: POST request

Background:
Given the profile "testbot"

Scenario: Accept POST Request
Given the node locations
| node | lat | lon |
| a | 1.00 | 1.00 |
| b | 1.01 | 1.00 |

And the ways
| nodes |
| ab |

When I request post I should get
| request | status_code |
| locate?loc=1.0,1.0 | 200 |
| nearest?loc=1.0,1.0 | 200 |
| viaroute?loc=1,1&loc=1.01,1 | 200 |
| match?loc=1,1&loc=1.01,1 | 200 |
| table?loc=1,1&loc=1.01,1 | 200 |

0 comments on commit eb71178

Please sign in to comment.