-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support to config mock server on ui (#552)
* doc: add document of atest extension * feat: support to config mock server on ui * add more document * Fix code scanning alert no. 61: Incorrect conversion between integer types Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Rick <[email protected]> --------- Signed-off-by: Rick <[email protected]> Co-authored-by: rick <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7d9a97f
commit bbaf91f
Showing
17 changed files
with
531 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
+++ | ||
title = "插件" | ||
+++ | ||
|
||
`atest` 会把非核心、可扩展的功能以插件(extension)的形式实现。下面介绍有哪些插件,以及如何使用: | ||
|
||
> 在不同的系统中,插件有着不同的表述,例如:extension、plugin 等。 | ||
| 类型 | 名称 | 描述 | | ||
|------|------|------| | ||
| 存储 | [orm](https://github.com/LinuxSuRen/atest-ext-store-orm) | 保存数据到关系型数据库中,例如:MySQL | | ||
| 存储 | [s3](https://github.com/LinuxSuRen/atest-ext-store-s3) | 保存数据到对象存储中 | | ||
| 存储 | [etcd](https://github.com/LinuxSuRen/atest-ext-store-etcd) | 保存数据到 Etcd 数据库中 | | ||
| 存储 | [git](https://github.com/LinuxSuRen/atest-ext-store-git) | 保存数据到 Git 仓库中 | | ||
| 存储 | [mongodb](https://github.com/LinuxSuRen/atest-ext-store-mongodb) | 保存数据到 MongDB 中 | | ||
|
||
> `atest` 也是唯一支持如此丰富的存储的接口开发、测试的开源工具。 | ||
## 下载插件 | ||
|
||
我们建议通过如下的命令来下载插件: | ||
|
||
```shell | ||
atest extension orm | ||
``` | ||
|
||
上面的命令,会识别当前的操作系统,自动下载最新版本的插件。当然,用户可以通过自行编译、手动下载的方式获取插件二进制文件。 | ||
|
||
`atest` 可以从任意支持 OCI 的镜像仓库中(命令参数说明中给出了支持的镜像服务地址)下载插件,也可以指定下载超时时间: | ||
|
||
```shell | ||
atest extension orm --registry ghcr.io --timeout 2ms | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
+++ | ||
title = "Mock 服务" | ||
+++ | ||
|
||
Mock 服务在前后端并行开发、系统对接、设备对接场景下能起到非常好的作用,可以极大地降低团队之间、系统之间的耦合度。 | ||
|
||
用户可以通过命令行终端(CLI)、Web UI 的方式来使用 Mock 服务。 | ||
|
||
## 命令行 | ||
|
||
```shell | ||
atest mock --prefix / --port 9090 mock.yaml | ||
``` | ||
|
||
## Web | ||
|
||
在 UI 上可以实现和命令行相同的功能,并可以通过页面编辑的方式修改、加载 Mock 服务配置。 | ||
|
||
## 语法 | ||
|
||
从整体上来看,我们的写法和 HTTP 的名称基本保持一致,用户无需再了解额外的名词。此外,提供两种描述 Mock 服务的方式: | ||
|
||
* 针对某个数据对象的 CRUD | ||
* 任意 HTTP 服务 | ||
|
||
下面是一个具体的例子: | ||
|
||
```yaml | ||
#!api-testing-mock | ||
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-mock-schema.json | ||
objects: | ||
- name: repo | ||
fields: | ||
- name: name | ||
kind: string | ||
- name: url | ||
kind: string | ||
- name: projects | ||
initCount: 3 | ||
sample: | | ||
{ | ||
"name": "api-testing", | ||
"color": "{{ randEnum "blue" "read" "pink" }}" | ||
} | ||
items: | ||
- name: base64 | ||
request: | ||
path: /v1/base64 | ||
response: | ||
body: aGVsbG8= | ||
encoder: base64 | ||
- name: prList | ||
request: | ||
path: /v1/repos/{repo}/prs | ||
header: | ||
name: rick | ||
response: | ||
header: | ||
server: mock | ||
body: | | ||
{ | ||
"count": 1, | ||
"items": [{ | ||
"title": "fix: there is a bug on page {{ randEnum "one" }}", | ||
"number": 123, | ||
"message": "{{.Response.Header.server}}", | ||
"author": "someone", | ||
"status": "success" | ||
}] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
+++ | ||
title = "测试用例验证" | ||
+++ | ||
|
||
`atest` 采用 https://expr.medv.io 对 HTTP 请求响应的验证,比如:返回的数据列表长度验证、具体值的验证等等。下面给出一些例子: | ||
|
||
> 需要注意的是,`data` 指的是 HTTP Response Body(响应体)的 JSON 对象。 | ||
## 数组长度判断 | ||
|
||
```yaml | ||
- name: projectKinds | ||
request: | ||
api: /api/resources/projectKinds | ||
expect: | ||
verify: | ||
- len(data.data) == 6 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.