Skip to content

Commit

Permalink
test: add e2e testing for some basic APIs (#1387)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Dec 5, 2023
1 parent 1a59261 commit 8905f0e
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ jobs:
java-version: 11
- name: Build with Maven
run: mvn clean -B package --file pom.xml
- name: Build Image
env:
IMAGE_PUSH: false
IMAGE_LOAD: true
IMAGE_PLATFORM: linux/amd64
run: |
docker buildx create --use --name mybuilder --driver docker-container
docker buildx use mybuilder
./script/docker/server/build.sh
- name: Run E2E
run: |
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
cd e2e && ./start.sh
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: mvn install -DskipTests=false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ WeChat Group : Add friend `tan-cloud`, and will invite you to the group.
- [Jpom](https://gitee.com/dromara/Jpom) : 简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
- [ArgusDBM](https://github.com/zmops/ArgusDBM) : 开源数据库一体化监控平台,致力于监控所有数据库
- [WangMarket](http://www.wang.market/) : 开源 SAAS 云建站系统

- [API Testing](https://github.com/LinuxSuRen/api-testing):轻量级、可扩展的接口开发、测试工具

##### Sponsor

Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ HertzBeat 赫兹跳动是 [Dromara开源社区](https://dromara.org/) 下顶级
- [Jpom](https://gitee.com/dromara/Jpom) : 简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
- [ArgusDBM](https://github.com/zmops/ArgusDBM) : 开源数据库一体化监控平台,致力于监控所有数据库
- [WangMarket](http://www.wang.market/) : 开源 SAAS 云建站系统
- [API Testing](https://github.com/LinuxSuRen/api-testing):轻量级、可扩展的接口开发、测试工具

##### 赞助

Expand Down
6 changes: 6 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ghcr.io/linuxsuren/api-testing:master

WORKDIR /workspace
COPY . .

CMD [ "/workspace/entrypoint.sh" ]
2 changes: 2 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
demo:
docker compose up hertzbeat
14 changes: 14 additions & 0 deletions e2e/RADME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Please add the corresponding e2e (aka end-to-end) test cases if you add or update APIs.

## How to work
* Start and watch the [docker-compose](https://docs.docker.com/compose/) via [the script](start.sh)
* Run the e2e testing via [api-testing](https://github.com/LinuxSuRen/api-testing)
* It will run the test cases from top to bottom
* You can add the necessary asserts to it

## Run locally
Please follow these steps if you want to run the e2e testing locally.

> Please make sure you have installed docker-compose v2
* Change the directory to `e2e`, then execute `./start.sh`
24 changes: 24 additions & 0 deletions e2e/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.1'
services:
testing:
build:
context: .
environment:
SERVER: http://hertzbeat:1157
depends_on:
hertzbeat:
condition: service_healthy
links:
- hertzbeat
hertzbeat:
image: tancloud/hertzbeat
ports:
- 1157:1157
environment:
ALLOW_NONE_AUTHENTICATION: "yes"
healthcheck:
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/1157"]
interval: 3s
timeout: 60s
retries: 10
start_period: 3s
80 changes: 80 additions & 0 deletions e2e/data/monitor-http.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

{
"detected": false,
"collector": "",
"monitor": {
"intervals": 60,
"tags": [],
"app": "api",
"host": "127.0.0.1",
"name": "{{.param.monitorHTTP}}"
},
"params": [
{
"field": "host",
"type": 1,
"value": "127.0.0.1"
},
{
"field": "port",
"type": 0,
"value": 80
},
{
"field": "method",
"type": 1,
"value": "GET"
},
{
"field": "uri",
"type": 1,
"value": ""
},
{
"field": "ssl",
"type": 1,
"value": false
},
{
"field": "headers",
"type": 3
},
{
"field": "params",
"type": 3
},
{
"field": "timeout",
"type": 0
},
{
"field": "contentType",
"type": 1
},
{
"field": "payload",
"type": 1
},
{
"field": "authType",
"type": 1
},
{
"field": "username",
"type": 1
},
{
"field": "password",
"type": 1
},
{
"field": "keyword",
"type": 1
},
{
"field": "successCode",
"type": 4,
"value": "200, 201"
}
]
}
4 changes: 4 additions & 0 deletions e2e/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

atest run -p testsuite.yaml --report md
31 changes: 31 additions & 0 deletions e2e/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

file=$1
if [ "$file" == "" ]
then
file=compose.yaml
fi

docker-compose version
docker-compose -f "$file" up --build -d

while true
do
docker-compose -f "$file" ps | grep testing
if [ $? -eq 1 ]
then
code=-1
docker-compose -f "$file" logs | grep e2e-testing
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
if [ $? -eq 1 ]
then
code=0
echo "successed"
fi

docker-compose -f "$file" down
set -e
exit $code
fi
sleep 1
done
Loading

0 comments on commit 8905f0e

Please sign in to comment.