Skip to content

Commit 251ec06

Browse files
committed
test: add e2e testing for some basic APIs
1 parent 1a59261 commit 251ec06

File tree

11 files changed

+409
-1
lines changed

11 files changed

+409
-1
lines changed

.github/workflows/maven-build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ jobs:
2222
java-version: 11
2323
- name: Build with Maven
2424
run: mvn clean -B package --file pom.xml
25+
- name: Build Image
26+
env:
27+
IMAGE_PUSH: false
28+
IMAGE_LOAD: true
29+
IMAGE_PLATFORM: linux/amd64
30+
run: |
31+
docker buildx create --use --name mybuilder --driver docker-container
32+
docker buildx use mybuilder
33+
34+
./script/docker/server/build.sh
35+
- name: Run E2E
36+
run: |
37+
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
38+
sudo chmod u+x /usr/local/bin/docker-compose
39+
40+
cd e2e && ./start.sh

.gitpod.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This configuration file was automatically generated by Gitpod.
2+
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
3+
# and commit this file to your remote git repository to share the goodness with others.
4+
5+
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
6+
7+
tasks:
8+
- init: mvn install -DskipTests=false

e2e/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/linuxsuren/api-testing:master
2+
3+
WORKDIR /workspace
4+
COPY . .
5+
6+
CMD [ "/workspace/entrypoint.sh" ]

e2e/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
demo:
2+
docker compose up hertzbeat

e2e/RADME.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Please add the corresponding e2e (aka end-to-end) test cases if you add or update APIs.
2+
3+
## How to work
4+
* Start and watch the [docker-compose](https://docs.docker.com/compose/) via [the script](start.sh)
5+
* Run the e2e testing via [api-testing](https://github.com/LinuxSuRen/api-testing)
6+
* It will run the test cases from top to bottom
7+
* You can add the necessary asserts to it
8+
9+
## Run locally
10+
Please follow these steps if you want to run the e2e testing locally.
11+
12+
> Please make sure you have installed docker-compose v2
13+
14+
* Change the directory to `e2e`, then execute `./start.sh`

e2e/compose.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.1'
2+
services:
3+
testing:
4+
build:
5+
context: .
6+
environment:
7+
SERVER: http://hertzbeat:1157
8+
depends_on:
9+
hertzbeat:
10+
condition: service_healthy
11+
links:
12+
- hertzbeat
13+
hertzbeat:
14+
image: tancloud/hertzbeat
15+
ports:
16+
- 1157:1157
17+
environment:
18+
ALLOW_NONE_AUTHENTICATION: "yes"
19+
healthcheck:
20+
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/1157"]
21+
interval: 3s
22+
timeout: 60s
23+
retries: 10
24+
start_period: 3s

e2e/data/monitor-http.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
{
3+
"detected": false,
4+
"collector": "",
5+
"monitor": {
6+
"intervals": 60,
7+
"tags": [],
8+
"app": "api",
9+
"host": "127.0.0.1",
10+
"name": "{{.param.monitorHTTP}}"
11+
},
12+
"params": [
13+
{
14+
"field": "host",
15+
"type": 1,
16+
"value": "127.0.0.1"
17+
},
18+
{
19+
"field": "port",
20+
"type": 0,
21+
"value": 80
22+
},
23+
{
24+
"field": "method",
25+
"type": 1,
26+
"value": "GET"
27+
},
28+
{
29+
"field": "uri",
30+
"type": 1,
31+
"value": ""
32+
},
33+
{
34+
"field": "ssl",
35+
"type": 1,
36+
"value": false
37+
},
38+
{
39+
"field": "headers",
40+
"type": 3
41+
},
42+
{
43+
"field": "params",
44+
"type": 3
45+
},
46+
{
47+
"field": "timeout",
48+
"type": 0
49+
},
50+
{
51+
"field": "contentType",
52+
"type": 1
53+
},
54+
{
55+
"field": "payload",
56+
"type": 1
57+
},
58+
{
59+
"field": "authType",
60+
"type": 1
61+
},
62+
{
63+
"field": "username",
64+
"type": 1
65+
},
66+
{
67+
"field": "password",
68+
"type": 1
69+
},
70+
{
71+
"field": "keyword",
72+
"type": 1
73+
},
74+
{
75+
"field": "successCode",
76+
"type": 4,
77+
"value": "200, 201"
78+
}
79+
]
80+
}

e2e/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
atest run -p testsuite.yaml --report md

e2e/start.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
file=$1
4+
if [ "$file" == "" ]
5+
then
6+
file=compose.yaml
7+
fi
8+
9+
docker-compose version
10+
docker-compose -f "$file" up --build -d
11+
12+
while true
13+
do
14+
docker-compose -f "$file" ps | grep testing
15+
if [ $? -eq 1 ]
16+
then
17+
code=-1
18+
docker-compose -f "$file" logs | grep e2e-testing
19+
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
20+
if [ $? -eq 1 ]
21+
then
22+
code=0
23+
echo "successed"
24+
fi
25+
26+
docker-compose -f "$file" down
27+
set -e
28+
exit $code
29+
fi
30+
sleep 1
31+
done

0 commit comments

Comments
 (0)