basic_spec.lua 784 B

1234567891011121314151617181920212223242526272829303132333435
  1. civet = require "ci/test/civet"
  2. local curl = require "cURL"
  3. describe("civetweb basic", function()
  4. setup(function()
  5. civet.start()
  6. end)
  7. teardown(function()
  8. civet.stop()
  9. end)
  10. it("should serve a simple get request", function()
  11. local out = ""
  12. function capture(str)
  13. out = out .. str
  14. end
  15. local c = curl.easy()
  16. :setopt_url('http://localhost:' .. civet.port .. "/")
  17. :setopt_writefunction(capture)
  18. :perform()
  19. :close()
  20. --print('rescode:' .. c.getinfo(curl.INFO_RESPONSE_CODE))
  21. assert.are.equal('Index of', string.match(out, 'Index of'))
  22. assert.are.equal('01_basic_test_dir', string.match(out, '01_basic_test_dir'))
  23. assert.are.equal('01_basic_test_file', string.match(out, '01_basic_test_file'))
  24. end)
  25. end)