forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e testing for the backend
Signed-off-by: Rick <[email protected]>
- Loading branch information
1 parent
457e059
commit 2e77ff9
Showing
7 changed files
with
206 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM linuxsuren/api-testing:v0.0.14 | ||
WORKDIR /workspace | ||
COPY testsuite.yaml . | ||
CMD [ "atest", "run", "-p", "testsuite.yaml", "--level=debug" ] |
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,17 @@ | ||
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) | ||
* It has three containers: database, Halo, and testing | ||
* 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 | ||
* Build project via `./gradlew clean build -x check` in root directory of this repository | ||
* Build image via `docker build . -t ghcr.io/halo-dev/halo-dev:dev` | ||
* Change the directory to `e2e`, then execute `./start.sh` |
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,48 @@ | ||
version: '3.1' | ||
services: | ||
testing: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
links: | ||
- halo | ||
depends_on: | ||
halo: | ||
condition: service_healthy | ||
halo: | ||
image: ghcr.io/halo-dev/halo-dev:dev | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"] | ||
interval: 30s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 30s | ||
command: | ||
- --spring.r2dbc.url=r2dbc:pool:postgresql://halodb/halo | ||
- --spring.r2dbc.username=halo | ||
# PostgreSQL 的密码,请保证与下方 POSTGRES_PASSWORD 的变量值一致。 | ||
- --spring.r2dbc.password=openpostgresql | ||
- --spring.sql.init.platform=postgresql | ||
# 外部访问地址,请根据实际需要修改 | ||
# - --halo.external-url=http://localhost:8090/ | ||
links: | ||
- postgresql | ||
depends_on: | ||
postgresql: | ||
condition: service_healthy | ||
postgresql: | ||
image: postgres:15.4 | ||
container_name: halodb | ||
restart: on-failure:3 | ||
ports: | ||
- "5432:5432" | ||
healthcheck: | ||
test: [ "CMD", "pg_isready" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
environment: | ||
- POSTGRES_PASSWORD=openpostgresql | ||
- POSTGRES_USER=halo | ||
- POSTGRES_DB=halo | ||
- PGUSER=halo |
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,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 |
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,86 @@ | ||
name: halo | ||
api: | | ||
{{default "http://halo:8090" (env "SERVER")}}/apis | ||
param: | ||
postName: "{{randAlpha 6}}" | ||
items: | ||
- name: init | ||
request: | ||
api: /api.console.halo.run/v1alpha1/system/initialize | ||
method: POST | ||
header: | ||
Content-Type: application/json | ||
body: | | ||
{ | ||
"siteTitle": "testing", | ||
"username": "admin", | ||
"password": "123456", | ||
"email": "[email protected]", | ||
"password_confirm": "123456" | ||
} | ||
expect: | ||
statusCode: 201 | ||
- name: createPost | ||
request: | ||
api: /api.console.halo.run/v1alpha1/posts | ||
method: POST | ||
header: | ||
Authorization: "Basic YWRtaW46MTIzNDU2" | ||
Content-Type: application/json | ||
body: | | ||
{ | ||
"post": { | ||
"spec": { | ||
"title": "{{.param.postName}}", | ||
"slug": "{{.param.postName}}", | ||
"template": "", | ||
"cover": "", | ||
"deleted": false, | ||
"publish": false, | ||
"pinned": false, | ||
"allowComment": true, | ||
"visible": "PUBLIC", | ||
"priority": 0, | ||
"excerpt": { | ||
"autoGenerate": true, | ||
"raw": "" | ||
}, | ||
"categories": [], | ||
"tags": [], | ||
"htmlMetas": [] | ||
}, | ||
"apiVersion": "content.halo.run/v1alpha1", | ||
"kind": "Post", | ||
"metadata": { | ||
"name": "c31f2192-c992-47b9-86b4-f3fc0605360e", | ||
"annotations": { | ||
"content.halo.run/preferred-editor": "default" | ||
} | ||
} | ||
}, | ||
"content": { | ||
"raw": "<p>{{.param.postName}}</p>", | ||
"content": "<p>{{.param.postName}}</p>", | ||
"rawType": "HTML" | ||
} | ||
} | ||
- name: listPosts | ||
request: | ||
api: /api.console.halo.run/v1alpha1/posts?keyword={{.param.postName}} | ||
header: | ||
Authorization: "Basic YWRtaW46MTIzNDU2" | ||
expect: | ||
verify: | ||
- data.total == 1 | ||
- name: recyclePost | ||
request: | ||
api: /api.console.halo.run/v1alpha1/posts/{{(index .listPosts.items 0).post.metadata.name}}/recycle | ||
method: PUT | ||
header: | ||
Authorization: "Basic YWRtaW46MTIzNDU2" | ||
- name: recover | ||
request: | ||
api: /content.halo.run/v1alpha1/posts/{{(index .listPosts.items 0).post.metadata.name}} | ||
method: DELETE | ||
header: | ||
Authorization: "Basic YWRtaW46MTIzNDU2" |