From e26d4f6d38554e960d8c072c5e2286817243dbe3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner <nicolas.werner@hotmail.de> Date: Sat, 26 Jun 2021 00:29:01 +0000 Subject: [PATCH 1/3] Add basic CI --- .gitlab-ci.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a131204 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,26 @@ +variables: + CCACHE_COMPILERCHECK: content + CCACHE_DIR: "${CI_PROJECT_DIR}/.ccache" + + +build: + stage: build + image: alpine:latest + tags: [docker] + before_script: + - echo 'https://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories + - apk update && apk add clang-extra-tools meson git python3 py3-pip py3-flask lcov gcovr curl-dev libevent-dev spdlog-dev grep g++ cmake pkgconf openssl + - export PATH="$PATH:/root/.local/bin" + - pip3 install --user reuse + - ./scripts/run_tls_testserver.sh & + script: + - meson setup builddir -Db_coverage=true -Dtests=true -Dexamples=true + - meson compile -C builddir + - ./builddir/tests/requests_tls -d + - kill %1 + - ./scripts/run_testserver.sh & + - sleep 2 + - ./builddir/tests/requests_tls -d + - ./builddir/examples/coeurl_example + - ninja -C builddir coverage-text + - grep TOTAL builddir/meson-logs/coverage.txt -- GitLab From d0930051a0a22936709307c2ea9f101888179d3a Mon Sep 17 00:00:00 2001 From: Nicolas Werner <nicolas.werner@hotmail.de> Date: Sat, 26 Jun 2021 03:09:39 +0200 Subject: [PATCH 2/3] Run tls server on different port --- .gitlab-ci.yml | 6 ++-- tests/requests_tls.cpp | 64 +++++++++++++++++++++--------------------- tests/testserver.py | 2 +- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a131204..a5994e0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,14 +13,12 @@ build: - export PATH="$PATH:/root/.local/bin" - pip3 install --user reuse - ./scripts/run_tls_testserver.sh & + - ./scripts/run_testserver.sh & script: - meson setup builddir -Db_coverage=true -Dtests=true -Dexamples=true - meson compile -C builddir - ./builddir/tests/requests_tls -d - - kill %1 - - ./scripts/run_testserver.sh & - - sleep 2 - - ./builddir/tests/requests_tls -d + - ./builddir/tests/requests -d - ./builddir/examples/coeurl_example - ninja -C builddir coverage-text - grep TOTAL builddir/meson-logs/coverage.txt diff --git a/tests/requests_tls.cpp b/tests/requests_tls.cpp index 9e7f3dd..d901ab1 100644 --- a/tests/requests_tls.cpp +++ b/tests/requests_tls.cpp @@ -16,8 +16,8 @@ TEST_CASE("Basic request") { Client g{}; g.set_verify_peer(false); - g.get("https://localhost:5000/", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + g.get("https://localhost:5443/", [&g](const Request &r) { + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.error_code() == CURLE_OK); CHECK(r.response() == "OK"); @@ -34,8 +34,8 @@ TEST_CASE("Basic request on bg thread") { std::thread t([&g]() { g.run(); }); - g.get("https://localhost:5000/", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + g.get("https://localhost:5443/", [&g](const Request &r) { + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response() == "OK"); CHECK(r.response_headers()["content-type"] == "text/plain; charset=utf-8"); @@ -50,9 +50,9 @@ TEST_CASE("Basic manual request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::GET, - "https://localhost:5000/"); + "https://localhost:5443/"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response() == "OK"); CHECK(r.response_headers()["content-type"] == "text/plain; charset=utf-8"); @@ -69,9 +69,9 @@ TEST_CASE("Basic redirect") { g.set_verify_peer(false); g.get( - "https://localhost:5000/redirect", + "https://localhost:5443/redirect", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/redirect"); + CHECK(r.url() == "https://localhost:5443/redirect"); CHECK(r.response_code() == 200); CHECK(r.response() == "OK"); g.close(); @@ -84,9 +84,9 @@ TEST_CASE("No redirect") { g.set_verify_peer(false); g.get( - "https://localhost:5000/redirect", + "https://localhost:5443/redirect", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/redirect"); + CHECK(r.url() == "https://localhost:5443/redirect"); CHECK(r.response_code() == 302); g.close(); }, @@ -100,9 +100,9 @@ TEST_CASE("Max redirects") { g.set_verify_peer(false); g.get( - "https://localhost:5000/double_redirect", + "https://localhost:5443/double_redirect", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/double_redirect"); + CHECK(r.url() == "https://localhost:5443/double_redirect"); CHECK(r.response_code() == 302); g.close(); }, @@ -116,10 +116,10 @@ TEST_CASE("Basic manual POST request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::POST, - "https://localhost:5000/post"); + "https://localhost:5443/post"); r->request("ABCD"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/post"); + CHECK(r.url() == "https://localhost:5443/post"); CHECK(r.response_code() == 200); CHECK(r.response() == "ABCD"); g.close(); @@ -135,10 +135,10 @@ TEST_CASE("Basic manual PUT request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::PUT, - "https://localhost:5000/put"); + "https://localhost:5443/put"); r->request("ABCD"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/put"); + CHECK(r.url() == "https://localhost:5443/put"); CHECK(r.response_code() == 200); CHECK(r.response() == "ABCD"); g.close(); @@ -154,9 +154,9 @@ TEST_CASE("Basic manual HEAD request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::HEAD, - "https://localhost:5000/"); + "https://localhost:5443/"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response().empty()); g.close(); @@ -172,9 +172,9 @@ TEST_CASE("Basic manual OPTIONS request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::OPTIONS, - "https://localhost:5000/"); + "https://localhost:5443/"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response_headers()["allow"].find("HEAD") != std::string::npos); CHECK(r.response_headers()["allow"].find("OPTIONS") != std::string::npos); @@ -193,9 +193,9 @@ TEST_CASE("Basic manual DELETE request") { g.set_verify_peer(false); auto r = std::make_shared<Request>(&g, Request::Method::DELETE, - "https://localhost:5000/delete"); + "https://localhost:5443/delete"); r->on_complete([&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/delete"); + CHECK(r.url() == "https://localhost:5443/delete"); CHECK(r.response_code() == 200); g.close(); @@ -210,9 +210,9 @@ TEST_CASE("Basic simple POST request") { Client g{}; g.set_verify_peer(false); - g.post("https://localhost:5000/post", "ABCD", "text/plain", + g.post("https://localhost:5443/post", "ABCD", "text/plain", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/post"); + CHECK(r.url() == "https://localhost:5443/post"); CHECK(r.response_code() == 200); CHECK(r.response() == "ABCD"); g.close(); @@ -225,9 +225,9 @@ TEST_CASE("Basic simple PUT request") { Client g{}; g.set_verify_peer(false); - g.put("https://localhost:5000/put", "ABCD", "text/plain", + g.put("https://localhost:5443/put", "ABCD", "text/plain", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/put"); + CHECK(r.url() == "https://localhost:5443/put"); CHECK(r.response_code() == 200); CHECK(r.response() == "ABCD"); g.close(); @@ -240,8 +240,8 @@ TEST_CASE("Basic simple HEAD request") { Client g{}; g.set_verify_peer(false); - g.head("https://localhost:5000/", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + g.head("https://localhost:5443/", [&g](const Request &r) { + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response().empty()); g.close(); @@ -254,8 +254,8 @@ TEST_CASE("Basic simple OPTIONS request") { Client g{}; g.set_verify_peer(false); - g.options("https://localhost:5000/", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/"); + g.options("https://localhost:5443/", [&g](const Request &r) { + CHECK(r.url() == "https://localhost:5443/"); CHECK(r.response_code() == 200); CHECK(r.response_headers()["allow"].find("HEAD") != std::string::npos); CHECK(r.response_headers()["allow"].find("OPTIONS") != std::string::npos); @@ -271,8 +271,8 @@ TEST_CASE("Basic simple DELETE request") { Client g{}; g.set_verify_peer(false); - g.delete_("https://localhost:5000/delete", [&g](const Request &r) { - CHECK(r.url() == "https://localhost:5000/delete"); + g.delete_("https://localhost:5443/delete", [&g](const Request &r) { + CHECK(r.url() == "https://localhost:5443/delete"); CHECK(r.response_code() == 200); g.close(); diff --git a/tests/testserver.py b/tests/testserver.py index 0916498..3ddb5a4 100755 --- a/tests/testserver.py +++ b/tests/testserver.py @@ -34,7 +34,7 @@ def test_delete(): if __name__ == "__main__": if len(sys.argv) >= 2: - app.run(debug=True, ssl_context=(sys.argv[1]+'/cert.pem', sys.argv[1]+'/key.pem')) + app.run(debug=True, ssl_context=(sys.argv[1]+'/cert.pem', sys.argv[1]+'/key.pem'), port=5443) else: app.run(debug=True) -- GitLab From c162ffc24372243945921ab1b5739053fc6ac2ec Mon Sep 17 00:00:00 2001 From: Nicolas Werner <nicolas.werner@hotmail.de> Date: Sat, 26 Jun 2021 03:23:09 +0200 Subject: [PATCH 3/3] Add junit reports --- .gitlab-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5994e0..b4d716e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,8 +17,11 @@ build: script: - meson setup builddir -Db_coverage=true -Dtests=true -Dexamples=true - meson compile -C builddir - - ./builddir/tests/requests_tls -d - - ./builddir/tests/requests -d + - ./builddir/tests/requests_tls -d --reporters=junit --out=https.xml + - ./builddir/tests/requests -d --reporters=junit --out=http.xml - ./builddir/examples/coeurl_example - ninja -C builddir coverage-text - grep TOTAL builddir/meson-logs/coverage.txt + artifacts: + reports: + junit: http*.xml -- GitLab