Update to use AWSNativeSDK 1.9.50 (#6618)
* Update to use AWSNativeSDK 1.9.50 * After SDK upgrade, some AWS objects are bound to SDK allocator, init AWS SDK for unit test
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <Configuration/AWSCoreConfiguration.h>
|
||||
#include <ResourceMapping/AWSResourceMappingConstants.h>
|
||||
@@ -112,31 +111,21 @@ public:
|
||||
m_resourceMappingManager = AZStd::make_unique<AWSCore::AWSResourceMappingManager>();
|
||||
}
|
||||
|
||||
void CreateTestConfigFile(const AZStd::string& configContent)
|
||||
{
|
||||
m_normalizedConfigFilePath = AZStd::string::format("%s/%s", m_normalizedConfigFolderPath.c_str(), "test_aws_resource_mappings.json");
|
||||
AzFramework::StringFunc::Path::Normalize(m_normalizedConfigFilePath);
|
||||
CreateTestFile(m_normalizedConfigFilePath, configContent);
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
AWSCoreFixture::SetUpFixture(false);
|
||||
|
||||
m_normalizedSourceProjectFolder = AZStd::string::format("%s/%s%s/", AZ::Test::GetCurrentExecutablePath().c_str(),
|
||||
"AWSResourceMappingManager", AZ::Uuid::CreateRandom().ToString<AZStd::string>(false, false).c_str());
|
||||
AzFramework::StringFunc::Path::Normalize(m_normalizedSourceProjectFolder);
|
||||
m_normalizedConfigFolderPath = AZStd::string::format("%s/%s/",
|
||||
m_normalizedSourceProjectFolder.c_str(), AWSCore::AWSCoreConfiguration::AWSCoreResourceMappingConfigFolderName);
|
||||
AzFramework::StringFunc::Path::Normalize(m_normalizedConfigFolderPath);
|
||||
m_configFilePath = (GetTestTempDirectoryPath() /
|
||||
AWSCore::AWSCoreConfiguration::AWSCoreResourceMappingConfigFolderName /
|
||||
"test_aws_resource_mappings.json").LexicallyNormal();
|
||||
AWSCoreInternalRequestBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
AWSCoreInternalRequestBus::Handler::BusDisconnect();
|
||||
RemoveTestFile();
|
||||
RemoveTestDirectory();
|
||||
RemoveFile(m_configFilePath.Native());
|
||||
m_configFilePath.clear();
|
||||
|
||||
m_reloadConfigurationCounter = 0;
|
||||
m_resourceMappingManager->DeactivateManager();
|
||||
@@ -147,57 +136,17 @@ public:
|
||||
|
||||
// AWSCoreInternalRequestBus interface implementation
|
||||
AZStd::string GetProfileName() const override { return ""; }
|
||||
AZStd::string GetResourceMappingConfigFilePath() const override { return m_normalizedConfigFilePath; }
|
||||
AZStd::string GetResourceMappingConfigFilePath() const override { return m_configFilePath.Native(); }
|
||||
void ReloadConfiguration() override { m_reloadConfigurationCounter++; }
|
||||
|
||||
AZStd::unique_ptr<AWSCore::AWSResourceMappingManager> m_resourceMappingManager;
|
||||
AZ::u8 m_reloadConfigurationCounter;
|
||||
|
||||
private:
|
||||
AZStd::string m_normalizedSourceProjectFolder;
|
||||
AZStd::string m_normalizedConfigFolderPath;
|
||||
AZStd::string m_normalizedConfigFilePath;
|
||||
|
||||
void CreateTestFile(const AZStd::string& filePath, const AZStd::string& fileContent)
|
||||
{
|
||||
AZ::IO::SystemFile file;
|
||||
if (!file.Open(filePath.c_str(),
|
||||
AZ::IO::SystemFile::OpenMode::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
|
||||
{
|
||||
AZ_Assert(false, "Failed to open test file");
|
||||
}
|
||||
|
||||
if (file.Write(fileContent.c_str(), fileContent.size()) != fileContent.size())
|
||||
{
|
||||
AZ_Assert(false, "Failed to write test file");
|
||||
}
|
||||
file.Close();
|
||||
}
|
||||
|
||||
void RemoveTestFile()
|
||||
{
|
||||
if (!m_normalizedConfigFilePath.empty())
|
||||
{
|
||||
AZ_Assert(AZ::IO::SystemFile::Delete(m_normalizedConfigFilePath.c_str()),
|
||||
"Failed to delete test config file at %s", m_normalizedConfigFilePath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveTestDirectory()
|
||||
{
|
||||
if (!m_normalizedConfigFilePath.empty())
|
||||
{
|
||||
AZ_Assert(AZ::IO::SystemFile::DeleteDir(m_normalizedConfigFolderPath.c_str()),
|
||||
"Failed to delete test config folder at %s", m_normalizedConfigFolderPath.c_str());
|
||||
AZ_Assert(AZ::IO::SystemFile::DeleteDir(m_normalizedSourceProjectFolder.c_str()),
|
||||
"Failed to delete test folder at %s", m_normalizedSourceProjectFolder.c_str());
|
||||
}
|
||||
}
|
||||
AZ::IO::Path m_configFilePath;
|
||||
};
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseInvalidConfigFile_ConfigDataIsEmpty)
|
||||
{
|
||||
CreateTestConfigFile(TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -212,7 +161,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseInvalidConfigFile_Con
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmpty)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -227,7 +176,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_Confi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseTemplateConfigFile_ConfigDataIsNotEmpty)
|
||||
{
|
||||
CreateTestConfigFile(TEST_TEMPLATE_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_TEMPLATE_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -242,7 +191,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseTemplateConfigFile_Co
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmptyWithMultithreadCalls)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
constexpr int testThreadNumber = 10;
|
||||
@@ -267,7 +216,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_Confi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_GlobalAccountIdEmpty)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_EMPTY_ACCOUNTID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_EMPTY_ACCOUNTID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -282,7 +231,7 @@ TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_Globa
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, DeactivateManager_AfterActivatingWithValidConfigFile_ConfigDataGetCleanedUp)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -302,7 +251,7 @@ TEST_F(AWSResourceMappingManagerTest, DeactivateManager_AfterActivatingWithValid
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetDefaultAccountId_AfterParsingValidConfigFile_GetExpectedDefaultAccountId)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -313,7 +262,7 @@ TEST_F(AWSResourceMappingManagerTest, GetDefaultAccountId_AfterParsingValidConfi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetDefaultRegion_AfterParsingValidConfigFile_GetExpectedDefaultRegion)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualRegion;
|
||||
@@ -324,7 +273,7 @@ TEST_F(AWSResourceMappingManagerTest, GetDefaultRegion_AfterParsingValidConfigFi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_AfterParsingValidConfigFile_GetExpectedAccountId)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -341,7 +290,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_AfterParsingValidConf
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_QueryNonexistResourceMappingKeyName_GetEmptyAccountId)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -352,7 +301,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_QueryNonexistResource
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_AfterParsingValidConfigFile_GetExpectedNameId)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualNameId;
|
||||
@@ -369,7 +318,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_AfterParsingValidConfigF
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_QueryNonexistResourceMappingKeyName_GetEmptyNameId)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualNameId;
|
||||
@@ -380,7 +329,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_QueryNonexistResourceMap
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_AfterParsingValidConfigFile_GetExpectedRegion)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualRegion;
|
||||
@@ -397,7 +346,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_AfterParsingValidConfigF
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_QueryNonexistResourceMappingKeyName_GetEmptyRegion)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualRegion;
|
||||
@@ -408,7 +357,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_QueryNonexistResourceMap
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceType_AfterParsingValidConfigFile_GetExpectedType)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualType;
|
||||
@@ -425,7 +374,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceType_AfterParsingValidConfigFil
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetResourceType_QueryNonexistResourceMappingKeyName_GetEmptyType)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualType;
|
||||
@@ -436,7 +385,7 @@ TEST_F(AWSResourceMappingManagerTest, GetResourceType_QueryNonexistResourceMappi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyServiceName_GetEmptyUrl)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualServiceUrl;
|
||||
@@ -447,7 +396,7 @@ TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyServiceName_GetE
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyRESTApiIdAndStage_GetEmptyUrl)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualServiceUrl;
|
||||
@@ -458,7 +407,7 @@ TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyRESTApiIdAndStag
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_RESTApiIdAndStageHaveInconsistentRegion_GetEmptyUrl)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualServiceUrl;
|
||||
@@ -469,7 +418,7 @@ TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_RESTApiIdAndStageHaveInconsi
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfterParsingInvalid_ConfigDataGetParsed)
|
||||
{
|
||||
CreateTestConfigFile(TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ActivateManager();
|
||||
|
||||
AZStd::string actualAccountId;
|
||||
@@ -481,7 +430,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfter
|
||||
EXPECT_TRUE(actualRegion.empty());
|
||||
EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Error);
|
||||
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ReloadConfigFile();
|
||||
|
||||
AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
|
||||
@@ -494,7 +443,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfter
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ReloadConfigFileNameAndParseValidConfigFile_ConfigDataGetParsed)
|
||||
{
|
||||
CreateTestConfigFile(TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
|
||||
m_resourceMappingManager->ReloadConfigFile(true);
|
||||
|
||||
EXPECT_EQ(m_reloadConfigurationCounter, 1);
|
||||
@@ -505,6 +454,7 @@ TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ReloadConfigFileNameAndPa
|
||||
|
||||
TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_MissingSetRegFile_ConfigDataIsNotParsed)
|
||||
{
|
||||
m_configFilePath.clear();
|
||||
m_resourceMappingManager->ReloadConfigFile(true);
|
||||
|
||||
EXPECT_EQ(m_reloadConfigurationCounter, 1);
|
||||
|
||||
Reference in New Issue
Block a user