Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/site/content/zh/latest/tasks/mock/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ items:
response:
header:
server: mock
content-type: application/json
body: |
{
"count": 1,
"items": [{
"title": "fix: there is a bug on page {{ randEnum "one" }}",
"number": 123,
"title": "fix: there is a bug on page {{ randEnum "one" "two" "three" "four" }}",
"number": {{randInt 100 199}},
"float": {{randFloat 0.0 1.0}},
"status": "{{randWeightEnum (weightObject 4 "open") (weightObject 1 "closed")}}",
"message": "{{.Response.Header.server}}",
"author": "someone",
"status": "success"
}]
"author": "{{env "USER"}}",
"created": "{{ now.Format "2006-01-02T15:04:05Z07:00" }}"
}],
"uptime": "{{uptime}}"
}
- name: base64
request:
Expand Down
26 changes: 25 additions & 1 deletion docs/site/content/zh/latest/tasks/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,28 @@ title = "用例模板"

```
182{{shuffle "09876543"}}
```
```

## 带权重的随机枚举

下面的代码以 80% 的概率返回 `open`,以 20% 的概率返回 `closed`:

```
{{randWeightEnum (weightObject 4 "open") (weightObject 1 "closed")}}
```

## 时间

下面的代码可以生成当前时间,并制定时间格式:

```
{{ now.Format "2006-01-02T15:04:05Z07:00" }}
```

## 环境变量

下面的代码可以获取环境变量 `SHELL` 的值,在需要使用一个全局变量的时候,可以使用这个模板函数:

```
{{ env "SHELL" }}
```
Loading
Loading