Skip to content

Commit 55aa0b3

Browse files
committed
updated quick start with testcase
1 parent 000791e commit 55aa0b3

1 file changed

Lines changed: 30 additions & 67 deletions

File tree

docs/quick-start.md

Lines changed: 30 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,64 @@ title: Quick Start
33
---
44

55
:::note
6-
- **Prerequisite**: First, [setup **chkware**](/setup) to continue
6+
- **Prerequisite**: First, [setup **CHKware**](/setup) to continue
77
- Find [More `http` examples](/examples/http-examples) here
88
:::
99

10-
Let's call an API that returns current bitcoin price in USD. Please do following:
10+
### Sample
1111

12-
- Create a file called `bitcoin-usd.chk`
13-
- Open `bitcoin-usd.chk` file, and add following data
12+
Let's call an API that returns current bitcoin price in USD, and test it. Please do as following:
13+
14+
- Create a file called `bitcoin-usd-testcase.chk` in any of your workspace. This file name has not special significance. File name can be anything ending `.chk` extension.
15+
16+
Open `bitcoin-usd-testcase.chk` file, and add following:
1417

1518
```yaml
1619
---
17-
version: default:http:0.7.2
20+
version: default:testcase:0.7.2
1821
request:
1922
url: https://api.coinstats.app/public/v1/coins/bitcoin?currency=USD
2023
method: GET
24+
25+
spec:
26+
asserts:
27+
- {type: AssertEqual, actual: $_response.code, expected: 200}
28+
- {type: AssertIsInt, actual: $_response.body.coin.priceBtc}
2129
```
2230
2331
- Hit enter after writing following command on terminal
2432
2533
```bash
26-
chk http bitcoin-usd.chk
34+
chk testcase bitcoin-usd-testcase.chk
2735
```
2836

29-
- You'll get output like following. Data will vary depending on the day you are doing it.
37+
You'll get output like following. Data will vary depending on the day you are doing it.
3038

3139
```bash
32-
File: bitcoin-usd.chk
33-
34-
Executing request
40+
File: bitcoin-usd-testcase.chk
3541

3642
- Making request [Success]
37-
====
38-
HTTP/1.1 200 OK
39-
Content-Type: application/json; charset=utf-8
40-
Content-Length: 510
41-
Connection: keep-alive
42-
Date: Sun, 07 Aug 2022 06:05:23 GMT
43-
X-Powered-By: Express
44-
Access-Control-Allow-Origin: *
45-
ETag: W/"1fe-daabae46"
46-
X-Cache: Miss from cloudfront
47-
Via: 1.1 02d36a84a910749e0e01cf16e7e1a02a.cloudfront.net (CloudFront)
48-
X-Amz-Cf-Pop: SIN5-C1
49-
X-Amz-Cf-Id: es7o2_gllNtjITVD3QM3Y5EH3ASHfg1sjav2o5RSSJKH8Mo3Dv_8BA==
50-
51-
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22991.80131938709, 'priceBtc': 1, 'volume': 17847616879.01853, 'marketCap': 439482097425.5293, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.11, 'priceChange1d': -0.92, 'priceChange1w': -3.04, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
52-
```
43+
- Process data for assertion [Success]
44+
- Prepare exposable [Success]
5345

54-
- Now If you add `--result` flag to the command: it should show you the raw result output.
55-
56-
```bash
57-
chk http --result bitcoin-usd.chk
58-
HTTP/1.1 200 OK
59-
Content-Type: application/json; charset=utf-8
60-
Content-Length: 510
61-
Connection: keep-alive
62-
Date: Sun, 07 Aug 2022 06:10:39 GMT
63-
X-Powered-By: Express
64-
Access-Control-Allow-Origin: *
65-
ETag: W/"1fe-779b4c2b"
66-
X-Cache: Miss from cloudfront
67-
Via: 1.1 14193a789201b44415bebb86f9e5fe9c.cloudfront.net (CloudFront)
68-
X-Amz-Cf-Pop: SIN5-C1
69-
X-Amz-Cf-Id: IodB70Lc4gtw_oinJwEIQnzgu9q-HCW_OCVfiAzYUUgmlrJr9CaiGA==
70-
71-
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22981.487132414983, 'priceBtc': 1, 'volume': 17816663920.88816, 'marketCap': 439284944516.0738, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.03, 'priceChange1d': -0.9, 'priceChange1w': -3.09, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
46+
---
47+
-> Running `AssertEqual` on `$_response.code` [Success]
48+
-> Running `AssertIsInt` on `$_response.body.coin.priceBtc` [Success]
7249
```
7350

74-
- If you open `bitcoin-usd.chk` change like following, you should only get the API response body.
51+
- Congratulation! You have just tested an API. :wink::tada::confetti_ball:
52+
---
7553

76-
```yaml
77-
---
78-
version: default:http:0.7.2
79-
request:
80-
url: https://api.coinstats.app/public/v1/coins/bitcoin?currency=USD
81-
method: GET
82-
return: .body # <-- to get body of response
83-
```
54+
### Explanation
8455

85-
```bash
86-
chk http --result bitcoin-usd.chk
87-
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22981.487132414983, 'priceBtc': 1, 'volume': 17816663920.88816, 'marketCap': 439284944516.0738, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.03, 'priceChange1d': -0.9, 'priceChange1w': -3.09, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
88-
```
56+
We call this `bitcoin-usd-testcase.chk` a spec or specification file. The content that you put was a [testcase specification](/references/testcase-reference).
8957

90-
- now we will use `jq` json parser to get price data. [jq website](https://stedolan.github.io/jq/) here.
58+
Let us look into the content and see what we wrote.
9159

92-
```bash
93-
chk http --result bitcoin-usd.chk | jq '.coin.price'
94-
22981.487132414983 # <-- depends on the current value
95-
```
96-
---
97-
We just fetched a live API. You can use `chk http` as your scriptable http client like this :rocket::star2:.
60+
On 1st line we wrote document version with `version:` same as we do on other config files i.e. terraform, ansible, etc. This is not all too important now.
9861

99-
Going further you can customize different parameters for `request` block, [see here](/examples/http-examples), and write testcases [see here](/examples/testcase-examples).
62+
On 2nd line, we wrote a `request:` block, which define how to sent the request to server. More on this block on [http specification](/references/http-reference).
10063

101-
Based on your workflow, you should save these `.chk` files in git repository. So that you can re-run it later, from anywhere where **chkware** is installed. Cheers.
64+
Then we wrote a `asserts:` sub-section under `spec:` block which defines how to check the response those we received.
10265

103-
:wink::tada::confetti_ball:
66+
That's basically it. Find more [example specification](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config) on the repository.

0 commit comments

Comments
 (0)