test-nginx icon indicating copy to clipboard operation
test-nginx copied to clipboard

Needs a Lua version

Open kikito opened this issue 12 years ago • 1 comments

Proposed syntax:

local ngxtest = require 'test_nginx'

local server = ngxtest.start_server(1989) --port

server:config(([[
  location /foo {
       set $memc_cmd set;
       set $memc_key foo;
       set $memc_value bar;
       memc_pass 127.0.0.1:%s;
  }
]]):format(ngxtest.get_memcached_port())

local response = server.request('GET', '/foo')

server:reset() -- for teardown tests

This could be used in any test library with setup/teardown, for example in busted:

local ngxtest = require 'test_nginx'
local server = ngxtest.start_server(1989)

describe('sayfoo', function()
  after_each(function()
    server:reset()
  end)
  it('works', function()
    server:config([[
      location /foo {
        init_by_lua '
          ngx.status = 200
          ngx.print('foo')
          ngx.eof()
        '
      }
    ]])
    assert.same(server:get('/foo'), {status = 200, body = 'foo', headers = {...}})
  end)
end)

This is just an example, I hope you get my point :)

kikito avatar Nov 19 '13 17:11 kikito

This would be lovely. Working with the lapis test harness which is a bit like this.

ryansch avatar Jul 30 '14 20:07 ryansch