Skip to content

Commit

Permalink
Update the test guide for mgmt sdk (#44500)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurMa1978 authored Jun 11, 2024
1 parent 684b650 commit 7188acb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Authenticate to Azure using environment variables
You'll need the following values to authenticate to Azure:

- **Subscription ID**
- **Client ID**
- **Client Secret**
- **Tenant ID**

## Obtaining the values
Expand All @@ -20,17 +18,15 @@ These values can be obtained from the [portal](https://portal.azure.com/) with t
4. Select **Overview**.
5. Copy the Subscription ID.

### Get Client ID / Client Secret / Tenant ID
### Get Tenant ID

For information on how to get Client ID, Client Secret, and Tenant ID, see [this
document](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
For information on how to get Tenant ID, see [this
document](https://learn.microsoft.com/azure/active-directory-b2c/tenant-management-read-tenant-name).

## Setting Environment Variables

After you obtain the values, set the following environment variables:

- `AZURE_CLIENT_ID`
- `AZURE_CLIENT_SECRET`
- `AZURE_TENANT_ID`
- `AZURE_SUBSCRIPTION_ID`

Expand All @@ -48,7 +44,5 @@ _(Note: Administrator access is required)_

### Linux-based OS:

export AZURE_CLIENT_ID="__CLIENT_ID__"
export AZURE_CLIENT_SECRET="__CLIENT_SECRET__"
export AZURE_TENANT_ID="__TENANT_ID__"
export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__"
10 changes: 5 additions & 5 deletions sdk/resourcemanager/Azure.ResourceManager/docs/TestGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ In order to run the tests, the following environment variables need to be set:
| :--- | :---- | :---------- |
| AZURE_TEST_MODE | Record<sup>1</sup> | Specify in which mode the test will run |
| AZURE_AUTHORITY_HOST | https://login.microsoftonline.com<sup>2</sup> | The host of the Azure Active Directory authority |
| AZURE_CLIENT_ID | TBD<sup>3</sup> | The Service Principal Application ID |
| AZURE_CLIENT_SECRET | TBD<sup>3</sup> | A Service Principal Authentication Key |
| AZURE_SUBSCRIPTION_ID | TBD<sup>3</sup> | The Azure Subscription ID |
| AZURE_TENANT_ID | TBD<sup>3</sup> | The AAD Tenant ID |

**Note**:

1. Our testing framework supports three different test modes: `Live`, `Playback`, `Record`. In management plane, please set the `AZURE_TEST_MODE` to `Record` for your first test run, this will record HTTP requests and responses and store the record files in the `SessionRecords folder corresponding to the ./assets directory`. Properly supporting recorded tests does require a few extra considerations. All random values should be obtained via `this.Recording.Random` since we use the same seed on test playback to ensure our client code generates the same "random" values each time. You can't share any state between tests or rely on ordering because you don't know the order they'll be recorded or replayed. Any sensitive values are redacted via the [`ConfigurationRecordedTestSanitizer`][test_sanitizer]. After you have successfully recorded all the tests for the first time, you can change its value to `Playback`. If the tests locally fail due to recording session file mismatches at this point, the attribute `RecordedTest` will help enable automatically re-record failed tests.

2. You need to change its value depending on the Azure Cloud type you are using in your tests. `https://login.microsoftonline.com` only applies to Azure Public Cloud.
2. Before initiating the Live and Record test, ensure that you are logged into your Azure account using either Azure CLI or Azure PowerShell.

3. These values depend on the subscription and token credential you are using for testing. Please refer to this [document][authenticate] to get the values.
3. You need to change its value depending on the Azure Cloud type you are using in your tests. `https://login.microsoftonline.com` only applies to Azure Public Cloud.

4. These values depend on the subscription you are using for testing. Please refer to this [document][env_variables] to get the values.

The easiest way to run the tests is via Visual Studio's test runner. Please note that the Visual Studio 2022 is required as one of the test target frameworks is `.NET 6.0`.

Expand Down Expand Up @@ -130,4 +130,4 @@ Our samples are structured as unit tests so we can easily verify they're up to d
[core_tests]: https:/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core.TestFramework
[mgmt_template]: https:/Azure/azure-sdk-for-net/tree/main/eng/templates/Azure.ResourceManager.Template
[test_sanitizer]: https:/Azure/azure-sdk-for-net/tree/main/sdk/core/Azure.Core.TestFramework#sanitizing
[authenticate]: https:/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/AuthUsingEnvironmentVariables.md
[env_variables]: https:/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/AuthUsingEnvironmentVariables.md

0 comments on commit 7188acb

Please sign in to comment.