Skip to content

Instantly share code, notes, and snippets.

@vdel26
Created April 4, 2016 13:25
Show Gist options
  • Save vdel26/be95e644b64a656f90013fb3f794b9b5 to your computer and use it in GitHub Desktop.
Save vdel26/be95e644b64a656f90013fb3f794b9b5 to your computer and use it in GitHub Desktop.
Test matching, capturing values in input URL and using them in rewrites
package.path = package.path .. ';../?.lua;test/?.lua'
require 'test_helper'
local services = require 'fixtures'
local matcher = require 'matcher'
local metric_builder = require 'metric_builder'
local rules = {
['GET api.domain.com/fronts/{source_id}/news'] = {
service_id = '16', source_scheme = 'http', target_scheme = 'http',
target_hostname = 'usat.com_80', target_path = '/syndication/fronts/{source_id}/news',
target_host_header = 'usat.com:80', threescale_method = 'fronts_news',
extra_query_params = '', delta = 1
}
}
local sorted_rules = require('sorted-rules').sorted_rules(rules)
local tests = {
['mapping capture from path to rewritten path'] = function()
ngx = n.new()
local rule, extra_path, captures = matcher.get_matched_rule('GET', 'api.domain.com', '/fronts/usat/news', sorted_rules)
assert_equal('16', rule.service_id)
assert_equal('fronts_news', rule.threescale_method)
local raw_usage = metric_builder.set_vars(services, rule, { user_key = 'apiKey' }, '', '', captures)
assert_equal('http://backend_usat.com_80/syndication/fronts/usat/news', ngx.var.proxy_pass)
end
}
return runtests(tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment