From 5221efacb4a61e7d34ab0a32782b38831c004c12 Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 15:31:50 -0700 Subject: [PATCH 1/7] add endpoints fixture --- requirements.txt | 2 +- test/test_conformance.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/test_conformance.py diff --git a/requirements.txt b/requirements.txt index 32f0c43..9eb2b58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pyyaml - +pytest diff --git a/test/test_conformance.py b/test/test_conformance.py new file mode 100644 index 0000000..57c984b --- /dev/null +++ b/test/test_conformance.py @@ -0,0 +1,34 @@ +import shlex +import subprocess + +import pytest + + +@pytest.fixture(scope="session") +def endpoint(): + container_name = 'hobbits-endpoint' + cleanup = shlex.split(f'docker rm -f {container_name}') + subprocess.run(cleanup, check=False) + + docker_run = shlex.split( + "docker run -d" + " --hostname hobbits-endpoint" + " --network hobbits" + f" --name {container_name}" + " --entrypoint netcat" + " hobbits-relayer -l -p 18000" + ) + completed_proc = subprocess.run( + docker_run, + stdout=subprocess.PIPE, + encoding='utf-8', + check=True + ) + container_id = completed_proc.stdout.strip() + yield container_id + docker_rmf = shlex.split(f'docker rm -f {container_id}') + subprocess.run(docker_rmf, check=True) + + +def test_200_status_code(endpoint): + pass From 68af9e91dc4161d77e7bc1ade5cfee10e2db987c Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 15:55:56 -0700 Subject: [PATCH 2/7] add missing trailing comma --- test/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run.py b/test/run.py index cea609e..94476b4 100644 --- a/test/run.py +++ b/test/run.py @@ -19,7 +19,7 @@ ] LANGS = { - 'bash':['bash','./parsers/bash/parser.sh'] + 'bash':['bash','./parsers/bash/parser.sh'], 'c': ['./parsers/c/test'], 'cpp': [ './parsers/cpp/test' ], 'd': ['./parsers/d/main'], From 3b9c7bccc705ba7b3c4d6b910d4f216af67061a5 Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 16:02:01 -0700 Subject: [PATCH 3/7] implement docker network fixture --- test/test_conformance.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/test_conformance.py b/test/test_conformance.py index 57c984b..41bdedd 100644 --- a/test/test_conformance.py +++ b/test/test_conformance.py @@ -3,18 +3,34 @@ import pytest +DOCKER_NETWORK = 'hobbits' +DOCKER_IMAGE = 'hobbits-relayer' +DOCKER_HOBBITS_ENDPOINT = 'hobbits-endpoint' + + +@pytest.fixture(scope="session") +def docker_network(): + cleanup = shlex.split(f'docker network rm {DOCKER_NETWORK}') + subprocess.run(cleanup, check=False) + + setup = shlex.split(f'docker network create {DOCKER_NETWORK}') + subprocess.run(setup, check=True) + yield DOCKER_NETWORK + + teardown = shlex.split(f'docker network rm {DOCKER_NETWORK}') + subprocess.run(teardown, check=True) + @pytest.fixture(scope="session") -def endpoint(): - container_name = 'hobbits-endpoint' - cleanup = shlex.split(f'docker rm -f {container_name}') +def endpoint(docker_network): + cleanup = shlex.split(f'docker rm -f {DOCKER_HOBBITS_ENDPOINT}') subprocess.run(cleanup, check=False) docker_run = shlex.split( "docker run -d" - " --hostname hobbits-endpoint" - " --network hobbits" - f" --name {container_name}" + f" --hostname {DOCKER_HOBBITS_ENDPOINT}" + f" --network {docker_network}" + f" --name {DOCKER_HOBBITS_ENDPOINT}" " --entrypoint netcat" " hobbits-relayer -l -p 18000" ) From 5955c98da06a0217c412ec5253cefb91ed0ad1d5 Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 16:15:07 -0700 Subject: [PATCH 4/7] implement docker-relayer fixture --- test/test_conformance.py | 43 +++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/test/test_conformance.py b/test/test_conformance.py index 41bdedd..549bb56 100644 --- a/test/test_conformance.py +++ b/test/test_conformance.py @@ -5,6 +5,7 @@ DOCKER_NETWORK = 'hobbits' DOCKER_IMAGE = 'hobbits-relayer' +DOCKER_HOBBITS_RELAYER = 'hobbits-relayer' DOCKER_HOBBITS_ENDPOINT = 'hobbits-endpoint' @@ -22,29 +23,57 @@ def docker_network(): @pytest.fixture(scope="session") -def endpoint(docker_network): +def docker_relayer(docker_network): + cleanup = shlex.split(f'docker rm -f {DOCKER_HOBBITS_RELAYER}') + subprocess.run(cleanup, check=False) + + setup = shlex.split( + 'docker run -d' + f' --network {docker_network}' + f' --name {DOCKER_HOBBITS_RELAYER}' + ' -p 10000:10000' + f' {DOCKER_IMAGE}' + ' -b tcp://0.0.0.0:10000 -t tcp://hobbits-endpoint:18000' + ) + completed_proc = subprocess.run( + setup, + stdout=subprocess.PIPE, + encoding='utf-8', + check=True + ) + container_id = completed_proc.stdout.strip() + yield container_id + + teardown = shlex.split(f'docker rm -f {DOCKER_HOBBITS_RELAYER}') + subprocess.run(teardown, check=True) + + +@pytest.fixture(scope="session") +def docker_endpoint(docker_network): cleanup = shlex.split(f'docker rm -f {DOCKER_HOBBITS_ENDPOINT}') subprocess.run(cleanup, check=False) - docker_run = shlex.split( + setup = shlex.split( "docker run -d" f" --hostname {DOCKER_HOBBITS_ENDPOINT}" f" --network {docker_network}" f" --name {DOCKER_HOBBITS_ENDPOINT}" " --entrypoint netcat" - " hobbits-relayer -l -p 18000" + f" {DOCKER_IMAGE}" + " -l -p 18000" ) completed_proc = subprocess.run( - docker_run, + setup, stdout=subprocess.PIPE, encoding='utf-8', check=True ) container_id = completed_proc.stdout.strip() yield container_id - docker_rmf = shlex.split(f'docker rm -f {container_id}') - subprocess.run(docker_rmf, check=True) + + teardown = shlex.split(f'docker rm -f {container_id}') + subprocess.run(teardown, check=True) -def test_200_status_code(endpoint): +def test_200_status_code(docker_endpoint, docker_relayer): pass From 42b476e5e9195ea631049df85f626b1d27647d04 Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 16:25:00 -0700 Subject: [PATCH 5/7] hello world! --- test/test_conformance.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/test_conformance.py b/test/test_conformance.py index 549bb56..5049c9f 100644 --- a/test/test_conformance.py +++ b/test/test_conformance.py @@ -1,3 +1,4 @@ +import pathlib import shlex import subprocess @@ -76,4 +77,13 @@ def docker_endpoint(docker_network): def test_200_status_code(docker_endpoint, docker_relayer): - pass + completed_proc = subprocess.run( + shlex.split('netcat -c localhost 10000'), + input=( + "EWP 0.2 RPC 5 5\n" + "hellohello\n" + ).encode('utf-8'), + cwd=pathlib.Path(__file__).parent, + capture_output=True, + ) + assert completed_proc.returncode == 0 From a8d9f1dab029ad64b45b7f4affe40c1ba6ec0c4a Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Mon, 15 Jul 2019 21:36:22 -0700 Subject: [PATCH 6/7] use image published in dockerhub --- test/test_conformance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_conformance.py b/test/test_conformance.py index 5049c9f..1f956d9 100644 --- a/test/test_conformance.py +++ b/test/test_conformance.py @@ -5,7 +5,7 @@ import pytest DOCKER_NETWORK = 'hobbits' -DOCKER_IMAGE = 'hobbits-relayer' +DOCKER_IMAGE = 'thenateway/hobbits-endpoint' # XXX: you must trust this image DOCKER_HOBBITS_RELAYER = 'hobbits-relayer' DOCKER_HOBBITS_ENDPOINT = 'hobbits-endpoint' From 57d6d1a83cb5615d61a186279523f72476ac342e Mon Sep 17 00:00:00 2001 From: Leibniz137 Date: Tue, 16 Jul 2019 13:33:32 -0700 Subject: [PATCH 7/7] check endpoint stdout for received message --- test/test_conformance.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/test_conformance.py b/test/test_conformance.py index 1f956d9..a52484d 100644 --- a/test/test_conformance.py +++ b/test/test_conformance.py @@ -77,13 +77,22 @@ def docker_endpoint(docker_network): def test_200_status_code(docker_endpoint, docker_relayer): - completed_proc = subprocess.run( + subprocess.run( shlex.split('netcat -c localhost 10000'), input=( "EWP 0.2 RPC 5 5\n" "hellohello\n" ).encode('utf-8'), cwd=pathlib.Path(__file__).parent, + ) + + completed_proc = subprocess.run( + shlex.split(f'docker logs {DOCKER_HOBBITS_ENDPOINT}'), capture_output=True, ) - assert completed_proc.returncode == 0 + endpoint_stdout = completed_proc.stdout + expected = ( + "EWP 0.2 RPC 5 5\n" + "hellohello" + ) + assert endpoint_stdout == completed_proc.stdout