Add guidance for scrubbing values.
Родитель
e95031fc52
Коммит
4342401ed6
|
@ -14,20 +14,20 @@ You will need the following things installed:
|
|||
2. In `Package.swift`, add `AzureTest` to the dependencies for your test target.
|
||||
3. Within the test scheme for your target, ensure you have created and set the following environment variables:
|
||||
- `TEST_MODE`: Set to either "record" or "playback".
|
||||
- `SDK_REPO_ROOT`: The local path to your clone of `azure-sdk-for-ios`.
|
||||
- `SDK_REPO_ROOT`: The local path to your clone of `azure-sdk-for-ios`. This is used only during recording. All files during playback must be included in the app bundle.
|
||||
|
||||
## Creating Resources
|
||||
|
||||
Most tests require some Azure resources to be set up prior to running, and these resources should be cleaned up after the test completes. Mechanisms exists to facilitate this automatically.
|
||||
|
||||
1. Within the service folder for your framework (the folder directly beneath `sdk`), add resources to either the `test-resources.bicep` file or `test-resources.json`. This file will be used to deploy resources when your test is run live (such as while recording).
|
||||
1. Within the service folder for your framework (the folder directly beneath `sdk`), add resources to either the `test-resources.bicep` file or `test-resources.json`. This file will be used to deploy resources to run your tests live (such as for recording).
|
||||
2. If you need to do further setup with the resources created in step 1, add or modify the `test-resources-pre.ps1` or `test-resources-post.ps1` scripts to perform any necessary setup. By default, you can only use Powershell cmdlets. The necessary outputs from these scripts should be dumped into a file called `test-settings.plist` (see below).
|
||||
3. Run the following common engineering script from the root of the SDK repo to deploy your test resources: `./eng/common/TestResources/New-TestResources.ps1 <SERVICE_DIR>`
|
||||
|
||||
## Storing Credentials
|
||||
|
||||
1. Create a class which implements `AzureTest.TestSettingsProtocol`. This model should consist of string-based properties which back credentials you need to supply to run tests live.
|
||||
2. Within your `Tests` folder, add the plist file created in step 3 above to the project. The file MUST MUST be named `test-settings.plist`, as this filename is part of the `.gitignore` and thus will not be committed as a change in source control.
|
||||
1. Create a class which implements `AzureTest.TestSettingsProtocol`. This model should consist of string-based properties which contain the _placeholder_ values that will be used during playback. These values must be deterministic. **NEVER** put actual credentials, tokens, connection strings, etc in this file!
|
||||
2. Within your `Tests` folder, add the plist file created in step 3 above to the project. The file MUST MUST be named `test-settings.plist`, as this filename is part of the `.gitignore` and thus will not be committed as a change in source control. This file contains the _actual_ values necessary to run your test live.
|
||||
3. Ensure that `test-settings.plist` has target membership in the relevant test target(s).
|
||||
|
||||
## Writing Tests
|
||||
|
@ -39,6 +39,23 @@ Most tests require some Azure resources to be set up prior to running, and these
|
|||
|
||||
![Screen Shot 2022-02-18 at 3 57 40 PM](https://user-images.githubusercontent.com/5723682/154776294-5adaf029-d44b-4759-aa9a-522dc930dd54.png)
|
||||
|
||||
## Scrubbing Values
|
||||
|
||||
`AzureTest` contains a class called `RequestURLFilter` which can be used to replace non-deterministic values in the request URL and body with deterministic ones to facilitate reliable playback. As an example:
|
||||
|
||||
```swift
|
||||
private var urlFilter: RequestURLFilter {
|
||||
let defaults = TestSettings()
|
||||
let textFilter = RequestURLFilter()
|
||||
textFilter.register(replacement: defaults.endpoint, for: settings.endpoint)
|
||||
return textFilter
|
||||
}
|
||||
```
|
||||
|
||||
The `textFilter.register(replacement:for:)` method is used to register replacements. You can register as many replacements as necessary.
|
||||
|
||||
Then, in the `setUpTest` or `setUpTestWithError` method, you can register this filter with `add(filter: urlFilter)`.
|
||||
|
||||
## Playing Back Tests
|
||||
|
||||
1. Change the `TEST_MODE` environment variable in your target's Test scheme to "playback".
|
||||
|
|
Загрузка…
Ссылка в новой задаче