Skip to content

Commit 6fd038e

Browse files
committed
feat: update for variable interpolation
1 parent 3d798e5 commit 6fd038e

11 files changed

Lines changed: 170 additions & 151 deletions

docs/examples/http-examples.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ request:
5353

5454
# get only response code
5555
expose:
56-
- $_response.code
56+
- "{$_response.code}"
5757
```
5858
5959
### Request with query string and header
@@ -189,7 +189,8 @@ request:
189189
photo: file:///home/username/student-photo-01.png
190190
191191
# get only response body; response headers, code, etc will be dropped
192-
expose: $_response.body
192+
expose:
193+
- "{$_response.body}"
193194
```
194195

195196
### Request with file upload

docs/examples/testcase-examples.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ title: Testcase examples
66

77
- This page should be use as reference for specification files.
88
- This page is subject to change. It is requested to check this page frequently.
9-
:::
9+
10+
:::
1011

1112
:::note
13+
1214
Case-wise more example can be found in [https://github.com/chkware/cli](https://github.com/chkware/cli/blob/main/tests/resources/storage/sample_config/bitcoin-usd-testcase.chk) repository
15+
1316
:::
1417

1518
[Testcase specification document reference](/references/testcase-reference)
@@ -27,8 +30,8 @@ request:
2730

2831
spec:
2932
asserts:
30-
- { type: AssertEqual, actual: $_response.code, expected: 201 }
31-
- { type: AssertIsMap, actual: $_response.body }
33+
- { type: AssertEqual, actual: "{$_response.code}", expected: 201 }
34+
- { type: AssertIsMap, actual: "{$_response.body}" }
3235
```
3336
3437
The above testcase spec. doc define a request that makes a `POST` call to `https://reqres.in/api/users` URL with a body `{"name": "My Name", "job": "My Job"}`.
@@ -46,7 +49,7 @@ Assertion [reference with examples](/references/testcase-reference#assertions) c
4649

4750
### A minimal Testcase with out-file request
4851

49-
A http spec. doc can be written on separate file, that does same as above request. Let's call it `same-request.chk`. The http spec. doc by default exposes `$_response` object.
52+
A http spec. doc can be written on separate file, that does same as above request. Let's call it `same-request.chk`. The http spec. doc by default exposes `_response` object.
5053

5154
```yaml
5255
# file: same-request.chk
@@ -70,11 +73,11 @@ spec:
7073
execute:
7174
file: "./same-request.chk"
7275
asserts:
73-
- { type: AssertEqual, actual: $_response.code, expected: 201 }
74-
- { type: AssertIsMap, actual: $_response.body }
76+
- { type: AssertEqual, actual: "{$_response.code}", expected: 201 }
77+
- { type: AssertIsMap, actual: "{$_response.body}" }
7578
```
7679

77-
Please notice the `$_response` in the testcase doc. This variable is available after the request gets executed as local variable.
80+
Please notice the `_response` in the testcase doc. This variable is available after the request gets executed as local variable.
7881

7982
### A Testcase with out-file request passing data
8083

@@ -92,7 +95,7 @@ variables:
9295
request:
9396
url: "https://reqres.in/api/users"
9497
method: POST
95-
body[json]: { "name": $name, "job": $job }
98+
body[json]: { "name": "{$name}", "job": "{$job}" }
9699
```
97100

98101
Now we can point out which value we want to pass using `with` statement in `execute` block.
@@ -109,8 +112,8 @@ spec:
109112
name: Her Name
110113
job: Her Job
111114
asserts:
112-
- { type: AssertEqual, actual: $_response.code, expected: 201 }
113-
- { type: AssertIsMap, actual: $_response.body }
115+
- { type: AssertEqual, actual: "{$_response.code}", expected: 201 }
116+
- { type: AssertIsMap, actual: "{$_response.body}" }
114117
```
115118

116119
Please notice that if we do not set a `with` then request will be sent with default value.

docs/examples/variable-examples.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ title: Variable examples
66

77
- This page should be use as reference for specification files.
88
- This page is subject to change. It is requested to check this page frequently.
9-
:::
9+
10+
:::
1011

1112
:::note
13+
1214
Case-wise more example can be found in [https://github.com/chkware/cli](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config/pass_cases/variables) repository
15+
1316
:::
1417

1518
[Variable specification document reference](/references/variable-reference)
1619

1720
We can also use variables inside a http and testcase specification file. See examples below.
1821

19-
** \* This is highly experimental. Report any bug you can find.**
20-
2122
### Request with query string using variables
2223

2324
```yaml
@@ -26,15 +27,14 @@ version: default:http:0.7.2
2627

2728
# define local variables
2829
variables:
29-
Foo: 'bar'
30+
Foo: "bar"
3031
Two: 2
3132
Server: https://example.org/api
3233

3334
request:
3435
# put variables on the path for query string
35-
url: {$Server}/path?foo={$Foo}&two={$Two}
36+
url: "{$Server}/path?foo={$Foo}&two={$Two}"
3637
method: GET
37-
3838
```
3939
4040
### Request with basic authentication header using variables
@@ -51,17 +51,16 @@ variables:
5151
Server: https://example.org/api
5252

5353
request:
54-
url: {$Server}/resource/id
54+
url: "{$Server}/resource/id"
5555
method: GET
5656

5757
headers:
5858
Accept-Encoding: gzip, deflate
59-
Content-Type: {$content_type}
59+
Content-Type: "{$content_type}"
6060

6161
auth[basic]:
62-
username: {$userName}
63-
password: {$password}
64-
62+
username: "{$userName}"
63+
password: "{$password}"
6564
```
6665
6766
### Testcase using variables
@@ -73,21 +72,18 @@ version: "default:testcase:0.7.2"
7372
variables:
7473
Name: "Morpheus"
7574
Job: "leader"
76-
Response: ~
7775
Server: https://reqres.in/api/v1
7876

7977
request:
8078
url: "{$Server}/users"
8179
method: POST
82-
body[json]: { "name": $Name, "job": $Job }
83-
return: ~
80+
body[json]: { "name": "{$Name}", "job": "{$Job}" }
8481

8582
spec:
8683
execute:
8784
file: ~
88-
result: $Response
8985

9086
asserts:
91-
- { type: AssertEqual, actual: $Response.code, expected: 201 }
92-
- { type: AssertIsMap, actual: $Response.body }
87+
- { type: AssertEqual, actual: "{$_response.code}", expected: 201 }
88+
- { type: AssertIsMap, actual: "{$_response.body}" }
9389
```

docs/quick-start.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ title: Quick Start
66

77
- **Prerequisite**: First, [setup **CHKware**](/setup) to continue
88
- Find [More `http` examples](/examples/http-examples) here
9-
:::
9+
10+
:::
1011

1112
### Sample
1213

@@ -25,8 +26,8 @@ Let's call an API that returns current bitcoin price in USD, and test it. Please
2526

2627
spec:
2728
asserts:
28-
- { type: AssertEqual, actual: $_response.code, expected: 200 }
29-
- { type: AssertIsInt, actual: $_response.body.coin.priceBtc }
29+
- { type: AssertEqual, actual: "{$_response.code}", expected: 200 }
30+
- { type: AssertIsInt, actual: "{$_response.body.coin.priceBtc}" }
3031
```
3132
3233
- Hit enter after writing following command on terminal
@@ -45,8 +46,8 @@ Let's call an API that returns current bitcoin price in USD, and test it. Please
4546
- Prepare exposable [Success]
4647

4748
---
48-
-> Running `AssertEqual` on `$_response.code` [Success]
49-
-> Running `AssertIsInt` on `$_response.body.coin.priceBtc` [Success]
49+
-> Running `AssertEqual` on `{$_response.code}` [Success]
50+
-> Running `AssertIsInt` on `{$_response.body.coin.priceBtc}` [Success]
5051
```
5152

5253
- Congratulation! You have just tested an API. :wink::tada::confetti_ball:

0 commit comments

Comments
 (0)