Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [DEV-1384] add integration tests #17

Merged
merged 5 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,35 @@ 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 -d

- name: Setup Python environment
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/pytest
run: |
set -euo pipefail
pytest -v -rP ./*.py
44 changes: 44 additions & 0 deletions tests/pytest/helpers.py
Original file line number Diff line number Diff line change
@@ -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)

3 changes: 3 additions & 0 deletions tests/pytest/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest==6.0.2
pytest-asyncio==0.16.0
pexpect==4.8.0
31 changes: 31 additions & 0 deletions tests/pytest/test_resolution.py
Original file line number Diff line number Diff line change
@@ -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)