test: add API e2e testing

This commit is contained in:
rick 2023-12-07 02:26:46 +00:00 committed by Rick
parent 88409cc1f0
commit 2f22246e29
7 changed files with 148 additions and 0 deletions

View file

@ -33,3 +33,10 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v2
- name: E2E
run: |
CGO_ENABLED=0 go build -o cloudreve .
docker build . -t cloudreve/cloudreve:latest
cd e2e && ./start.sh

11
.gitpod.yml Normal file
View file

@ -0,0 +1,11 @@
# 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: go get && go build ./... && go test ./...
command: go run .

6
e2e/Dockerfile Normal file
View file

@ -0,0 +1,6 @@
FROM ghcr.io/linuxsuren/api-testing:master
WORKDIR /workspace
COPY . .
CMD [ "/workspace/entrypoint.sh" ]

14
e2e/compose.yaml Normal file
View file

@ -0,0 +1,14 @@
version: '3.1'
services:
testing:
build:
context: .
environment:
SERVER: http://cloudreve:5212
depends_on:
cloudreve:
condition: service_started
links:
- cloudreve
cloudreve:
image: cloudreve/cloudreve:latest

4
e2e/entrypoint.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
set -e
atest run -p test-suite.yaml --report md

32
e2e/start.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
file=$1
if [ "$file" == "" ]
then
file=compose.yaml
fi
docker-compose version
docker-compose -f "$file" up --build -d --pull=never
while true
do
docker-compose -f "$file" ps | grep testing
if [ $? -eq 1 ]
then
code=-1
docker-compose -f "$file" logs | grep e2e-cloudreve
docker-compose -f "$file" logs | grep e2e-testing
docker-compose ps -a | grep e2e-testing | grep "Exited (0)"
if [ $? -eq 0 ]
then
code=0
echo "successed"
fi
docker-compose -f "$file" down
set -e
exit $code
fi
sleep 1
done

74
e2e/test-suite.yaml Normal file
View file

@ -0,0 +1,74 @@
#!api-testing
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
name: atest
api: |
{{default "http://localhost:5212" (env "SERVER")}}/api/v3
param:
username: admin@admin.com
password: "123456"
items:
- name: signup
request:
api: /user
method: POST
header:
Content-Type: application/json
body: |
{
"userName": "{{.param.username}}",
"Password": "{{.param.password}}",
"captchaCode": ""
}
- name: login
request:
api: /user/session
method: POST
header:
Content-Type: application/json
body: |
{
"userName": "{{.param.username}}",
"Password": "{{.param.password}}",
"captchaCode": ""
}
- name: login-failed
request:
api: /user/session
method: POST
header:
Content-Type: application/json
body: |
{
"userName": "{{.param.username}}",
"Password": "wrong-pass",
"captchaCode": ""
}
expect:
bodyFieldsExpect:
code: "40020"
- name: getStorageInfo
request:
api: /user/storage
expect:
bodyFieldsExpect:
code: "0"
- name: addTag
request:
api: /tag/filter
method: POST
header:
Content-Type: application/json
body: |
{
"expression": "{{randAlpha 4}}",
"name": "{{randAlpha 4}}",
"color": "rgba(0, 0, 0, 0.54)",
"icon": "Circle"
}
- name: getSetting
request:
api: /user/setting
- name: signOff
request:
api: /user/session
method: DELETE