diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..90551896 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,22 @@ +name: E2E + +on: + pull_request: + branches: + - main + - dev + +concurrency: + group: ${{github.workflow}} - ${{github.ref}} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: E2E Testing + run: | + sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose + sudo chmod u+x /usr/local/bin/docker-compose + docker compose up --build testing --exit-code-from testing --remove-orphans diff --git a/docker-compose.yml b/docker-compose.yml index 802a7426..1d6fd3a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,18 @@ services: - DEMO_MODE=false volumes: - /data/orion-visor-space/docker-volumes/orion-visor-service/root-orion:/root/orion + healthcheck: + test: ["CMD", "curl", "http://127.0.0.1:9200/orion-visor/api/server/bootstrap/health"] + interval: 3s + timeout: 300s + retries: 200 + start_period: 3s depends_on: + orion-visor-mysql: + condition: service_healthy + orion-visor-redis: + condition: service_healthy + links: - orion-visor-mysql - orion-visor-redis orion-visor-mysql: @@ -34,6 +45,12 @@ services: - /data/orion-visor-space/docker-volumes/orion-visor-mysql/var-lib-mysql:/var/lib/mysql - /data/orion-visor-space/docker-volumes/orion-visor-mysql/var-lib-mysql-files:/var/lib/mysql-files - /data/orion-visor-space/docker-volumes/orion-visor-mysql/etc-mysql:/etc/mysql + healthcheck: + test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/3306"] + interval: 3s + timeout: 60s + retries: 10 + start_period: 3s orion-visor-redis: image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:2.0.9 privileged: true @@ -44,7 +61,23 @@ services: volumes: - /data/orion-visor-space/docker-volumes/orion-visor-redis/data:/data command: sh -c "redis-server /usr/local/redis.conf --requirepass $${REDIS_PASSWORD}" + healthcheck: + test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] + interval: 3s + timeout: 60s + retries: 10 + start_period: 3s orion-visor-adminer: image: adminer ports: - 8081:8080 + testing: + build: + context: e2e + environment: + SERVER: http://orion-visor-service:80 + depends_on: + orion-visor-service: + condition: service_healthy + links: + - orion-visor-service diff --git a/e2e/Dockerfile b/e2e/Dockerfile new file mode 100644 index 00000000..886f4f12 --- /dev/null +++ b/e2e/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/linuxsuren/api-testing:v0.0.17 + +WORKDIR /workspace +COPY . . + +CMD [ "/workspace/entrypoint.sh" ] diff --git a/e2e/entrypoint.sh b/e2e/entrypoint.sh new file mode 100755 index 00000000..2aa71863 --- /dev/null +++ b/e2e/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +atest run -p testsuite.yaml --report md diff --git a/e2e/testsuite.yaml b/e2e/testsuite.yaml new file mode 100644 index 00000000..76a444d6 --- /dev/null +++ b/e2e/testsuite.yaml @@ -0,0 +1,54 @@ +#!api-testing +# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json +name: orion-visor +api: | + {{default "http://orion-visor-service:80" (env "SERVER")}} +items: +- name: login + request: + api: /orion-visor/api/infra/auth/login + method: POST + header: + Content-type: application/json + body: | + {"username":"admin","password":"21232f297a57a5a743894a0e4a801fc3"} + expect: + bodyFieldsExpect: + code: 200 +- name: userPermission + request: + api: /orion-visor/api/infra/permission/user + header: + Authorization: Bearer {{.login.data.token}} + expect: + bodyFieldsExpect: + code: 200 + msg: "success" +- name: menu + request: + api: /orion-visor/api/infra/permission/menu + header: + Authorization: Bearer {{.login.data.token}} + expect: + bodyFieldsExpect: + code: 200 + msg: "success" +- name: haveUnRead + request: + api: /orion-visor/api/infra/system-message/has-unread + header: + Authorization: Bearer {{.login.data.token}} + expect: + bodyFieldsExpect: + data: false +- name: queryOperatorLog + request: + api: /orion-visor/api/infra/mine/query-operator-log + method: POST +- name: hostList + request: + api: /orion-visor/api/infra/tag/list?type=HOST +- name: queryHost + request: + api: /orion-visor/api/asset/host/query + method: POST