From 77db32f712066aa94e91eafa569eccdb3f70511b Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 30 Jan 2024 13:20:00 +0200 Subject: [PATCH 1/8] add tests, requirment and workflow --- .github/workflows/scheme_test.yml | 75 ++++++++++++++++++++ grid-proxy/tests/schema_test/requirments.txt | 3 + grid-proxy/tests/schema_test/test_schema.py | 18 +++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/scheme_test.yml create mode 100644 grid-proxy/tests/schema_test/requirments.txt create mode 100644 grid-proxy/tests/schema_test/test_schema.py diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml new file mode 100644 index 000000000..c3831375f --- /dev/null +++ b/.github/workflows/scheme_test.yml @@ -0,0 +1,75 @@ +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: + + +jobs: + api-tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: grid-proxy + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: tfgrid-graphql + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + 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 + run: | + export PATH=/home/runner/go/bin:$PATH + export GIT_COMMIT=$(git rev-list -1 HEAD) + go build -ldflags "-X main.GitCommit=$GIT_COMMIT" cmds/proxy_server/main.go + env: + GO111MODULE: on + + - 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/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..90601e3d2 --- /dev/null +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -0,0 +1,18 @@ +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'] +url = 'http://localhost:8080' +if network == 'dev': + url = 'https://gridproxy.dev.grid.tf' + +schema = schemathesis.from_path("docs/swagger.json", 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 From f760915b1e4b851420cec456f8c968ec8fbedc56 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 30 Jan 2024 14:56:43 +0200 Subject: [PATCH 2/8] add all networks link and fix the localhost build --- grid-proxy/tests/schema_test/test_schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grid-proxy/tests/schema_test/test_schema.py b/grid-proxy/tests/schema_test/test_schema.py index 90601e3d2..7396fa5e6 100644 --- a/grid-proxy/tests/schema_test/test_schema.py +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -4,9 +4,12 @@ from schemathesis.checks import not_a_server_error, status_code_conformance, content_type_conformance, response_schema_conformance, response_headers_conformance network = os.environ['NETWORK'] -url = 'http://localhost:8080' -if network == 'dev': - url = 'https://gridproxy.dev.grid.tf' +if network == 'main': + url = 'https://gridproxy.grid.tf' +elif network != 'local': + url = 'https://gridproxy.'+ network +'.grid.tf' +else: + url = 'http://localhost:8080' schema = schemathesis.from_path("docs/swagger.json", base_url = url) From c1ac3e1787c34f140a676724dd8852269d94852d Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 30 Jan 2024 15:00:19 +0200 Subject: [PATCH 3/8] workflow update --- .github/workflows/scheme_test.yml | 29 ++++++++++------------------- .gitignore | 2 ++ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml index c3831375f..8df5cf5d5 100644 --- a/.github/workflows/scheme_test.yml +++ b/.github/workflows/scheme_test.yml @@ -23,20 +23,7 @@ jobs: defaults: run: working-directory: grid-proxy - services: - postgres: - image: postgres - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: tfgrid-graphql - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 + steps: - name: Checkout uses: actions/checkout@v4 @@ -56,11 +43,15 @@ jobs: - name: Build run: | - export PATH=/home/runner/go/bin:$PATH - export GIT_COMMIT=$(git rev-list -1 HEAD) - go build -ldflags "-X main.GitCommit=$GIT_COMMIT" cmds/proxy_server/main.go - env: - GO111MODULE: on + go mod tidy + make db-start + make db-fill + make server-start m=${{ secrets.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 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 From 72114da10515ff264a7ff816ab7a2433fa3c1f2c Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 30 Jan 2024 17:09:08 +0200 Subject: [PATCH 4/8] fix mnemonics line in workflow --- .github/workflows/scheme_test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml index 8df5cf5d5..9ace8851d 100644 --- a/.github/workflows/scheme_test.yml +++ b/.github/workflows/scheme_test.yml @@ -42,11 +42,13 @@ jobs: 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=${{ secrets.MNEMONICS }}& + make server-start m="$MNEMONICS" & - name: Wait on localhost uses: iFaxity/wait-on-action@v1 From 9b442c15e13069ca6ac90fdae976982ec280bcc4 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 30 Jan 2024 17:18:35 +0200 Subject: [PATCH 5/8] fix network condition --- grid-proxy/tests/schema_test/test_schema.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grid-proxy/tests/schema_test/test_schema.py b/grid-proxy/tests/schema_test/test_schema.py index 7396fa5e6..80ff7b846 100644 --- a/grid-proxy/tests/schema_test/test_schema.py +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -6,10 +6,10 @@ network = os.environ['NETWORK'] if network == 'main': url = 'https://gridproxy.grid.tf' -elif network != 'local': - url = 'https://gridproxy.'+ network +'.grid.tf' -else: +elif network == '': url = 'http://localhost:8080' +else: + url = 'https://gridproxy.'+ network +'.grid.tf' schema = schemathesis.from_path("docs/swagger.json", base_url = url) From fdda75c8c7d9ee71eb22d89bed2c96473076ba55 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 15 Apr 2024 17:49:28 +0200 Subject: [PATCH 6/8] adding trigger on PR on the main branch --- .github/workflows/scheme_test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml index 9ace8851d..10be9c91b 100644 --- a/.github/workflows/scheme_test.yml +++ b/.github/workflows/scheme_test.yml @@ -15,6 +15,9 @@ on: - test - main push: + pull_request: + branches: + - master jobs: From 1811cac665732a1a87515c555a82dfad42875c98 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 16 Apr 2024 17:53:06 +0200 Subject: [PATCH 7/8] update swagger links for networks --- .github/workflows/scheme_test.yml | 2 +- grid-proxy/tests/schema_test/test_schema.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scheme_test.yml b/.github/workflows/scheme_test.yml index 10be9c91b..17544c959 100644 --- a/.github/workflows/scheme_test.yml +++ b/.github/workflows/scheme_test.yml @@ -17,7 +17,7 @@ on: push: pull_request: branches: - - master + - development jobs: diff --git a/grid-proxy/tests/schema_test/test_schema.py b/grid-proxy/tests/schema_test/test_schema.py index 80ff7b846..7daf1bb54 100644 --- a/grid-proxy/tests/schema_test/test_schema.py +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -6,12 +6,16 @@ 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" + schemathesis.from_path(swagger, base_url = url) else: - url = 'https://gridproxy.'+ network +'.grid.tf' - -schema = schemathesis.from_path("docs/swagger.json", base_url = url) + 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]) From 9363368f9ea411cfc8ba0ab09e016d387d27bd4f Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 16 Apr 2024 17:57:00 +0200 Subject: [PATCH 8/8] add missing schema --- grid-proxy/tests/schema_test/test_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid-proxy/tests/schema_test/test_schema.py b/grid-proxy/tests/schema_test/test_schema.py index 7daf1bb54..e538f3351 100644 --- a/grid-proxy/tests/schema_test/test_schema.py +++ b/grid-proxy/tests/schema_test/test_schema.py @@ -11,7 +11,7 @@ elif network == '': url = 'http://localhost:8080' swagger = "docs/swagger.json" - schemathesis.from_path(swagger, base_url = url) + schema = schemathesis.from_path(swagger, base_url = url) else: url = 'https://gridproxy.' + network + '.grid.tf' swagger = 'https://gridproxy.' + network + '.grid.tf/swagger/doc.json'