Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add API e2e testing #1904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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 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" ]
14 changes: 14 additions & 0 deletions e2e/compose.yaml
Original file line number Diff line number Diff line change
@@ -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 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 test-suite.yaml --report md
32 changes: 32 additions & 0 deletions e2e/start.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 74 additions & 0 deletions e2e/test-suite.yaml
Original file line number Diff line number Diff line change
@@ -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