From 0b3e06fe993c972c66d6e3bf2e2d8b35065d296b Mon Sep 17 00:00:00 2001
From: wiboris <54044985+wiboris@users.noreply.github.com>
Date: Mon, 9 Oct 2023 15:20:45 -0700
Subject: [PATCH] Adding Support to override the ClientRequestID guid format
for test recording sessions. (#39133)
* adding an enviroment variable "RECORDING_DEFAULT_ClIENT_GUID" to support using the default string format for ClientID's in test recording mode
* changing code to support storing the enviroment variable into the test recordings variables
* handling the case if the variable is not present in the recording
* changing from enviroment var to property of RecordedTestBase
* removing files
* whitespace fix
* update
* recovered deleted file
* restored deleted code
* fix
* feedback
(cherry picked from commit 240efa7ad801712117eb3624791431f92aa132d6)
* removed dead code
* whitespace
---
.../Azure.Core.TestFramework/src/ProxyTransport.cs | 12 ++++++++++--
.../Azure.Core.TestFramework/src/RecordedTestBase.cs | 7 +++++++
.../Azure.Core.TestFramework/src/TestRecording.cs | 12 ++++++++++++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs b/sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
index 5b7099fb27238..61c8abdf0f227 100644
--- a/sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
+++ b/sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
@@ -135,8 +135,16 @@ public override Request CreateRequest()
_recording.HasRequests = true;
lock (_recording.Random)
{
- // Make sure ClientRequestId are the same across request and response
- request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
+ if (_recording.UseDefaultGuidFormatForClientRequestId)
+ {
+ // User want the client format to use the default format
+ request.ClientRequestId = _recording.Random.NewGuid().ToString();
+ }
+ else
+ {
+ // Make sure ClientRequestId are the same across request and response
+ request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
+ }
}
return request;
}
diff --git a/sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs b/sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
index bf9d6306c5647..7161f0b06aca3 100644
--- a/sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
+++ b/sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
@@ -149,6 +149,13 @@ public string ReplacementHost
///
public bool CompareBodies { get; set; } = true;
+ ///
+ /// Determines if the ClientRequestId that is sent as part of a request while in Record mode
+ /// should use the default Guid format. The default Guid format contains hyphens.
+ /// The default value is false.
+ ///
+ public bool UseDefaultGuidFormatForClientRequestId { get; set; } = false;
+
///
/// Request headers whose values can change between recording and playback without causing request matching
/// to fail. The presence or absence of the header itself is still respected in matching.
diff --git a/sdk/core/Azure.Core.TestFramework/src/TestRecording.cs b/sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
index 25aec74da98aa..bc36ff3936de3 100644
--- a/sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
+++ b/sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
@@ -199,6 +199,18 @@ public TestRandom Random
public string RecordingId { get; private set; }
+ ///
+ /// Determines if the ClientRequestId that is sent as part of a request while in Record mode
+ /// should use the default Guid format. The default Guid format contains hyphens.
+ ///
+ public bool UseDefaultGuidFormatForClientRequestId
+ {
+ get
+ {
+ return _recordedTestBase.UseDefaultGuidFormatForClientRequestId;
+ }
+ }
+
///
/// Gets the moment in time that this test is being run. This is useful
/// for any test recordings that capture the current time.