From 26ad18c6e32b452b52a68f8b99eeed33312bcac9 Mon Sep 17 00:00:00 2001 From: Kan Tang Date: Mon, 26 Oct 2020 10:19:22 +0800 Subject: [PATCH] Resolved File test issue. (#844) --- .../azure-storage-files-shares/CHANGELOG.md | 2 +- .../shares/protocol/share_rest_client.hpp | 16 ++++++---- .../test/share_service_client_test.cpp | 30 ++++++++++++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/sdk/storage/azure-storage-files-shares/CHANGELOG.md b/sdk/storage/azure-storage-files-shares/CHANGELOG.md index 6745a5233..de8094705 100644 --- a/sdk/storage/azure-storage-files-shares/CHANGELOG.md +++ b/sdk/storage/azure-storage-files-shares/CHANGELOG.md @@ -3,7 +3,7 @@ ## 1.0.0-beta.5 (Unreleased) ### Breaking Changes - +* `Azure::Storage::Files::Shares::Metrics::IncludeAPIs` is now renamed to `Azure::Storage::Files::Shares::Metrics::IncludeApis`, and is changed to a nullable member. * Move header `azure/storage/files/shares/shares.hpp` to `azure/storage/files/shares.hpp` diff --git a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp index a3d0c5765..6e2c00d33 100644 --- a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp +++ b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp @@ -566,8 +566,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { { std::string Version; // The version of Storage Analytics to configure. bool Enabled = bool(); // Indicates whether metrics are enabled for the File service. - bool IncludeAPIs = bool(); // Indicates whether metrics should generate summary statistics for - // called API operations. + Azure::Core::Nullable IncludeApis; // Indicates whether metrics should generate summary + // statistics for called API operations. ShareRetentionPolicy RetentionPolicy; }; @@ -1372,9 +1372,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { writer.Write(XmlNode{XmlNodeType::StartTag, "Enabled"}); writer.Write(XmlNode{XmlNodeType::Text, nullptr, object.Enabled ? "true" : "false"}); writer.Write(XmlNode{XmlNodeType::EndTag}); - writer.Write(XmlNode{XmlNodeType::StartTag, "IncludeAPIs"}); - writer.Write(XmlNode{XmlNodeType::Text, nullptr, object.IncludeAPIs ? "true" : "false"}); - writer.Write(XmlNode{XmlNodeType::EndTag}); + if (object.IncludeApis.HasValue()) + { + writer.Write(XmlNode{XmlNodeType::StartTag, "IncludeAPIs"}); + writer.Write(XmlNode{ + XmlNodeType::Text, nullptr, object.IncludeApis.GetValue() ? "true" : "false"}); + writer.Write(XmlNode{XmlNodeType::EndTag}); + } writer.Write(XmlNode{XmlNodeType::StartTag, "RetentionPolicy"}); ShareRetentionPolicyToXml(writer, object.RetentionPolicy); writer.Write(XmlNode{XmlNodeType::EndTag}); @@ -1605,7 +1609,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } else if (path.size() == 1 && path[0] == XmlTagName::c_IncludeAPIs) { - result.IncludeAPIs = (std::strcmp(node.Value, "true") == 0); + result.IncludeApis = (std::strcmp(node.Value, "true") == 0); } else if (path.size() == 1 && path[0] == XmlTagName::c_Version) { diff --git a/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp index aea681f25..642b68a9b 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp @@ -8,6 +8,16 @@ namespace Azure { namespace Storage { namespace Test { + namespace { + bool NullableEquals( + const Azure::Core::Nullable& lhs, + const Azure::Core::Nullable& rhs) + { + return (lhs.HasValue() && rhs.HasValue() && (lhs.GetValue() == rhs.GetValue())) + || (!lhs.HasValue() && !rhs.HasValue()); + } + } // namespace + const size_t c_SHARE_TEST_SIZE = 5; std::shared_ptr @@ -153,12 +163,12 @@ namespace Azure { namespace Storage { namespace Test { properties.HourMetrics.Enabled = true; properties.HourMetrics.RetentionPolicy.Enabled = true; properties.HourMetrics.RetentionPolicy.Days = 4; - properties.HourMetrics.IncludeAPIs = true; + properties.HourMetrics.IncludeApis = true; properties.MinuteMetrics.Enabled = true; properties.MinuteMetrics.RetentionPolicy.Enabled = true; properties.MinuteMetrics.RetentionPolicy.Days = 3; - properties.MinuteMetrics.IncludeAPIs = true; + properties.MinuteMetrics.IncludeApis = true; Files::Shares::CorsRule corsRule; corsRule.AllowedOrigins = "http://www.example1.com"; @@ -183,7 +193,8 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(downloadedProperties.HourMetrics.Version, properties.HourMetrics.Version); EXPECT_EQ(downloadedProperties.HourMetrics.Enabled, properties.HourMetrics.Enabled); - EXPECT_EQ(downloadedProperties.HourMetrics.IncludeAPIs, properties.HourMetrics.IncludeAPIs); + EXPECT_TRUE(NullableEquals( + downloadedProperties.HourMetrics.IncludeApis, properties.HourMetrics.IncludeApis)); EXPECT_EQ( downloadedProperties.HourMetrics.RetentionPolicy.Enabled, properties.HourMetrics.RetentionPolicy.Enabled); @@ -199,7 +210,8 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(downloadedProperties.MinuteMetrics.Version, properties.MinuteMetrics.Version); EXPECT_EQ(downloadedProperties.MinuteMetrics.Enabled, properties.MinuteMetrics.Enabled); - EXPECT_EQ(downloadedProperties.MinuteMetrics.IncludeAPIs, properties.MinuteMetrics.IncludeAPIs); + EXPECT_TRUE(NullableEquals( + downloadedProperties.HourMetrics.IncludeApis, properties.HourMetrics.IncludeApis)); EXPECT_EQ( downloadedProperties.MinuteMetrics.RetentionPolicy.Enabled, properties.MinuteMetrics.RetentionPolicy.Enabled); @@ -242,12 +254,12 @@ namespace Azure { namespace Storage { namespace Test { properties.HourMetrics.Enabled = true; properties.HourMetrics.RetentionPolicy.Enabled = true; properties.HourMetrics.RetentionPolicy.Days = 4; - properties.HourMetrics.IncludeAPIs = true; + properties.HourMetrics.IncludeApis = true; properties.MinuteMetrics.Enabled = true; properties.MinuteMetrics.RetentionPolicy.Enabled = true; properties.MinuteMetrics.RetentionPolicy.Days = 3; - properties.MinuteMetrics.IncludeAPIs = true; + properties.MinuteMetrics.IncludeApis = true; Files::Shares::CorsRule corsRule; corsRule.AllowedOrigins = "http://www.example1.com"; @@ -276,7 +288,8 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(downloadedProperties.HourMetrics.Version, properties.HourMetrics.Version); EXPECT_EQ(downloadedProperties.HourMetrics.Enabled, properties.HourMetrics.Enabled); - EXPECT_EQ(downloadedProperties.HourMetrics.IncludeAPIs, properties.HourMetrics.IncludeAPIs); + EXPECT_TRUE(NullableEquals( + downloadedProperties.HourMetrics.IncludeApis, properties.HourMetrics.IncludeApis)); EXPECT_EQ( downloadedProperties.HourMetrics.RetentionPolicy.Enabled, properties.HourMetrics.RetentionPolicy.Enabled); @@ -292,7 +305,8 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(downloadedProperties.MinuteMetrics.Version, properties.MinuteMetrics.Version); EXPECT_EQ(downloadedProperties.MinuteMetrics.Enabled, properties.MinuteMetrics.Enabled); - EXPECT_EQ(downloadedProperties.MinuteMetrics.IncludeAPIs, properties.MinuteMetrics.IncludeAPIs); + EXPECT_TRUE(NullableEquals( + downloadedProperties.HourMetrics.IncludeApis, properties.HourMetrics.IncludeApis)); EXPECT_EQ( downloadedProperties.MinuteMetrics.RetentionPolicy.Enabled, properties.MinuteMetrics.RetentionPolicy.Enabled);