From 8748ea021d90bfd1f5c0824f994b71c94872a57c Mon Sep 17 00:00:00 2001 From: toktar Date: Fri, 8 Jul 2022 15:46:08 +0300 Subject: [PATCH 1/5] test: Add integration test --- tests/e2e-pytest/helpers.py | 44 +++++++++++++++++++++++++++++++ tests/e2e-pytest/requirements.txt | 3 +++ tests/e2e-pytest/test_cosmos.py | 31 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests/e2e-pytest/helpers.py create mode 100644 tests/e2e-pytest/requirements.txt create mode 100644 tests/e2e-pytest/test_cosmos.py diff --git a/tests/e2e-pytest/helpers.py b/tests/e2e-pytest/helpers.py new file mode 100644 index 00000000..1da5e65e --- /dev/null +++ b/tests/e2e-pytest/helpers.py @@ -0,0 +1,44 @@ +import copy +import sys +import pexpect +import json + + +RESOLVER_URL = "http://localhost:1313" +PATH = "/1.0/identifiers/" + +TESTNET_DID = "did:cheqd:testnet:zFWM1mKVGGU2gHYuLAQcTJfZBebqBpGf" +TESTNET_FRAGMENT = TESTNET_DID + "#key1" +FAKE_TESTNET_DID = "did:cheqd:testnet:zF7rhDBfUt9d1gJPjx7s1JXfUY7oVWkY" +FAKE_TESTNET_FRAGMENT = TESTNET_DID + "#fake_key" + +MAINNET_DID = "did:cheqd:mainnet:zF7rhDBfUt9d1gJPjx7s1JXfUY7oVWkY" +MAINNET_FRAGMENT = MAINNET_DID + "#key1" +FAKE_MAINNET_DID = "did:cheqd:mainnet:zFWM1mKVGGU2gHYuLAQcTJfZBebqBpGf" +FAKE_MAINNET_FRAGMENT = MAINNET_DID + "#fake_key" + + +IMPLICIT_TIMEOUT = 40 +ENCODING = "utf-8" +READ_BUFFER = 60000 + + +def run(command, params, expected_output): + cli = pexpect.spawn(f"{command} {params}", encoding=ENCODING, timeout=IMPLICIT_TIMEOUT, maxread=READ_BUFFER) + cli.logfile = sys.stdout + cli.expect(expected_output) + return cli + + +def run_interaction(cli, input_string, expected_output): + cli.sendline(input_string) + cli.expect(expected_output) + + +def json_loads(s_to_load: str) -> dict: + s = copy.copy(s_to_load) + s = s.replace("\\", "") + s = s.replace("\"[", "[") + s = s.replace("]\"", "]") + return json.loads(s) + diff --git a/tests/e2e-pytest/requirements.txt b/tests/e2e-pytest/requirements.txt new file mode 100644 index 00000000..3734659f --- /dev/null +++ b/tests/e2e-pytest/requirements.txt @@ -0,0 +1,3 @@ +pytest==6.0.2 +pytest-asyncio==0.16.0 +pexpect==4.8.0 \ No newline at end of file diff --git a/tests/e2e-pytest/test_cosmos.py b/tests/e2e-pytest/test_cosmos.py new file mode 100644 index 00000000..17c729ec --- /dev/null +++ b/tests/e2e-pytest/test_cosmos.py @@ -0,0 +1,31 @@ +import pytest +from helpers import run, TESTNET_DID, MAINNET_DID, TESTNET_FRAGMENT, MAINNET_FRAGMENT, \ + FAKE_TESTNET_DID, FAKE_MAINNET_DID, FAKE_TESTNET_FRAGMENT, FAKE_MAINNET_FRAGMENT, RESOLVER_URL, PATH + + +@pytest.mark.parametrize( + "did_url, expected_output", + [ + (TESTNET_DID, fr"didDocument(.*?)\"id\":\"{TESTNET_DID}\"(.*?)didDocumentMetadata" + r"(.*?)didResolutionMetadata"), + (MAINNET_DID, fr"didDocument(.*?)\"id\":\"{MAINNET_DID}\"(.*?)didDocumentMetadata" + r"(.*?)didResolutionMetadata"), + (FAKE_TESTNET_DID, r"didDocument\":null,\"didDocumentMetadata\":\[\]," + r"\"didResolutionMetadata(.*?)\"error\":\"notFound\""), + (FAKE_MAINNET_DID, r"didDocument\":null,\"didDocumentMetadata\":\[\]," + r"\"didResolutionMetadata(.*?)\"error\":\"notFound\""), + ("did:wrong_method:MTMxDQKMTMxDQKMT", r"didDocument\":null,\"didDocumentMetadata\":\[\]," + r"\"didResolutionMetadata(.*?)\"error\":\"methodNotSupported\""), + + (TESTNET_FRAGMENT, fr"\"contentStream\":(.*?)\"id\":\"{TESTNET_FRAGMENT}\"(.*?)contentMetadata" + r"(.*?)dereferencingMetadata\""), + (MAINNET_FRAGMENT, fr"\"contentStream\":(.*?)\"id\":\"{MAINNET_FRAGMENT}\"(.*?)contentMetadata" + r"(.*?)dereferencingMetadata\""), + (FAKE_TESTNET_FRAGMENT, r"\"contentStream\":null,\"contentMetadata\":\[\]," + r"\"dereferencingMetadata(.*?)\"error\":\"FragmentNotFound\""), + (FAKE_MAINNET_FRAGMENT, r"\"contentStream\":null,\"contentMetadata\":\[\]," + r"\"dereferencingMetadata(.*?)\"error\":\"FragmentNotFound\""), + ] +) +def test_resolution(did_url, expected_output): + run("curl", RESOLVER_URL + PATH + did_url.replace("#", "%23"), expected_output) From e2d9689f08be1a9fb71c6e126dea37cbe5620196 Mon Sep 17 00:00:00 2001 From: toktar Date: Fri, 8 Jul 2022 15:48:12 +0300 Subject: [PATCH 2/5] test: Update pipelines --- .github/workflows/test.yml | 33 +++++++++++++++++++ .../{test_cosmos.py => test_resolution.py} | 0 2 files changed, 33 insertions(+) rename tests/e2e-pytest/{test_cosmos.py => test_resolution.py} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7fb1e613..0ba2c07c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,3 +16,36 @@ jobs: - name: Run Golang unit tests run: go test -v ./... + + python-integration-tests: + name: "Python integration tests" + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Download node Docker image + uses: actions/download-artifact@v3 + with: + name: cheqd-did-resolver.tar + + - name: Load node Docker image + run: docker load -i cheqd-did-resolver.tar + + - name: Setup full resolver Docker + working-directory: ./docker + run: | + docker compose --profile full up + + - name: Setup Python environment + working-directory: ./tests/e2e-pytest + run: | + set -euo pipefail + pip3 install -r requirements.txt >> /dev/null + sudo chmod -R 775 /home/runner/ + + - name: Run tests + working-directory: ./tests/e2e-pytest + run: | + set -euo pipefail + pytest -v -rP *.py \ No newline at end of file diff --git a/tests/e2e-pytest/test_cosmos.py b/tests/e2e-pytest/test_resolution.py similarity index 100% rename from tests/e2e-pytest/test_cosmos.py rename to tests/e2e-pytest/test_resolution.py From 874ea026d67d4b62f85250f326284e372980c1c6 Mon Sep 17 00:00:00 2001 From: toktar Date: Fri, 8 Jul 2022 15:56:11 +0300 Subject: [PATCH 3/5] Update tests dir name --- .github/workflows/test.yml | 4 ++-- tests/{e2e-pytest => pytest}/helpers.py | 0 tests/{e2e-pytest => pytest}/requirements.txt | 0 tests/{e2e-pytest => pytest}/test_resolution.py | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/{e2e-pytest => pytest}/helpers.py (100%) rename tests/{e2e-pytest => pytest}/requirements.txt (100%) rename tests/{e2e-pytest => pytest}/test_resolution.py (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ba2c07c..1e7f0cde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,14 +38,14 @@ jobs: docker compose --profile full up - name: Setup Python environment - working-directory: ./tests/e2e-pytest + working-directory: ./tests/pytest run: | set -euo pipefail pip3 install -r requirements.txt >> /dev/null sudo chmod -R 775 /home/runner/ - name: Run tests - working-directory: ./tests/e2e-pytest + working-directory: ./tests/pytest run: | set -euo pipefail pytest -v -rP *.py \ No newline at end of file diff --git a/tests/e2e-pytest/helpers.py b/tests/pytest/helpers.py similarity index 100% rename from tests/e2e-pytest/helpers.py rename to tests/pytest/helpers.py diff --git a/tests/e2e-pytest/requirements.txt b/tests/pytest/requirements.txt similarity index 100% rename from tests/e2e-pytest/requirements.txt rename to tests/pytest/requirements.txt diff --git a/tests/e2e-pytest/test_resolution.py b/tests/pytest/test_resolution.py similarity index 100% rename from tests/e2e-pytest/test_resolution.py rename to tests/pytest/test_resolution.py From 221547114200f52b5ab9b997dacb693f885407de Mon Sep 17 00:00:00 2001 From: toktar Date: Fri, 8 Jul 2022 16:05:20 +0300 Subject: [PATCH 4/5] Update GA test --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e7f0cde..ac94fb65 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,8 +34,7 @@ jobs: - name: Setup full resolver Docker working-directory: ./docker - run: | - docker compose --profile full up + run: docker compose --profile full up - name: Setup Python environment working-directory: ./tests/pytest @@ -48,4 +47,4 @@ jobs: working-directory: ./tests/pytest run: | set -euo pipefail - pytest -v -rP *.py \ No newline at end of file + pytest -v -rP ./*.py \ No newline at end of file From 1ef6bbdc4e846c93d35557ddf59cb556dff563df Mon Sep 17 00:00:00 2001 From: toktar Date: Fri, 8 Jul 2022 16:12:44 +0300 Subject: [PATCH 5/5] Update GA test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac94fb65..e81fc116 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: - name: Setup full resolver Docker working-directory: ./docker - run: docker compose --profile full up + run: docker compose --profile full up -d - name: Setup Python environment working-directory: ./tests/pytest