2023-04-12 13:31:52 +08:00
|
|
|
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/3f16717cd6f841118006f12c346e9341)](https://www.codacy.com/gh/LinuxSuRen/api-testing/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=LinuxSuRen/api-testing\&utm_campaign=Badge_Grade)
|
|
|
|
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/3f16717cd6f841118006f12c346e9341)](https://www.codacy.com/gh/LinuxSuRen/api-testing/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=LinuxSuRen/api-testing\&utm_campaign=Badge_Coverage)
|
2023-03-05 11:32:27 +08:00
|
|
|
![GitHub All Releases](https://img.shields.io/github/downloads/linuxsuren/api-testing/total)
|
2023-05-24 19:51:21 +08:00
|
|
|
![](https://sloc.xyz/github/linuxsuren/api-testing)
|
2023-05-09 21:41:46 +08:00
|
|
|
[![LinuxSuRen/open-source-best-practice](https://img.shields.io/static/v1?label=OSBP&message=%E5%BC%80%E6%BA%90%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5&color=blue)](https://github.com/LinuxSuRen/open-source-best-practice)
|
2023-03-05 11:32:27 +08:00
|
|
|
|
2022-06-08 17:32:17 +08:00
|
|
|
This is a API testing tool.
|
2023-03-05 11:32:27 +08:00
|
|
|
|
2023-05-18 09:51:35 +08:00
|
|
|
## Features
|
2023-04-12 13:31:52 +08:00
|
|
|
|
|
|
|
* Response Body fields equation check
|
|
|
|
* Response Body [eval](https://expr.medv.io/)
|
2023-04-15 21:47:50 +08:00
|
|
|
* Verify the Kubernetes resources
|
2023-04-12 13:31:52 +08:00
|
|
|
* Validate the response body with [JSON schema](https://json-schema.org/)
|
2023-05-18 09:51:35 +08:00
|
|
|
* Pre and post handle with the API request
|
2023-04-12 13:31:52 +08:00
|
|
|
* Output reference between TestCase
|
2023-05-31 23:08:25 +08:00
|
|
|
* Run in server mode, and provide the [gRPC endpoint](pkg/server/server.proto)
|
2023-04-12 13:31:52 +08:00
|
|
|
* [VS Code extension](https://github.com/LinuxSuRen/vscode-api-testing) support
|
2023-06-07 22:59:47 +08:00
|
|
|
* [HTTP API record](extensions/collector)
|
2023-04-12 13:31:52 +08:00
|
|
|
|
|
|
|
## Get started
|
|
|
|
|
|
|
|
Install it via [hd](https://github.com/LinuxSuRen/http-downloader) or download from [releases](https://github.com/LinuxSuRen/api-testing/releases):
|
|
|
|
|
|
|
|
```shell
|
|
|
|
hd install atest
|
|
|
|
```
|
|
|
|
|
2023-05-31 23:08:25 +08:00
|
|
|
or, you can install it in Kubernetes. See also the [manifests](sample/manifest.yaml).
|
|
|
|
|
2023-04-12 13:31:52 +08:00
|
|
|
see the following usage:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
API testing tool
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
atest [command]
|
|
|
|
|
|
|
|
Available Commands:
|
|
|
|
completion Generate the autocompletion script for the specified shell
|
|
|
|
help Help about any command
|
|
|
|
json Print the JSON schema of the test suites struct
|
|
|
|
run Run the test suite
|
|
|
|
sample Generate a sample test case YAML file
|
|
|
|
server Run as a server mode
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
-h, --help help for atest
|
|
|
|
-v, --version version for atest
|
|
|
|
|
|
|
|
Use "atest [command] --help" for more information about a command.
|
|
|
|
```
|
|
|
|
|
|
|
|
below is an example of the usage, and you could see the report as well:
|
|
|
|
|
2023-04-20 17:49:00 +08:00
|
|
|
`atest run -p sample/testsuite-gitlab.yaml --duration 1m --thread 3 --report md`
|
2023-04-12 13:31:52 +08:00
|
|
|
|
|
|
|
| API | Average | Max | Min | Count | Error |
|
|
|
|
|---|---|---|---|---|---|
|
|
|
|
| GET https://gitlab.com/api/v4/projects | 1.152777167s | 2.108680194s | 814.928496ms | 99 | 0 |
|
|
|
|
| GET https://gitlab.com/api/v4/projects/45088772 | 840.761064ms | 1.487285371s | 492.583066ms | 10 | 0 |
|
|
|
|
consume: 1m2.153686448s
|
2023-03-05 11:32:27 +08:00
|
|
|
|
|
|
|
## Template
|
2023-04-12 13:31:52 +08:00
|
|
|
|
2023-03-05 11:32:27 +08:00
|
|
|
The following fields are templated with [sprig](http://masterminds.github.io/sprig/):
|
|
|
|
|
2023-04-12 13:31:52 +08:00
|
|
|
* API
|
|
|
|
* Request Body
|
|
|
|
* Request Header
|
2023-03-10 15:42:19 +08:00
|
|
|
|
2023-04-24 12:20:49 +08:00
|
|
|
### Functions
|
|
|
|
|
|
|
|
You could use all the common functions which comes from [sprig](http://masterminds.github.io/sprig/). Besides some specific functions are available:
|
|
|
|
|
|
|
|
| Name | Usage |
|
|
|
|
|---|---|
|
|
|
|
| `randomKubernetesName` | `{{randomKubernetesName}}` to generate Kubernetes resource name randomly, the name will have 8 chars |
|
2023-05-18 09:51:35 +08:00
|
|
|
| `sleep` | `{{sleep(1)}}` in the pre and post request handle |
|
2023-04-24 12:20:49 +08:00
|
|
|
|
2023-04-15 21:47:50 +08:00
|
|
|
## Verify against Kubernetes
|
|
|
|
|
|
|
|
It could verify any kinds of Kubernetes resources. Please set the environment variables before using it:
|
|
|
|
|
|
|
|
* `KUBERNETES_SERVER`
|
|
|
|
* `KUBERNETES_TOKEN`
|
|
|
|
|
|
|
|
See also the [example](sample/kubernetes.yaml).
|
|
|
|
|
2023-03-10 15:42:19 +08:00
|
|
|
## TODO
|
2023-04-12 13:31:52 +08:00
|
|
|
|
|
|
|
* Reduce the size of context
|
|
|
|
* Support customized context
|
2023-03-05 11:32:27 +08:00
|
|
|
|
|
|
|
## Limit
|
2023-04-12 13:31:52 +08:00
|
|
|
|
|
|
|
* Only support to parse the response body when it's a map or array
|