tests: allow overriding test network addresses (#6877)

You can now override the test pubsub & httpbox addresses
using environment variables in case the default addresses
don't suit your needs.

Example:
```
export CHATTERINO_TEST_PUBSUB_WSS_ADDR="127.0.0.1:20050"
export CHATTERINO_TEST_PUBSUB_WS_ADDR="127.0.0.1:20051"
export CHATTERINO_TEST_HTTPBOX_ADDR="127.0.0.1:20052"
ctest
```

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Ava Chow
2026-03-28 22:06:28 +00:00
committed by GitHub
co-authored by Rasmus Karlsson
parent 6e90f25a1a
commit df49635ac2
9 changed files with 47 additions and 21 deletions
+2 -2
View File
@@ -151,7 +151,7 @@ void MyClient::onMessage(const QByteArray &msg)
TEST(BasicPubSub, SubscriptionCycle)
{
mock::BaseApplication app;
const QString host("wss://127.0.0.1:9050/liveupdates/sub-unsub");
const QString host("wss://" + PUBSUB_WSS_ADDR + "/liveupdates/sub-unsub");
MyManager manager(host);
manager.sub({1, "foo"});
QTest::qWait(500);
@@ -184,7 +184,7 @@ TEST(BasicPubSub, SubscriptionCycle)
TEST(BasicPubSub, SubLimits)
{
mock::BaseApplication app;
const QString host("wss://127.0.0.1:9050/liveupdates/sub-unsub");
const QString host("wss://" + PUBSUB_WSS_ADDR + "/liveupdates/sub-unsub");
MyManager manager(host, 1);
manager.sub({.type = 1, .condition = "foo"});
manager.sub({.type = 2, .condition = "foo"});
+2 -1
View File
@@ -25,7 +25,8 @@ TEST(BttvLiveUpdates, AllEvents)
{
mock::BaseApplication app;
const QString host("wss://127.0.0.1:9050/liveupdates/bttv/all-events");
const QString host("wss://" + PUBSUB_WSS_ADDR +
"/liveupdates/bttv/all-events");
chatterino::BttvLiveUpdates liveUpdates(host);
std::optional<BttvLiveUpdateEmoteUpdateAddMessage> addMessage;
-7
View File
@@ -16,13 +16,6 @@
namespace chatterino {
#ifdef CHATTERINO_TEST_USE_PUBLIC_HTTPBIN
// Using our self-hosted version of httpbox https://github.com/kevinastone/httpbox
const char *const HTTPBIN_BASE_URL = "https://braize.pajlada.com/httpbox";
#else
const char *const HTTPBIN_BASE_URL = "http://127.0.0.1:9051";
#endif
class RequestWaiter
{
public:
+15 -6
View File
@@ -477,7 +477,7 @@ TEST_F(PluginTest, testHttp)
waiter.requestDone();
};
(*lua)["DoReq"](HTTPBIN_BASE_URL + c.url, c.data);
(*lua)["DoReq"](HTTPBIN_BASE_URL.toStdString().c_str() + c.url, c.data);
waiter.waitForRequest();
EXPECT_EQ(lua->get<bool>("success"), c.success);
@@ -740,8 +740,10 @@ TEST_F(PluginTest, testTcpWebSocket)
open = true;
});
lua->set("url", "ws://" + PUBSUB_WS_ADDR + "/echo");
std::shared_ptr<lua::api::WebSocket> ws = lua->script(R"lua(
local ws = c2.WebSocket.new("ws://127.0.0.1:9052/echo")
local ws = c2.WebSocket.new(url)
ws.on_text = function(data)
add(true, data)
end
@@ -816,8 +818,10 @@ TEST_F(PluginTest, testTlsWebSocket)
open = true;
});
lua->set("url", "wss://" + PUBSUB_WSS_ADDR + "/echo");
std::shared_ptr<lua::api::WebSocket> ws = lua->script(R"lua(
local ws = c2.WebSocket.new("wss://127.0.0.1:9050/echo", {
local ws = c2.WebSocket.new(url, {
headers = {
["User-Agent"] = "Lua",
["A-Header"] = "A value",
@@ -893,8 +897,10 @@ TEST_F(PluginTest, testWebSocketNoPerms)
)lua");
ASSERT_TRUE(res);
lua->set("url", "wss://" + PUBSUB_WSS_ADDR + "/echo");
const char *shouldThrow = R"lua(
return c2.WebSocket.new('wss://127.0.0.1:9050/echo')
return c2.WebSocket.new(url)
)lua";
EXPECT_ANY_THROW(lua->script(shouldThrow));
}
@@ -902,12 +908,13 @@ TEST_F(PluginTest, testWebSocketNoPerms)
TEST_F(PluginTest, testWebSocketApi)
{
configure({PluginPermission{{{"type", "Network"}}}});
lua->set("url", "wss://" + PUBSUB_WSS_ADDR + "/echo");
bool ok = lua->script(R"lua(
local t = function () end
local b = function () end
local c = function () end
local ws = c2.WebSocket.new("wss://127.0.0.1:9050/echo", {
local ws = c2.WebSocket.new(url, {
on_text = t,
on_binary = b,
on_close = c,
@@ -928,8 +935,10 @@ TEST_F(PluginTest, testWebSocketUnsetFns)
waiter.requestDone();
});
lua->set("url", "wss://" + PUBSUB_WSS_ADDR + "/echo");
lua->script(R"lua(
local ws = c2.WebSocket.new("wss://127.0.0.1:9050/echo")
local ws = c2.WebSocket.new(url)
ws.on_close = function()
done()
end
+4 -2
View File
@@ -27,7 +27,8 @@ const QString TARGET_USER_ID = "60b39e943e203cc169dfc106";
TEST(SeventvEventAPI, AllEvents)
{
mock::BaseApplication app;
const QString host("wss://127.0.0.1:9050/liveupdates/seventv/all-events");
const QString host("wss://" + PUBSUB_WSS_ADDR +
"/liveupdates/seventv/all-events");
SeventvEventAPI eventAPI(host, std::chrono::milliseconds(1000));
std::optional<EmoteAddDispatch> addDispatch;
@@ -105,7 +106,8 @@ TEST(SeventvEventAPI, AllEvents)
TEST(SeventvEventAPI, NoHeartbeat)
{
mock::BaseApplication app;
const QString host("wss://127.0.0.1:9050/liveupdates/seventv/no-heartbeat");
const QString host("wss://" + PUBSUB_WSS_ADDR +
"/liveupdates/seventv/no-heartbeat");
SeventvEventAPI eventApi(host, std::chrono::milliseconds(1000));
eventApi.subscribeUser("", EMOTE_SET_A);
+16
View File
@@ -7,6 +7,22 @@
#include <QString>
#include <QStringView>
const QString PUBSUB_WSS_ADDR =
qEnvironmentVariable("CHATTERINO_TEST_PUBSUB_WSS_ADDR", "127.0.0.1:9050");
const QString PUBSUB_WS_ADDR =
qEnvironmentVariable("CHATTERINO_TEST_PUBSUB_WS_ADDR", "127.0.0.1:9052");
#ifdef CHATTERINO_TEST_USE_PUBLIC_HTTPBIN
// Using our self-hosted version of httpbox https://github.com/kevinastone/httpbox
const QString HTTPBIN_BASE_URL =
"https://" + qEnvironmentVariable("CHATTERINO_TEST_HTTPBOX_ADDR",
"braize.pajlada.com/httpbox");
#else
const QString HTTPBIN_BASE_URL =
"http://" +
qEnvironmentVariable("CHATTERINO_TEST_HTTPBOX_ADDR", "127.0.0.1:9051");
#endif
std::ostream &operator<<(std::ostream &os, QStringView str)
{
os << str.toString().toStdString();
+4
View File
@@ -14,6 +14,10 @@ class QString;
class QStringView;
class QByteArray;
extern const QString PUBSUB_WSS_ADDR;
extern const QString PUBSUB_WS_ADDR;
extern const QString HTTPBIN_BASE_URL;
// This file is included in all TUs in chatterino-test to avoid ODR violations.
std::ostream &operator<<(std::ostream &os, QStringView str);
std::ostream &operator<<(std::ostream &os, const QByteArray &bytes);
+2 -1
View File
@@ -84,7 +84,8 @@ class FTest : public PubSub
{
public:
explicit FTest(const char *path, std::chrono::seconds pingInterval)
: PubSub(QString("wss://127.0.0.1:9050%1").arg(path), pingInterval)
: PubSub(QString("wss://%1%2").arg(PUBSUB_WSS_ADDR).arg(path),
pingInterval)
{
}
};
+2 -2
View File
@@ -65,7 +65,7 @@ TEST(WebSocketPool, tcpEcho)
auto handle = pool.createSocket(
{
.url = QUrl("ws://127.0.0.1:9052/echo?query=123&xd=wow"),
.url = QUrl("ws://" + PUBSUB_WS_ADDR + "/echo?query=123&xd=wow"),
.headers =
{
{"My-Header", "my-header-VALUE"},
@@ -131,7 +131,7 @@ TEST(WebSocketPool, tlsEcho)
auto handle = pool.createSocket(
{
.url = QUrl("wss://127.0.0.1:9050/echo"),
.url = QUrl("wss://" + PUBSUB_WSS_ADDR + "/echo"),
.headers{
{"My-Header", "my-header-VALUE"},
{"Another-Header", "other-header"},