From b198438f2568f124971053c7f804fd986dff68ba Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 30 May 2022 01:43:13 +0200 Subject: [PATCH] Run httpbin docker image locally in CI (#3778) --- .github/workflows/test.yml | 2 ++ tests/README.md | 8 ++++++++ tests/src/NetworkRequest.cpp | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 tests/README.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe1e5ceda..8ba250038 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,8 +83,10 @@ jobs: - name: Test (Ubuntu) if: startsWith(matrix.os, 'ubuntu') run: | + docker pull kennethreitz/httpbin docker pull ${{ env.TWITCH_PUBSUB_SERVER_IMAGE }} docker run --network=host --detach ${{ env.TWITCH_PUBSUB_SERVER_IMAGE }} + docker run -p 9051:80 --detach kennethreitz/httpbin ./bin/chatterino-test --platform minimal working-directory: build-test shell: bash diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..449e59013 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,8 @@ +To run tests all tests you will need to run the `kennethreitz/httpbin` and `ghcr.io/chatterino/twitch-pubsub-server-test:latest` docker images + +For example: + +```bash +docker run --network=host --detach ghcr.io/chatterino/twitch-pubsub-server-test:latest +docker run -p 9051:80 --detach kennethreitz/httpbin +``` diff --git a/tests/src/NetworkRequest.cpp b/tests/src/NetworkRequest.cpp index 8af91514f..96d62ca4b 100644 --- a/tests/src/NetworkRequest.cpp +++ b/tests/src/NetworkRequest.cpp @@ -13,9 +13,17 @@ using namespace chatterino; namespace { -static QString getStatusURL(int code) +// Change to http://httpbin.org if you don't want to run the docker image yourself to test this +const char *const HTTPBIN_BASE_URL = "http://127.0.0.1:9051"; + +QString getStatusURL(int code) { - return QString("http://httpbin.org/status/%1").arg(code); + return QString("%1/status/%2").arg(HTTPBIN_BASE_URL).arg(code); +} + +QString getDelayURL(int delay) +{ + return QString("%1/delay/%2").arg(HTTPBIN_BASE_URL).arg(delay); } } // namespace @@ -201,7 +209,7 @@ TEST(NetworkRequest, TimeoutTimingOut) { EXPECT_TRUE(NetworkManager::workerThread.isRunning()); - auto url = "http://httpbin.org/delay/5"; + auto url = getDelayURL(5); std::mutex mut; bool requestDone = false; @@ -248,7 +256,7 @@ TEST(NetworkRequest, TimeoutNotTimingOut) { EXPECT_TRUE(NetworkManager::workerThread.isRunning()); - auto url = "http://httpbin.org/delay/1"; + auto url = getDelayURL(1); std::mutex mut; bool requestDone = false; @@ -293,7 +301,7 @@ TEST(NetworkRequest, FinallyCallbackOnTimeout) { EXPECT_TRUE(NetworkManager::workerThread.isRunning()); - auto url = "http://httpbin.org/delay/5"; + auto url = getDelayURL(5); std::mutex mut; bool requestDone = false;