Files
amnezia-client/client/tests/utils/testUtils.cpp
T
NickVs2015andMrMirDan b76c88bba3 feat: migrate test to main repo (#3172)
* basic tests  adaptation

* fix: ui servers model and controller test awg config

* fix: platforms test builds

* build dirs inspection

* fix: changed paths for tests and tests artifacts

* fix: 'deploy' parent dir

* windows ctest configuration and macos dependencies inspection

* windows check executable and macos copy openssl libs

* windows test executables check and macos copy openssl

* changed some path on windows

* android apk list

* fix: updated android apk path

* Verify Android test files

* fix: build tests only with AMNEZIA_BUILD_TESTS

* fix: copy openssl runtime next to test_openssl_library

* fix: awg2 test config and inverted description checks

* chore: move run_android_tests.sh to client/tests and drop personal paths

* chore: gate tests by option, scope secrets and drop global concurrency in ci

* chore: serialized vps test job, scoped secrets, backup secret guard, test data lookup

---------

Co-authored-by: MrMirDan <8mirdan8@gmail.com>
2026-09-16 17:05:43 +08:00

74 lines
2.2 KiB
C++

#include "utils/testUtils.h"
#include <QByteArray>
#include <QDebug>
#include "core/repositories/secureServersRepository.h"
#include "core/utils/serverConfigUtils.h"
namespace amnezia::test
{
QString getEnvValue(const QString &key)
{
const QByteArray keyUtf8 = key.toUtf8();
if (qEnvironmentVariableIsSet(keyUtf8.constData())) {
return qEnvironmentVariable(keyUtf8.constData());
}
return QString();
}
void logEnvValueState(const QString &key)
{
const QString value = getEnvValue(key);
qInfo().noquote() << QString("%1: configured=%2 length=%3 value=\"%4\"")
.arg(key,
isEnvValueConfigured(value) ? "yes" : "no",
QString::number(value.size()),
value);
}
bool isEnvValueConfigured(const QString &value)
{
const QString trimmed = value.trimmed();
if (trimmed.isEmpty()) {
return false;
}
if (trimmed.endsWith(QStringLiteral("_config_string"))) {
return false;
}
return true;
}
std::optional<QString> serverDescription(SecureServersRepository *repo, const QString &serverId)
{
switch (repo->serverKind(serverId)) {
case serverConfigUtils::ConfigType::SelfHostedAdmin: {
const auto cfg = repo->selfHostedAdminConfig(serverId);
return cfg ? std::optional<QString>(cfg->description) : std::nullopt;
}
case serverConfigUtils::ConfigType::SelfHostedUser: {
const auto cfg = repo->selfHostedUserConfig(serverId);
return cfg ? std::optional<QString>(cfg->description) : std::nullopt;
}
case serverConfigUtils::ConfigType::Native: {
const auto cfg = repo->nativeConfig(serverId);
return cfg ? std::optional<QString>(cfg->description) : std::nullopt;
}
case serverConfigUtils::ConfigType::AmneziaPremiumV2: {
const auto cfg = repo->apiV2Config(serverId);
return cfg ? std::optional<QString>(cfg->description) : std::nullopt;
}
default:
return std::nullopt;
}
}
std::optional<QString> serverDescriptionAt(SecureServersRepository *repo, int index)
{
return serverDescription(repo, repo->serverIdAt(index));
}
} // namespace amnezia::test