Skip to content

Commit

Permalink
spec/http_proxy_spec.lua: very basic unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Feb 5, 2024
1 parent 2673754 commit 54d26f7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions spec/http_proxy_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

describe('http_proxy', function()
describe('.request', function()
local function stub_ngx_request()
ngx.var = { }

stub(ngx, 'exit')
stub(ngx.req, 'get_headers', function() return { } end)
stub(ngx.req, 'get_method', function() return 'GET' end)
end

local function stub_resty_http_proxy()
local httpc = {
}

local response = {}
stub(httpc, 'request', function() return response end)
stub(httpc, 'proxy_response')
stub(httpc, 'set_keepalive')

local resty_http_proxy = require 'resty.http.proxy'
stub(resty_http_proxy, 'new', function() return httpc end)
end

before_each(function()
stub_ngx_request()
stub_resty_http_proxy()
end)

describe('on https backend', function()
local upstream = {
uri = {
scheme = 'https'
},
request_unbuffered = false,
skip_https_connect = false
}
local proxy_uri = {
}

before_each(function()
stub(upstream, 'rewrite_request')
end)

it('terminates phase', function()
local http_proxy = require('apicast.http_proxy')
http_proxy.request(upstream, proxy_uri)
assert.spy(ngx.exit).was_called_with(ngx.OK)
end)
end)
end)
end)

0 comments on commit 54d26f7

Please sign in to comment.