Skip to content

Commit

Permalink
Adding Support to override the ClientRequestID guid format for test r…
Browse files Browse the repository at this point in the history
…ecording sessions. (Azure#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 240efa7)

* removed dead code

* whitespace
  • Loading branch information
wiboris authored and matthohn-msft committed Oct 27, 2023
1 parent d99a765 commit 0b3e06f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public string ReplacementHost
/// </summary>
public bool CompareBodies { get; set; } = true;

/// <summary>
/// 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 <value>false</value>.
/// </summary>
public bool UseDefaultGuidFormatForClientRequestId { get; set; } = false;

/// <summary>
/// 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.
Expand Down
12 changes: 12 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ public TestRandom Random

public string RecordingId { get; private set; }

/// <summary>
/// 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.
/// </summary>
public bool UseDefaultGuidFormatForClientRequestId
{
get
{
return _recordedTestBase.UseDefaultGuidFormatForClientRequestId;
}
}

/// <summary>
/// Gets the moment in time that this test is being run. This is useful
/// for any test recordings that capture the current time.
Expand Down

0 comments on commit 0b3e06f

Please sign in to comment.