diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/civetweb/ci/test | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/civetweb/ci/test')
-rw-r--r-- | src/civetweb/ci/test/01_basic/basic_spec.lua | 35 | ||||
-rw-r--r-- | src/civetweb/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir | 0 | ||||
-rw-r--r-- | src/civetweb/ci/test/01_basic/docroot/01_basic_test_file | 0 | ||||
-rw-r--r-- | src/civetweb/ci/test/README.md | 34 | ||||
-rw-r--r-- | src/civetweb/ci/test/civet.lua | 42 |
5 files changed, 111 insertions, 0 deletions
diff --git a/src/civetweb/ci/test/01_basic/basic_spec.lua b/src/civetweb/ci/test/01_basic/basic_spec.lua new file mode 100644 index 000000000..cf3b3007b --- /dev/null +++ b/src/civetweb/ci/test/01_basic/basic_spec.lua @@ -0,0 +1,35 @@ +civet = require "ci/test/civet" +local curl = require "cURL" + +describe("civetweb basic", function() + + setup(function() + civet.start() + end) + + teardown(function() + civet.stop() + end) + + + it("should serve a simple get request", function() + + local out = "" + function capture(str) + out = out .. str + end + + local c = curl.easy() + :setopt_url('http://localhost:' .. civet.port .. "/") + :setopt_writefunction(capture) + :perform() + :close() + + --print('rescode:' .. c.getinfo(curl.INFO_RESPONSE_CODE)) + + assert.are.equal('Index of', string.match(out, 'Index of')) + assert.are.equal('01_basic_test_dir', string.match(out, '01_basic_test_dir')) + assert.are.equal('01_basic_test_file', string.match(out, '01_basic_test_file')) + end) + +end) diff --git a/src/civetweb/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir b/src/civetweb/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/civetweb/ci/test/01_basic/docroot/01_basic_test_dir/git_keep_empty_dir diff --git a/src/civetweb/ci/test/01_basic/docroot/01_basic_test_file b/src/civetweb/ci/test/01_basic/docroot/01_basic_test_file new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/civetweb/ci/test/01_basic/docroot/01_basic_test_file diff --git a/src/civetweb/ci/test/README.md b/src/civetweb/ci/test/README.md new file mode 100644 index 000000000..fdbecbe0e --- /dev/null +++ b/src/civetweb/ci/test/README.md @@ -0,0 +1,34 @@ +== Travis CI Tests + +Travis is a service which will build your project when you commit or get pull requests on Github. + +I have fixed and extended the travis configuration to build on the new sudo-less docker infrastructure. + +=== CI Process + +* On Check-in or Pull Requests clone the repo +* Run make WITH_LUA=1 WITH_DEBUG=1 WITH_IPV6=1 WITH_WEBSOCKET=1 +* Build a standalone lua installation (seperate from civetweb or the OS) +* Build LuaRocks in standalone installation +* Install a few rocks into the standalone installation +* Start the test script + +=== test/ci_tests/01_basic/basic_spec.lua + +On the initial checkin, there is only one test which demonstrates: + +* reliably starting civetweb server on travis infrastructure +* waiting (polling) with lua.socket to establish the server is up and running +* using libcurl via lua to test that files in the specified docroot are available +* kill the civetweb server process +* waiting (polling) the server port to see that the server has freed it + +=== Adding Tests + +* Create a directory under ci_tests +* Add a spec file, so now we have ci_tests/02_my_awesome_test/awesome_spec.lua +* Any file under ci_tests which ends in _spec.lua will be automatically run +* Check out the 'busted' and lua-curl3 docs for more info +* https://github.com/Lua-cURL/Lua-cURLv3 +* http://olivinelabs.com/busted/ + diff --git a/src/civetweb/ci/test/civet.lua b/src/civetweb/ci/test/civet.lua new file mode 100644 index 000000000..19a6848f5 --- /dev/null +++ b/src/civetweb/ci/test/civet.lua @@ -0,0 +1,42 @@ +socket = require "socket" + +local civet = {} + +-- default params +civet.port=12345 +civet.max_retry=100 +civet.start_delay=0.1 + +function civet.start(docroot) + -- TODO: use a property + docroot = docroot or 'ci/test/01_basic/docroot' + assert(io.popen('./civetweb' + .. " -listening_ports " .. civet.port + .. " -document_root " .. docroot + .. " > /dev/null 2>&1 &" + )) + -- wait until the server answers + for i=1,civet.max_retry do + local s = socket.connect('127.0.0.1', civet.port) + if s then + s:close() + break + end + socket.select(nil, nil, civet.start_delay) -- sleep + end +end + +function civet.stop() + os.execute('killall civetweb') + -- wait until the server port closes + for i=1,civet.max_retry do + local s = socket.connect('127.0.0.1', civet.port) + if not s then + break + end + s:close() + socket.select(nil, nil, civet.start_delay) -- sleep + end +end + +return civet |