diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17a6ecf610..d6c1bdd5f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000000..29c34fc209 --- /dev/null +++ b/.gitpod.yml @@ -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 . + + diff --git a/e2e/Dockerfile b/e2e/Dockerfile new file mode 100644 index 0000000000..4e0ea4f245 --- /dev/null +++ b/e2e/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/linuxsuren/api-testing:master + +WORKDIR /workspace +COPY . . + +CMD [ "/workspace/entrypoint.sh" ] diff --git a/e2e/compose.yaml b/e2e/compose.yaml new file mode 100644 index 0000000000..04c3dd0921 --- /dev/null +++ b/e2e/compose.yaml @@ -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 diff --git a/e2e/entrypoint.sh b/e2e/entrypoint.sh new file mode 100755 index 0000000000..e78ba4005e --- /dev/null +++ b/e2e/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +atest run -p test-suite.yaml --report md diff --git a/e2e/start.sh b/e2e/start.sh new file mode 100755 index 0000000000..b7a0c2bbac --- /dev/null +++ b/e2e/start.sh @@ -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 diff --git a/e2e/test-suite.yaml b/e2e/test-suite.yaml new file mode 100644 index 0000000000..7bf179b18b --- /dev/null +++ b/e2e/test-suite.yaml @@ -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