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
Copy file name to clipboardExpand all lines: documentation/api-scenario/readme.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ _**Caution**: This project is in early preview phase, hence breaking changes sho
6
6
7
7
## Features
8
8
9
-
- Simple to use: Intuitive step definition based on Swagger examples and raw REST call.
9
+
- Simple to use: Intuitive step definition based on Swagger operations and examples.
10
10
- ARM Template integration: Support creating external Azure resources with ARM Template and executing Azure Powershell or Azure CLI scripts with ARM Template deployment script.
11
-
- Implementation independent: [oav](https://github.com/Azure/oav) is the default API scenario runner, and more runners will be supported, like SDKs in different languages.
11
+
- Implementation independent: [oav](https://github.com/Azure/oav) is the default API scenario runner. More runners will be supported, like SDKs in different languages.
- **ResourceGroup:** All of the following API scenario and steps should be under some resourceGroup. It means:
36
34
- The consumer (API scenario runner or anything consumes API scenario) SHOULD maintain the resource group itself. Usually it requires user to input the subscriptionId/location, then it creates the resource group before test running, and deletes the resource group after running
37
35
- The consumer SHOULD set the following variables:
38
36
- **subscriptionId**
39
37
- **resourceGroupName**
40
38
- **location**
41
-
- For details of how variables works please see [Variables](./Variables.md)
39
+
- For details of how variables work please see [Variables](./Variables.md)
42
40
- **variables**
43
-
- **Type:** Optional, Map of strings
41
+
- **Type:** Optional, Map of strings or variable containers
44
42
- See [Variables](./Variables.md)
45
43
- **prepareSteps**
46
44
- **Type:** Optional, Array of [Step](#step)
47
45
- Steps that should run before every API scenario steps.
48
46
- **scenarios**
49
47
- **Type:** Required, Array of [Scenario](#scenario)
48
+
- **cleanUpSteps**
49
+
- **Type:** Optional, Array of [Step](#step)
50
+
- Steps that should run after every API scenario steps.
50
51
51
52
## Scenario
52
53
53
-
See [Scenario Schema](./v1.1/schema.json#L83).
54
+
See [Scenario Schema](./v1.2/schema.json#L249).
54
55
55
56
It defines one API scenario that could go through on its own.
- Describe how the scope (ResourceGroup if scope is ResourceGroup) could be shared with other tests. If it's true or it's the same string setting for different API scenario, then they share the same scope, which means:
80
-
- These tests will run under the same scope (e.g. ResourceGroup). They may launch in parallel.
81
-
- **prepareSteps** will only run once in the scope. The variables will be shared.
82
-
- By default all the API scenario in one definition file will be launched in the same scope. If shareScope is false then it will not share anything with other API scenarios in the same file.
79
+
- Describe how the scope (ResourceGroup if scope is ResourceGroup) could be shared with other scenarios. If true or the same string value for different API scenario, they share the same scope, which means:
80
+
- These API scenarios will run under the same scope (e.g. ResourceGroup).
81
+
- **prepareSteps** and **cleanUpSteps** will run only once in the scope. The variables will be shared.
82
+
- By default all the API scenario in one definition file will be launched in the same scope. If shareScope is false, the API scenarios will not share anything with others in the same file.
83
83
- **variables**
84
84
- **Type:** Optional, Map of strings
85
85
- See [Variables](./Variables.md)
@@ -89,30 +89,33 @@ variables:
89
89
90
90
## Step
91
91
92
-
See [Step Schema](./v1.1/schema.json#L114).
92
+
See [Step Schema](./v1.2/schema.json#L280).
93
93
94
94
Defines one step in API scenario.
95
95
96
96
Should be one of the following:
97
97
98
98
- [Step REST Call](#step-rest-call)
99
-
- [REST Call](#rest-call)
100
-
- [REST Call by ResourceName Tracking and Update](#rest-call-by-resourcename-tracking-and-update)
99
+
- [REST Operation](#rest-operation)
100
+
- [REST Example](#rest-example)
101
101
- [Step ARM Template](#step-arm-template)
102
102
- [Step ARM Deployment Script](#step-arm-deployment-script)
103
103
104
104
All of the above definitions share the following fields:
105
105
106
-
- **variables**
107
-
- **Type:** Optional, Map of Strings
108
-
- See [Variables](./Variables.md)
109
106
- **step**
110
107
- **Type:** Required, String
111
108
- Step name. Must be unique in the same file.
109
+
- **description**
110
+
- **Type:** Optional, String
111
+
- A brief explanation about the step
112
+
- **variables**
113
+
- **Type:** Optional, Map of Strings or variables
114
+
- See [Variables](./Variables.md)
112
115
113
116
## Step ARM Template
114
117
115
-
See [Step ARM Template Schema](./v1.1/schema.json#L250).
118
+
See [Step ARM Template Schema](./v1.2/schema.json#L427).
116
119
117
120
Step to deploy ARM template to the scope. Template parameters and outputs will also interact with variables automatically, see [Variables](./Variables.md).
118
121
@@ -129,10 +132,9 @@ Step to deploy ARM template to the scope. Template parameters and outputs will a
129
132
- **Type:** Required, String
130
133
- Path to ARM template json file. See [ARM Template](https://docs.microsoft.com/azure/templates/).
131
134
132
-
133
135
## Step ARM Deployment Script
134
136
135
-
See [Step ARM Deployment Script Schema](./v1.1/schema.json#L266).
137
+
See [Step ARM Deployment Script Schema](./v1.2/schema.json#L448).
136
138
137
139
Step to deploy ARM deployment script to the scope. Template parameters and outputs will also interact with variables automatically, see [Variables](./Variables.md).
138
140
@@ -186,98 +188,104 @@ Step to deploy ARM deployment script to the scope. Template parameters and outpu
186
188
187
189
## Step REST Call
188
190
189
-
See [Step REST Call Schema](./v1.1/schema.json#L208)
191
+
Step to run a rest call defined in swagger operation. This may not be just one http call.
190
192
191
-
Step to run a swagger operation defined rest call. This may not be just one http call.
192
-
193
-
- If the operation is a long running operation (LRO), then follow the LRO polling strategy.
193
+
- If the operation is a long running operation (LRO), then follow the LRO polling strategy:
194
194
- Response statusCode must be 200 if the LRO succeeded, no matter what code the initial response is.
195
195
- If the LRO is PUT/PATCH, the runner should automatically insert a GET after the polling to verify the resource update result.
196
196
- If the operation is DELETE, then after the operation, the runner should automatically insert a GET to verify resource cannot be found.
197
197
198
-
Rest call step could be defined either by an example file, or by resourceName tracking and update.
198
+
REST call step could be defined either by an operation, or by an example file. REST call will have computed **requestParameter** and **responseExpected** after parsing and loading.
199
+
200
+
### REST Operation
201
+
202
+
See [Step Operation Schema](./v1.2/schema.json#L339)
199
203
200
-
Rest call will have computed **requestParameter** and **responseExpected** after parsing and loading:
204
+
**Example:**
205
+
```yml
206
+
- step: createPublicIPAddress
207
+
operationId: PublicIPAddresses_CreateOrUpdate
208
+
```
209
+
210
+
**Fields:**
211
+
212
+
- **operationId:**
213
+
- **Type:** Required, String
214
+
- OperationId defined in Swagger.
215
+
- **parameters:**
216
+
- **Type:** Optional, Map from parameter name to parameter value
217
+
- **responses:**
218
+
- **Type:** Optional, Map from expected response code to response headers and body.
219
+
- **outputVariables**
220
+
- **Type:** Optional, Map from variable name to object with property:
221
+
- **type**: Required, String
222
+
- **fromRequest**
223
+
- **Type:** Required, String
224
+
- Path to the request field to be used as variable.
225
+
- **fromResponse**
226
+
- **Type:** Required, String
227
+
- Path to the response field to be used as variable.
201
228
202
-
- **requestParameter**
229
+
### REST Example
203
230
204
-
### REST Call
231
+
See [Step Example Schema](./v1.2/schema.json#L389)
- Path to example file. Should be in format of "x-ms-example" files.
221
-
- **operationId**
222
-
- **Type:** Optional, String
223
-
- OperationId defined in swagger operation. It could be skipped if the example file is referenced by only one operation so we could detect the operationId.
224
-
- **statusCode:**
225
-
- **Type:** Optional, Number
226
-
- **Default:** 200
227
-
- Expected response code.
228
-
- For LRO it must be 200 to indicate succeeded result, and must be 400 to indicate failed result.
229
245
- **requestUpdate**
230
246
- **Type:** Optional, Array of [JsonPatchOp](#jsonpatchop)
231
-
- Updates that applied to the requestParameters before sending it.
247
+
- Updates that apply to the **requestParameters** before sending it, with `/parameters` in example as root of Json path.
232
248
- **responseUpdate**
233
249
- **Type:** Optional, Array of [JsonPatchOp](#jsonpatchop)
234
-
- Updates that applied to the responseExpected.
250
+
- Updates that apply to the **responseExpected**, with `/responses` in example as root of Json path.
235
251
- **outputVariables**
236
252
- **Type:** Optional, Map from variable name to object with property:
253
+
- **type**: Required, String
254
+
- **fromRequest**
255
+
- **Type:** Required, String
256
+
- Path to the request field to be used as variable.
237
257
- **fromResponse**
238
258
- **Type:** Required, String
239
259
- Path to the response field to be used as variable.
240
260
241
-
### Rest Call by ResourceName Tracking and Update
261
+
**Conventions:**
242
262
243
-
**Example**
263
+
When the scope is `ResourceGroup` and the request is a PUT/PATCH, the **requestUpdate** JsonPatchOp items starting with body parameter name SHOULD be applied to the response body (if any) for all successful status codes, excluding writeOnly properties - `x-ms-secret: true` or `x-ms-mutability` doesn't contain `read`.
The **responseUpdate** SHOULD be applied after the **requestUpdate**, providing option to override the behavior by convention.
251
266
252
-
- step: Update_publicIPAddresses
253
-
resourceName: publicIPAddresses_pubipdns
254
-
resourceUpdate:
255
-
- replace: /properties/location
256
-
value: westus
257
-
```
258
-
259
-
Different steps with the same resourceName will be tracked by the API scenario. It knows that you are trying to update the same resource. You can use the first request with example to specify the request and resource id, then the following step with the same resourceName will use the same resource id to update the resource. For the
260
-
261
-
**Fields:**
267
+
The behavior of applying **requestUpdate** to the response body should follow JSON merge-patch ([RFC 7396](https://tools.ietf.org/html/rfc7396)).
262
268
263
-
- **resourceName**
264
-
- **Type:** Required, String
265
-
- The user-defined resource name of the resource to be tracked. It's only used as a name of that resource and do not need to be same as the actual resource name.
266
-
- **resourceUpdate**
267
-
- **Type:** Optional, Array of [JsonPatchOp](#jsonpatchop)
268
-
- Array of changes to be applied to the resource.
269
-
270
-
resourceUpdate will help to automate compute the request body and the expected response body. The algorithm will be:
271
-
272
-
- Get the expected response body from previous step with same `resourceName`, or from current step with example loaded.
273
-
- For each change in `resourceUpdate`, apply the change to the expected response body, mark as `computedAllProperties`.
274
-
- Let new request body parameter value to be: `computedAllProperties`without `readOnly` fields and `x-ms-mutability` fields that don't contains `update`.
275
-
- Let new response expected to be: `computedAllProperties`without `x-ms-secrets` fields and `x-ms-mutability` fields that don't contain `read`.
276
-
- Let the operationId to be: resource PUT operationId.
269
+
The whole process is illustrated as below pseudo-code:
270
+
```
271
+
if (scope is 'ResourceGroup' && operation.verb in ('PUT', 'PATCH')) {
Copy file name to clipboardExpand all lines: documentation/api-scenario/references/Variables.md
+21-14Lines changed: 21 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,34 @@
1
1
# Variables in API scenario
2
2
3
-
## Variable definition and replacement
3
+
## Variable types
4
4
5
-
Variables could be defined in different level of API scenario:
5
+
Variables could be of different types:
6
+
-`array`
7
+
-`bool`
8
+
-`int`
9
+
-`object`
10
+
-`secureString`
11
+
-`secureObject`
12
+
-`string`
13
+
14
+
## Variable definition
6
15
7
-
-`runtime`: Variables specified at runtime
8
-
-`global`: API scenario definition level variable definition
9
-
-`scope`: Scope level variable
10
-
-`scenario`: API scenario level variable definition
11
-
-`step`: Step level variable definition
16
+
Variables could be defined in different level of API scenario:
12
17
13
-
Variable could be referenced by `$(variableName)`. Currently variable type must be string.
18
+
-`runtime`: Variables specified at runtime. Only `string` or `secureString` type is allowed in runtime level.
19
+
-`global`: API scenario file level variable definition.
20
+
-`scope`: Scope level variable. If the scope of API scenario is `ResourceGroup`, variable `resourceGroupName` will be available in scope level.
21
+
-`scenario`: API scenario level variable definition.
22
+
-`step`: Step level variable definition.
14
23
15
-
For example, in the following API scenario:
24
+
Variable could be referenced by `$(variableName)`. For example, in the following API scenario:
16
25
17
26
```yaml
18
27
variables:
19
28
resourceName: level-1
20
29
21
30
scenarios:
22
-
- definition: Create some resource
31
+
- description: Create some resource
23
32
variables:
24
33
resourceName: level-2
25
34
steps:
@@ -29,7 +38,7 @@ scenarios:
29
38
exampleFile: ../examples/ResourceCreate.json
30
39
```
31
40
32
-
if in `../examples/ResourceCreate.json` we have `$(resourceName)` in some string, it would be replaced with `level-3`.
41
+
If in `../examples/ResourceCreate.json` there is `$(resourceName)` in some string, it would be replaced with `level-3`.
33
42
34
43
Variables could also be defined on test running. For example you could set `subscriptionId` or `resourceGroupName` on the global scope. How to set global env is based on the API scenario consumer.
35
44
@@ -41,9 +50,7 @@ variables:
41
50
resourceId: Microsoft.Contoso/$(resourceName)
42
51
```
43
52
44
-
Then `$(resourceId)` would be resolved to `Microsoft.Contoso/abc`.
45
-
46
-
Variable resolving is limited to at most 100 times for certain string.
53
+
Then `$(resourceId)` would be resolved to `Microsoft.Contoso/abc`. Note that variables referencing `secureString` should be regarded as `secureString` in API Scenario runner.
0 commit comments