diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml new file mode 100644 index 000000000..17544c959 --- /dev/null +++ b/.github/workflows/scheme_test.yml @@ -0,0 +1,71 @@ +name: Proxy Schema Test + +on: + workflow_dispatch: + inputs: + NETWORK: + description: 'Network to run test on' + required: true + default: 'local' + type: choice + options: + - local + - dev + - qa + - test + - main + push: + pull_request: + branches: + - development + + +jobs: + api-tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: grid-proxy + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Setting up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Installing all necessary packages + run: pip install -r tests/schema_test/requirments.txt + + - name: Build + env: + MNEMONICS: ${{ secrets.MNEMONICS }} + run: | + go mod tidy + make db-start + make db-fill + make server-start m="$MNEMONICS" & + + - name: Wait on localhost + uses: iFaxity/wait-on-action@v1 + with: + resource: http://localhost:8080 + + - name: Run tests + run: NETWORK=${{ github.event.inputs.NETWORK }} python3 -m pytest -v ./tests/schema_test/ --html=./tests/schema_test/report.html + + - name: Upload pytest test results + uses: actions/upload-artifact@v4 + with: + name: schema-pytest-results + path: | + ///home/runner/work/tfgrid-sdk-go/tfgrid-sdk-go/grid-proxy/tests/schema_test/report.html + ///home/runner/work/tfgrid-sdk-go/tfgrid-sdk-go/grid-proxy/tests/schema_test/assets + if: ${{ always() }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index be8c48dbb..718c96424 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ coverage/ bin/ dist/ + +.hypothesis \ No newline at end of file diff --git a/grid-proxy/tests/schema_test/requirments.txt b/grid-proxy/tests/schema_test/requirments.txt new file mode 100644 index 000000000..be9b97e31 --- /dev/null +++ b/grid-proxy/tests/schema_test/requirments.txt @@ -0,0 +1,3 @@ +pytest==7.3.1 +schemathesis==3.24.3 +pytest-html==4.1.1 \ No newline at end of file diff --git a/grid-proxy/tests/schema_test/test_schema.py b/grid-proxy/tests/schema_test/test_schema.py new file mode 100644 index 000000000..e538f3351 --- /dev/null +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -0,0 +1,25 @@ +import os +import pytest +import schemathesis +from schemathesis.checks import not_a_server_error, status_code_conformance, content_type_conformance, response_schema_conformance, response_headers_conformance + +network = os.environ['NETWORK'] +if network == 'main': + url = 'https://gridproxy.grid.tf' + swagger = 'https://gridproxy.grid.tf/swagger/doc.json' + schema = schemathesis.from_uri(swagger, base_url = url) +elif network == '': + url = 'http://localhost:8080' + swagger = "docs/swagger.json" + schema = schemathesis.from_path(swagger, base_url = url) +else: + url = 'https://gridproxy.' + network + '.grid.tf' + swagger = 'https://gridproxy.' + network + '.grid.tf/swagger/doc.json' + schema = schemathesis.from_uri(swagger, base_url = url) + + +@pytest.mark.parametrize("check", [not_a_server_error, status_code_conformance, content_type_conformance, response_schema_conformance, response_headers_conformance]) +@schema.parametrize() +def test_api(case, check): + response = case.call() + case.validate_response(response, checks=(check,)) \ No newline at end of file