diff options
author | prettyboy <prettyboy@yandex-team.com> | 2023-04-06 18:10:10 +0300 |
---|---|---|
committer | prettyboy <prettyboy@yandex-team.com> | 2023-04-06 18:10:10 +0300 |
commit | cf01db4c44585761db33d3f41fd3fe41a9acd70b (patch) | |
tree | e6cff885a2539e5918d897703a57b5b0bd87f9b8 | |
parent | 208c5b52d89a6f0103b8b447cf2c9b6120cb772d (diff) | |
download | ydb-cf01db4c44585761db33d3f41fd3fe41a9acd70b.tar.gz |
[library/cpp/testing/common/ut/env] Added GetGlobalResource function to obtain global resources from context file
-rw-r--r-- | library/cpp/testing/common/env.cpp | 15 | ||||
-rw-r--r-- | library/cpp/testing/common/env.h | 4 | ||||
-rw-r--r-- | library/cpp/testing/common/ut/env_ut.cpp | 13 |
3 files changed, 32 insertions, 0 deletions
diff --git a/library/cpp/testing/common/env.cpp b/library/cpp/testing/common/env.cpp index fa3a47fe16..77c6b0d90b 100644 --- a/library/cpp/testing/common/env.cpp +++ b/library/cpp/testing/common/env.cpp @@ -107,6 +107,13 @@ const TString& GetTestParam(TStringBuf name, const TString& def) { return def; } +const TString& GetGlobalResource(TStringBuf name) { + auto& resources = NPrivate::GetTestEnv().GlobalResources; + auto it = resources.find(name.data()); + Y_VERIFY(it != resources.end()); + return it->second; +} + void AddEntryToCoreSearchFile(const TString& filename, TStringBuf cmd, int pid, const TFsPath& binaryPath = TFsPath(), const TFsPath& cwd = TFsPath()) { auto lock = TFileLock(filename); TGuard<TFileLock> guard(lock); @@ -164,6 +171,7 @@ namespace NPrivate { GdbPath = ""; CoreSearchFile = ""; TestParameters.clear(); + GlobalResources.clear(); const TString contextFilename = GetEnv("YA_TEST_CONTEXT_FILE"); if (contextFilename) { @@ -219,6 +227,13 @@ namespace NPrivate { } } + value = context.GetValueByPath("resources.global"); + if (value) { + for (const auto& entry : value->GetMap()) { + GlobalResources[entry.first] = entry.second.GetStringSafe(""); + } + } + value = context.GetValueByPath("internal.core_search_file"); if (value) { CoreSearchFile = value->GetStringSafe(""); diff --git a/library/cpp/testing/common/env.h b/library/cpp/testing/common/env.h index 7b89aa1bed..6dbef4959b 100644 --- a/library/cpp/testing/common/env.h +++ b/library/cpp/testing/common/env.h @@ -45,6 +45,9 @@ const TString& GetTestParam(TStringBuf name); // @brief return test parameter by name. If not exists, return specified default value const TString& GetTestParam(TStringBuf name, const TString& def); +// @brief return path to global resource. If not exists, aborts the test run +const TString& GetGlobalResource(TStringBuf name); + // @brief return path to the gdb const TString& GdbPath(); @@ -76,6 +79,7 @@ namespace NPrivate { TString GdbPath; TString CoreSearchFile; std::unordered_map<TString, TString> TestParameters; + std::unordered_map<TString, TString> GlobalResources; }; TString GetCwd(); diff --git a/library/cpp/testing/common/ut/env_ut.cpp b/library/cpp/testing/common/ut/env_ut.cpp index 2aed1e4a25..fe4946a65f 100644 --- a/library/cpp/testing/common/ut/env_ut.cpp +++ b/library/cpp/testing/common/ut/env_ut.cpp @@ -160,3 +160,16 @@ TEST(Runtime, WatchProcessCore) { )json"; EXPECT_EQ(expected, data); } + +TEST(Runtime, GlobalResources) { + TString context = R"json({ + "resources": { + "global": { + "TOOL_NAME_RESOURCE_GLOBAL": "path" + } + } + })json"; + + auto filename = ReInitializeContext(context); + EXPECT_EQ("path", GetGlobalResource("TOOL_NAME_RESOURCE_GLOBAL")); +} |