You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the `use` section, the value should always be the latest version of the `@autorest/go` package.
117
117
The latest version can be found at the NPM [page][autorest_go] for `@autorest/go`.
118
118
119
-
For services that authenticate with Azure Active Directory, you **must** include the `security-scopes` parameter with the appropriate values (example below).
119
+
For services that authenticate with Microsoft Entra ID, you **must** include the `security-scopes` parameter with the appropriate values (example below).
The first part of the test above is for getting the secrets needed for authentication from your environment, best practice is to store your test secrets in environment variables.
250
+
The first part of the test above is for getting resource configuration from your environment.
243
251
244
252
The rest of the snippet shows a test that creates a single table and requirements (similar to assertions in other languages) that the response from the service has the same table name as the supplied parameter. Every test in Go has to have exactly one parameter, the `t *testing.T` object, and it must begin with `Test`. After making a service call or creating an object you can make assertions on that object by using the external `testify/require` library. In the example above, we "require" that the error returned is `nil`, meaning the call was successful and then we require that the response object has the same table name as supplied.
245
253
@@ -249,7 +257,7 @@ If you set the environment variable `AZURE_RECORD_MODE` to "record" and run `go
249
257
250
258
### Scrubbing Secrets
251
259
252
-
The recording files eventually live in the main repository (`github.com/Azure/azure-sdk-for-go`) and we need to make sure that all of these recordings are free from secrets. To do this we use Sanitizers with regular expressions for replacements. All of the available sanitizers are available as methods from the `recording` package. The recording methods generally take three parameters: the test instance (`t *testing.T`), the value to be removed (ie. an account name or key), and the value to use in replacement.
260
+
Recording files live in the assets repository (`github.com/Azure/azure-sdk-assets`) and must not contain secrets. We use sanitizers with regular expression replacements to prevent recording secrets. The test proxy has many built-in sanitizers enabled by default. However, you may need to add your own by calling functions from the `recording` package. These functions generally take three parameters: the test instance (`t *testing.T`), the value to be removed (ie. an account name or key), and the value to use in replacement.
253
261
254
262
| Sanitizer Type | Method |
255
263
| -------------- | ------ |
@@ -263,7 +271,9 @@ The recording files eventually live in the main repository (`github.com/Azure/az
263
271
| URI Sanitizer | `AddURISanitizer(value, regex string, options *RecordingOptions)` |
264
272
| URI Subscription ID Sanitizer | `AddURISubscriptionIDSanitizer(value string, options *RecordingOptions)` |
265
273
266
-
To add a scrubber that replaces the URL of your account use the `TestMain()` function to set sanitizers before you begin running tests.
274
+
You may also need to remove a built-in sanitizer overwriting a non-secret value needed by a test. To do this, call `RemoveRegisteredSanitizers` with a list of sanitizer IDs such as "AZSDK3430". See the [test proxy documentation](https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDictionary.cs) for a complete list of all the built-in sanitizers and their IDs.
275
+
276
+
Configure sanitizers before running tests:
267
277
268
278
```go
269
279
const recordingDirectory = "<path to service directory with assets.json file>/testdata"
@@ -290,15 +300,18 @@ func run(m *testing.M) int {
The credentials in `azidentity` are not automatically configured to run in playback mode. To make sure your tests run in playback mode even with `azidentity` credentials the best practice is to use a simple `FakeCredential` type that inserts a fake Authorization header to mock a credential. An example for swapping the `DefaultAzureCredential` using a helper function is shown below in the context of `aztables`
The `FakeCredential` show here implements the `azcore.TokenCredential` interface and can be used anywhere the `azcore.TokenCredential` is used.
354
-
355
335
### Live Test Resource Management
356
336
357
337
If you have live tests that require Azure resources, you'll need to create a test resources config file for deployment during CI.
358
338
Please see the [test resource][test_resources] documentation for more info.
359
339
360
340
### Committing/Updating Recordings
361
341
362
-
The `assets.json` file located in your module directory is used by the Test Framework to figure out how to retrieve session records from the assets repo. In order to push new session records, you need to invoke:
342
+
Always inspect recordings for secrets before pushing them. The `assets.json` file located in your module directory is used by the Test Framework to figure out how to retrieve session records from the assets repo. In order to push new session records, you need to invoke:
0 commit comments