test: add e2e test cases of user, role, and plugin (#4920)

* chore: provide an out-of-the-box gitpod config file

* test: add e2e test cases of user, role, and plugin

---------

Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
Co-authored-by: John Niang <johnniang@foxmail.com>
This commit is contained in:
Rick 2023-11-28 21:52:44 +08:00 committed by GitHub
parent 99edbddfa2
commit ce5c1f9052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 183 additions and 8 deletions

View File

@ -91,5 +91,5 @@ jobs:
sudo chmod u+x /usr/local/bin/docker-compose
repo=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
docker tag ghcr.io/${repo}/halo-dev:pr-${{ github.event.number }} ghcr.io/halo-dev/halo-dev:dev
docker tag ghcr.io/${repo}/halo-dev:pr-${{ github.event.number }} ghcr.io/halo-dev/halo-dev:main
cd e2e && ./start.sh

1
.gitignore vendored
View File

@ -64,7 +64,6 @@ nbdist/
### VSCode
.vscode
.gitpod.yml
### Local file
application-local.yml

8
.gitpod.yml Normal file
View File

@ -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: ./gradlew clean build -x check && sdk install java 17.0.3-ms

View File

@ -13,5 +13,12 @@ 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`
* Build image via `docker build . -t ghcr.io/halo-dev/halo-dev:main`
* Change the directory to `e2e`, then execute `./start.sh`
## Run Halo only
Please run the following command if you only want to run Halo.
```shell
docker-compose up halo
```

View File

@ -10,7 +10,7 @@ services:
halo:
condition: service_healthy
halo:
image: ghcr.io/halo-dev/halo-dev:dev
image: ghcr.io/halo-dev/halo-dev:${TAG:-main}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"]
interval: 30s
@ -25,6 +25,8 @@ services:
- --spring.sql.init.platform=postgresql
# 外部访问地址,请根据实际需要修改
# - --halo.external-url=http://localhost:8090/
ports:
- 8090:8090
links:
- postgresql
depends_on:

View File

@ -4,6 +4,7 @@ api: |
param:
postName: "{{randAlpha 6}}"
userName: "{{randAlpha 6}}"
roleName: "{{randAlpha 6}}"
notificationName: "{{randAlpha 6}}"
auth: "Basic YWRtaW46MTIzNDU2"
items:
@ -28,7 +29,7 @@ items:
api: /api.console.halo.run/v1alpha1/posts
method: POST
header:
Authorization: "Basic YWRtaW46MTIzNDU2"
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
@ -71,7 +72,7 @@ items:
request:
api: /api.console.halo.run/v1alpha1/posts?keyword={{.param.postName}}
header:
Authorization: "Basic YWRtaW46MTIzNDU2"
Authorization: "{{.param.auth}}"
expect:
verify:
- data.total == 1
@ -80,13 +81,171 @@ items:
api: /api.console.halo.run/v1alpha1/posts/{{(index .listPosts.items 0).post.metadata.name}}/recycle
method: PUT
header:
Authorization: "Basic YWRtaW46MTIzNDU2"
Authorization: "{{.param.auth}}"
- name: recover
request:
api: /content.halo.run/v1alpha1/posts/{{(index .listPosts.items 0).post.metadata.name}}
method: DELETE
header:
Authorization: "Basic YWRtaW46MTIzNDU2"
Authorization: "{{.param.auth}}"
## Users
- name: createUser
request:
api: /api.console.halo.run/v1alpha1/users
method: POST
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"avatar": "",
"bio": "{{randAlpha 6}}",
"displayName": "{{randAlpha 6}}",
"email": "test@halo.com",
"name": "{{.param.userName}}",
"password": "{{randAlpha 6}}",
"phone": "",
"roles": []
}
- name: updateUserPass
request:
api: /api.console.halo.run/v1alpha1/users/{{.param.userName}}/password
method: PUT
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"password": "{{randAlpha 3}}"
}
- name: grantPermission
request:
api: /api.console.halo.run/v1alpha1/users/{{.param.userName}}/permissions
method: POST
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"roles": [
"guest"
]
}
- name: deleteUser
request:
api: |
{{default "http://halo:8090" (env "SERVER")}}/api/v1alpha1/users/{{.param.userName}}
method: DELETE
header:
Authorization: "{{.param.auth}}"
## Roles
- name: createRole
request:
api: |
{{default "http://halo:8090" (env "SERVER")}}/api/v1alpha1/roles
method: POST
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"apiVersion": "v1alpha1",
"kind": "Role",
"metadata": {
"name": "",
"generateName": "role-",
"labels": {},
"annotations": {
"rbac.authorization.halo.run/dependencies": "[\"role-template-manage-appstore\"]",
"rbac.authorization.halo.run/display-name": "{{.param.roleName}}"
}
},
"rules": []
}
expect:
statusCode: 201
- name: listRoles
request:
api: |
{{default "http://halo:8090" (env "SERVER")}}/api/v1alpha1/roles
header:
Authorization: "{{.param.auth}}"
expect:
verify:
- data.total >= 3
- name: deleteRole
request:
api: |
{{default "http://halo:8090" (env "SERVER")}}/api/v1alpha1/roles/{{(index .listRoles.items 0).metadata.name}}
method: DELETE
header:
Authorization: "{{.param.auth}}"
## Plugins
- name: installPlugin
request:
api: /api.console.halo.run/v1alpha1/plugins/-/install-from-uri
method: POST
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"uri": "https://github.com/Stonewuu/halo-plugin-sitepush/releases/download/1.3.1/halo-plugin-sitepush-1.3.1.jar"
}
- name: pluginList
request:
api: /api.console.halo.run/v1alpha1/plugins
header:
Authorization: "{{.param.auth}}"
expect:
verify:
- data.total >= 1
- name: inActivePlugins
request:
api: /api.console.halo.run/v1alpha1/plugins?enabled=false&keyword=&page=0&size=0
header:
Authorization: "{{.param.auth}}"
expect:
verify:
- data.total == 1
- name: disablePlugin
request:
api: /api.console.halo.run/v1alpha1/plugins/PluginSitePush/plugin-state
method: PUT
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"enable": false
}
- name: enablePlugin
request:
api: /api.console.halo.run/v1alpha1/plugins/PluginSitePush/plugin-state
method: PUT
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
body: |
{
"enable": true
}
- name: resetPlugin
request:
api: /api.console.halo.run/v1alpha1/plugins/PluginSitePush/reset-config
method: PUT
header:
Authorization: "{{.param.auth}}"
Content-Type: application/json
- name: uninstallPlugin
request:
api: /plugin.halo.run/v1alpha1/plugins/PluginSitePush
method: DELETE
header:
Authorization: "{{.param.auth}}"
# Notifications
- name: createNotification