From 0d522bf3cb2df7c59b1da039f39601a1c0fa81b6 Mon Sep 17 00:00:00 2001 From: Simon Holesch Date: Fri, 16 Aug 2024 21:37:11 +0200 Subject: [PATCH] tests: Add tutorial test I already broke the tutorial way too often. Add a test case. --- tests/test_tutorial.py | 23 +++++++++++++++++++++++ tests/tutorial/hello | 1 + tests/tutorial/tutorial-tcp-place.toml | 5 +++++ tests/tutorial/tutorial-tcp.toml | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 tests/test_tutorial.py create mode 100644 tests/tutorial/hello create mode 100644 tests/tutorial/tutorial-tcp-place.toml create mode 100644 tests/tutorial/tutorial-tcp.toml diff --git a/tests/test_tutorial.py b/tests/test_tutorial.py new file mode 100644 index 0000000..1aa4a78 --- /dev/null +++ b/tests/test_tutorial.py @@ -0,0 +1,23 @@ +async def test_tutorial(vms): + async with vms.hub.ssh_task("not-my-board hub", "hub", wait_ready=True): + async with vms.hub.ssh_task( + "python3 -m http.server -d ./src/tests/tutorial -b localhost 8080", + "http_server", + ): + async with vms.hub.ssh_task( + "not-my-board export http://localhost:2092 ./src/tests/tutorial/tutorial-tcp-place.toml", + "export", + wait_ready=True, + ): + async with vms.hub.ssh_task_root( + "not-my-board agent http://localhost:2092", "agent", wait_ready=True + ): + await vms.hub.ssh( + "doas not-my-board attach ./src/tests/tutorial/tutorial-tcp.toml" + ) + + await vms.hub.ssh_poll("nc -z localhost 8080") + result = await vms.hub.ssh( + "wget -qO - http://localhost:8081/hello", prefix="wget" + ) + assert result.stdout.rstrip() == "Hello, World!" diff --git a/tests/tutorial/hello b/tests/tutorial/hello new file mode 100644 index 0000000..8ab686e --- /dev/null +++ b/tests/tutorial/hello @@ -0,0 +1 @@ +Hello, World! diff --git a/tests/tutorial/tutorial-tcp-place.toml b/tests/tutorial/tutorial-tcp-place.toml new file mode 100644 index 0000000..9305da5 --- /dev/null +++ b/tests/tutorial/tutorial-tcp-place.toml @@ -0,0 +1,5 @@ +port = 2192 + +[[parts]] +compatible = [ "tutorial-http-server" ] +tcp.http = { host = "localhost", port = 8080 } diff --git a/tests/tutorial/tutorial-tcp.toml b/tests/tutorial/tutorial-tcp.toml new file mode 100644 index 0000000..de1a47a --- /dev/null +++ b/tests/tutorial/tutorial-tcp.toml @@ -0,0 +1,3 @@ +[parts.http-server] +compatible = [ "tutorial-http-server" ] +tcp.http = { local_port = 8081 }