From 3762c59552f4901d26c2b267f894f48fc5d319f1 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:52:20 -0800 Subject: [PATCH] Test proxy start (#4295) * lll * sss * oipio * vcvc * enable test proxy start at test suite start for KV and storage , example created for attestation, we cannot find the base definitions for the test suites, * Contrib * clangs * clangs * test logs * pipeline * more clangs * pipeline * clang * try try again * try try again * try again * try again * again * update paths , moved to macro , call macro in target code * core * capitalization --- .vscode/cspell.json | 1 + CONTRIBUTING.md | 5 ++++ cmake-modules/TestProxyPrep.cmake | 9 ++++--- eng/pipelines/templates/jobs/ci.tests.yml | 3 +++ eng/scripts/Start-TestProxy.ps1 | 4 +-- .../test/ut/CMakeLists.txt | 3 +++ .../test/ut/tpmattestation_test.cpp | 3 +++ sdk/core/azure-core-test/CMakeLists.txt | 3 +++ .../inc/azure/core/test/test_base.hpp | 27 ++++++++++++++++++- .../test/ut/CMakeLists.txt | 5 +++- .../test/ut/settings_client_base_test.hpp | 2 ++ .../test/ut/CMakeLists.txt | 3 +++ .../test/ut/certificate_client_base_test.hpp | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/key_client_base_test.hpp | 3 +++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/secret_client_base_test.hpp | 3 +++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/test_base.hpp | 3 +++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ 23 files changed, 86 insertions(+), 7 deletions(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index b490dd7bf..0164a40f2 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -80,6 +80,7 @@ "IMDS", "immutability", "Intel", + "isoutput", "issecret", "itfactor", "iusg", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d76be24ab..ef6bbec83 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -207,6 +207,11 @@ Even for running on `PLAYBACK` mode, the env configuration is mandatory. This is Take a look to [this file](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/core/ci.yml#L52) which defines the required configuarion for each SDK package. Those settings are used to run all unit test on `PLAYBACK` mode on CI, you can use the same settings from that file to run on `PLAYBACK` locally. +##### Test-Proxy + +Recording and playing back tests depends on an external tool called "test-proxy" (see doc/TestProxy.md) +You can start this tool manually or autmatically as part of you development flow. +For automatic start you will need to set the environment variable "AZURE_TEST_USE_TEST_PROXY" to value "ON". ##### Running tests diff --git a/cmake-modules/TestProxyPrep.cmake b/cmake-modules/TestProxyPrep.cmake index dc4005353..11ff1d4ad 100644 --- a/cmake-modules/TestProxyPrep.cmake +++ b/cmake-modules/TestProxyPrep.cmake @@ -2,9 +2,12 @@ # SPDX-License-Identifier: MIT # -macro(CopyTestProxyScripts) - file(COPY ${CMAKE_SOURCE_DIR}/eng/Scripts/Start-TestProxy.ps1 +macro(SetUpTestProxy subDir) + # assets.json dir + add_compile_definitions(AZURE_TEST_ASSETS_DIR="${AZ_ROOT_DIR}/${subDir}/") + #copy start stop scripts to the bin folder + file(COPY ${AZ_ROOT_DIR}/eng/scripts/Start-TestProxy.ps1 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - file(COPY ${CMAKE_SOURCE_DIR}/eng/Scripts/Stop-TestProxy.ps1 + file(COPY ${AZ_ROOT_DIR}/eng/scripts/Stop-TestProxy.ps1 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) endmacro() diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml index d003ab96e..81879063f 100644 --- a/eng/pipelines/templates/jobs/ci.tests.yml +++ b/eng/pipelines/templates/jobs/ci.tests.yml @@ -186,6 +186,7 @@ jobs: workingDirectory: '$(Build.SourcesDirectory)/sdk/${{parameters.ServiceDirectory}}' displayName: Restore Recordings condition: and(succeeded(), contains(variables.CmakeArgs, 'BUILD_TESTING=ON'), ne('${{parameters.ServiceDirectory}}', 'core'),ne('${{parameters.ServiceDirectory}}', 'template')) + name: RestoreRecordings - pwsh: | ctest ` @@ -200,7 +201,9 @@ jobs: - ${{ parameters.PostTestSteps }} + - pwsh: | + $ErrorActionPreference = 'SilentlyContinue' get-content test-proxy.log displayName: TestProxy Log condition: and(succeededOrFailed(), contains(variables.CmakeArgs, 'BUILD_TESTING=ON'),ne('${{parameters.ServiceDirectory}}', 'template')) diff --git a/eng/scripts/Start-TestProxy.ps1 b/eng/scripts/Start-TestProxy.ps1 index d4f9f5b13..bf83162e4 100644 --- a/eng/scripts/Start-TestProxy.ps1 +++ b/eng/scripts/Start-TestProxy.ps1 @@ -37,6 +37,6 @@ if($error){ } } -echo "Start test proxy with argument list --storage-location $AssetsPath" +echo "Start test proxy with argument list -l $AssetsPath" #starts it in a separate process that will outlive pwsh in order to serve requests. -Start-Process 'test-proxy' -ArgumentList "--storage-location $AssetsPath" +Start-Process 'test-proxy' -ArgumentList "start -l $AssetsPath" -WorkingDirectory $AssetsPath diff --git a/sdk/attestation/azure-security-attestation/test/ut/CMakeLists.txt b/sdk/attestation/azure-security-attestation/test/ut/CMakeLists.txt index 37a46505a..7fd135df8 100644 --- a/sdk/attestation/azure-security-attestation/test/ut/CMakeLists.txt +++ b/sdk/attestation/azure-security-attestation/test/ut/CMakeLists.txt @@ -17,6 +17,9 @@ add_compile_definitions(AZURE_TEST_DATA_PATH="${CMAKE_BINARY_DIR}") # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/attestation") + include(GoogleTest) add_executable ( diff --git a/sdk/attestation/azure-security-attestation/test/ut/tpmattestation_test.cpp b/sdk/attestation/azure-security-attestation/test/ut/tpmattestation_test.cpp index d4ba3639c..c7a72698c 100644 --- a/sdk/attestation/azure-security-attestation/test/ut/tpmattestation_test.cpp +++ b/sdk/attestation/azure-security-attestation/test/ut/tpmattestation_test.cpp @@ -25,6 +25,9 @@ namespace Azure { namespace Security { namespace Attestation { namespace Test { // cspell: words aikcert class TpmAttestationTests : public Azure::Core::Test::TestBase { + public: + TpmAttestationTests() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); }; + private: protected: std::shared_ptr m_credential; diff --git a/sdk/core/azure-core-test/CMakeLists.txt b/sdk/core/azure-core-test/CMakeLists.txt index 302d57a85..984d88c42 100644 --- a/sdk/core/azure-core-test/CMakeLists.txt +++ b/sdk/core/azure-core-test/CMakeLists.txt @@ -30,6 +30,9 @@ add_library ( ${AZURE_CORE_TEST_SOURCE} ) +include(TestProxyPrep) +SetUpTestProxy("sdk/core") + if (MSVC) # - C6326: Google comparisons target_compile_options(azure-core-test-fw PUBLIC /wd6326) diff --git a/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp b/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp index 7e21bd6a1..f56ff6b73 100644 --- a/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp +++ b/sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp @@ -406,9 +406,34 @@ namespace Azure { namespace Core { namespace Test { */ void TearDown() override; + void SetUpTestSuiteLocal(std::string const& assetsPath) + { + if (Azure::Core::_internal::Environment::GetVariable("AZURE_TEST_USE_TEST_PROXY") == "ON") + { + std::string finalAsets(assetsPath); + std::string pwshCommand + = "pwsh -NoProfile -ExecutionPolicy Unrestricted Start-TestProxy.ps1 -AssetsPath " + + finalAsets; + int result = system(pwshCommand.c_str()); + if (result != 0) + { + std::cout << "Non zero exit code for start proxy : " << result; + } + } + }; + + static void TearDownTestSuite() + { + if (Azure::Core::_internal::Environment::GetVariable("AZURE_TEST_USE_TEST_PROXY") == "ON") + { + int result + = std::system("pwsh -NoProfile -ExecutionPolicy Unrestricted Stop-TestProxy.ps1"); + std::cout << "Non zero exit code for stop proxy : " << result; + } + }; /** * Returns the assets.json file path used when invoking the test-proxy playback/record */ - virtual std::string GetAssetsPath() { return "assets.json"; } + static std::string GetAssetsPath() { return "assets.json"; } }; }}} // namespace Azure::Core::Test diff --git a/sdk/keyvault/azure-security-keyvault-administration/test/ut/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-administration/test/ut/CMakeLists.txt index 6e060fb51..e0d3e1d63 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/test/ut/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-administration/test/ut/CMakeLists.txt @@ -8,10 +8,13 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED True) include(GoogleTest) - +include(TestProxyPrep) +SetUpTestProxy("sdk/keyvault") # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +# Additional test files to be copied to the output directory. + add_executable ( azure-security-keyvault-administration-test macro_guard.cpp diff --git a/sdk/keyvault/azure-security-keyvault-administration/test/ut/settings_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-administration/test/ut/settings_client_base_test.hpp index f7e03cd28..5dd4d4ed1 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/test/ut/settings_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-administration/test/ut/settings_client_base_test.hpp @@ -79,5 +79,7 @@ namespace Azure { { return Azure::Core::Test::TestBase::GetTestNameSuffix(sanitize); } + + SettingsClientTest() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); } }; }}}}} // namespace Azure::Security::KeyVault::Administration::Test diff --git a/sdk/keyvault/azure-security-keyvault-certificates/test/ut/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-certificates/test/ut/CMakeLists.txt index 20a567863..75d5bbd2c 100644 --- a/sdk/keyvault/azure-security-keyvault-certificates/test/ut/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-certificates/test/ut/CMakeLists.txt @@ -12,6 +12,9 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/keyvault") + add_executable ( azure-security-keyvault-certificates-test macro_guard.cpp diff --git a/sdk/keyvault/azure-security-keyvault-certificates/test/ut/certificate_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-certificates/test/ut/certificate_client_base_test.hpp index 36005af5a..f5073271c 100644 --- a/sdk/keyvault/azure-security-keyvault-certificates/test/ut/certificate_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-certificates/test/ut/certificate_client_base_test.hpp @@ -43,6 +43,8 @@ namespace Azure { class KeyVaultCertificateClientTest : public Azure::Core::Test::TestBase, public ::testing::WithParamInterface { + public: + KeyVaultCertificateClientTest() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); } private: std::unique_ptr m_client; diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt index 1acc71819..f1154f625 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/keyvault") ################## Unit Tests ########################## add_executable ( diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp index ce85c0626..d9a6c7915 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_base_test.hpp @@ -23,6 +23,9 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace Test { class KeyVaultKeyClient : public Azure::Core::Test::TestBase { + public: + KeyVaultKeyClient() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); } + private: std::unique_ptr m_client; diff --git a/sdk/keyvault/azure-security-keyvault-secrets/test/ut/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-secrets/test/ut/CMakeLists.txt index 146720e94..833342f8b 100644 --- a/sdk/keyvault/azure-security-keyvault-secrets/test/ut/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-secrets/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/keyvault") add_executable ( azure-security-keyvault-secrets-test diff --git a/sdk/keyvault/azure-security-keyvault-secrets/test/ut/secret_client_base_test.hpp b/sdk/keyvault/azure-security-keyvault-secrets/test/ut/secret_client_base_test.hpp index 9897ef30f..e78f8c2c1 100644 --- a/sdk/keyvault/azure-security-keyvault-secrets/test/ut/secret_client_base_test.hpp +++ b/sdk/keyvault/azure-security-keyvault-secrets/test/ut/secret_client_base_test.hpp @@ -18,6 +18,9 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets { class KeyVaultSecretClientTest : public Azure::Core::Test::TestBase, public ::testing::WithParamInterface { + public: + KeyVaultSecretClientTest() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); } + private: std::unique_ptr m_client; diff --git a/sdk/storage/azure-storage-blobs/test/ut/CMakeLists.txt b/sdk/storage/azure-storage-blobs/test/ut/CMakeLists.txt index 0b21c02a4..8b561f70c 100644 --- a/sdk/storage/azure-storage-blobs/test/ut/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/storage") add_executable ( azure-storage-blobs-test diff --git a/sdk/storage/azure-storage-common/test/ut/CMakeLists.txt b/sdk/storage/azure-storage-common/test/ut/CMakeLists.txt index 3e3ef7435..79d9faa78 100644 --- a/sdk/storage/azure-storage-common/test/ut/CMakeLists.txt +++ b/sdk/storage/azure-storage-common/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/storage") add_executable ( azure-storage-common-test diff --git a/sdk/storage/azure-storage-common/test/ut/test_base.hpp b/sdk/storage/azure-storage-common/test/ut/test_base.hpp index 6fc59a4e0..05f28531a 100644 --- a/sdk/storage/azure-storage-common/test/ut/test_base.hpp +++ b/sdk/storage/azure-storage-common/test/ut/test_base.hpp @@ -26,6 +26,9 @@ namespace Azure { namespace Storage { namespace Test { class StorageTest : public Azure::Core::Test::TestBase { + public: + StorageTest() { TestBase::SetUpTestSuiteLocal(AZURE_TEST_ASSETS_DIR); } + protected: const std::string& StandardStorageConnectionString(); const std::string& PremiumStorageConnectionString(); diff --git a/sdk/storage/azure-storage-files-datalake/test/ut/CMakeLists.txt b/sdk/storage/azure-storage-files-datalake/test/ut/CMakeLists.txt index 13dce96db..2eda8f39a 100644 --- a/sdk/storage/azure-storage-files-datalake/test/ut/CMakeLists.txt +++ b/sdk/storage/azure-storage-files-datalake/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/storage") add_executable ( azure-storage-files-datalake-test diff --git a/sdk/storage/azure-storage-files-shares/test/ut/CMakeLists.txt b/sdk/storage/azure-storage-files-shares/test/ut/CMakeLists.txt index 7b2c33e4b..debd0d9c5 100644 --- a/sdk/storage/azure-storage-files-shares/test/ut/CMakeLists.txt +++ b/sdk/storage/azure-storage-files-shares/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/storage") add_executable ( azure-storage-files-shares-test diff --git a/sdk/storage/azure-storage-queues/test/ut/CMakeLists.txt b/sdk/storage/azure-storage-queues/test/ut/CMakeLists.txt index 301dd9d4b..7403d1f04 100644 --- a/sdk/storage/azure-storage-queues/test/ut/CMakeLists.txt +++ b/sdk/storage/azure-storage-queues/test/ut/CMakeLists.txt @@ -11,6 +11,8 @@ include(GoogleTest) # Export the test folder for recordings access. add_compile_definitions(AZURE_TEST_RECORDING_DIR="${CMAKE_CURRENT_LIST_DIR}") +include(TestProxyPrep) +SetUpTestProxy("sdk/storage") add_executable ( azure-storage-queues-test