-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Added PlaybackOnlyAttribute #12663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seanmcc-msft
merged 2 commits into
Azure:master
from
seanmcc-msft:feature/storage/PlaybackOnly
Jun 25, 2020
Merged
Added PlaybackOnlyAttribute #12663
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Interfaces; | ||
| using NUnit.Framework.Internal; | ||
|
|
||
| namespace Azure.Core.TestFramework | ||
| { | ||
| /// <summary> | ||
| /// Attribute on test assemblies, classes, or methods that run only against playback resources. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = true)] | ||
| public class PlaybackOnlyAttribute : NUnitAttribute, IApplyToTest | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a "reason" required ctor parameter.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| private readonly string _reason; | ||
|
|
||
| /// <summary> | ||
| /// Constructs the attribute giving a reason the associated tests is playback only. | ||
| /// </summary> | ||
| public PlaybackOnlyAttribute(string reason) | ||
| { | ||
| _reason = reason; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed. | ||
| /// </summary> | ||
| /// <param name="test">The <see cref="Test"/> to modify.</param> | ||
| public void ApplyToTest(Test test) | ||
| { | ||
| test.Properties.Add("Category", "Playback"); | ||
|
|
||
| if (test.RunState != RunState.NotRunnable) | ||
| { | ||
| RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment(); | ||
| if (mode != RecordedTestMode.Playback) | ||
| { | ||
| test.RunState = RunState.Ignored; | ||
| test.Properties.Set("_SKIPREASON", $"Playback tests will not run when AZURE_TEST_MODE is {mode}. This test was skipped for the following reason: {_reason}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this prevent someone from being able to re-record the test just by changing the ctor parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which constructor parameter are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
azure-sdk-for-net/sdk/storage/Azure.Storage.Blobs/tests/BlobUriBuilderTests.cs
Line 16 in b9bd85c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume so, yes, but this is by design. The workflow to re-record would be to comment out the attribute.