From 793d55d9c6cb7fd570e5d76e8d74b2086db28bff Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 11 Feb 2024 00:18:35 +0100 Subject: [PATCH] Testing: Add Python-based integration tests README/doctests have problems on Windows, so this is meant as an alternative. --- tests/test_integration_python.py | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/test_integration_python.py diff --git a/tests/test_integration_python.py b/tests/test_integration_python.py new file mode 100644 index 0000000..86a750b --- /dev/null +++ b/tests/test_integration_python.py @@ -0,0 +1,86 @@ +import subprocess +import sys +import unittest + +from tests.integration_util import node, setup, teardown, translate + + +def setUpModule(): + node.start() + assert node.http_host, "http_url must be available" + + +def tearDownModule(): + node.stop() + + +class IntegrationTest(unittest.TestCase): + """ + Integration tests defined as Python code, derived from README doctest code. + + Rationale: Currently, running the README doctests on + Windows trips, and hasn't been resolved yet. + """ + def setUp(self) -> None: + """ + Provision tables. + """ + setup() + + def tearDown(self) -> None: + """ + Destroy tables. + """ + teardown() + + def cmd(self, command: str): + """ + Invoke a shell command. + """ + return subprocess.check_call(translate(command), shell=True) + + def test_connectivity(self): + command = "cr8 timeit --hosts localhost:4200" + self.cmd(command) + + def test_sys_cluster(self): + command = "echo 'SELECT * FROM sys.cluster;' | cr8 timeit --hosts localhost:4200" + self.cmd(command) + + def test_sys_summits(self): + command = "echo 'SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;' | cr8 timeit --hosts localhost:4200" + self.cmd(command) + + def test_insert_fake_data(self): + command = "cr8 insert-fake-data --hosts localhost:4200 --table x.demo --num-records 200" + self.cmd(command) + + def test_insert_json(self): + command = "cat tests/demo.json | cr8 insert-json --table x.demo --hosts localhost:4200" + self.cmd(command) + + def test_insert_json_print(self): + command = """echo '{"name": "Arthur"}' | cr8 insert-json --table mytable""" + self.cmd(command) + + def test_insert_from_sql(self): + command = "cr8 insert-fake-data --hosts localhost:4200 --table x.demo --num-records 200" + self.cmd(command) + command = "echo 'REFRESH TABLE x.demo;' | cr8 timeit --hosts localhost:4200" + self.cmd(command) + command = """ + cr8 insert-from-sql \ + --src-uri "postgresql://crate@localhost:5432/doc" \ + --query "SELECT name FROM x.demo" \ + --hosts localhost:4200 \ + --table y.demo + """ + self.cmd(command) + + def test_run_spec_toml(self): + command = "cr8 run-spec specs/sample.toml localhost:4200 -r localhost:4200" + self.cmd(command) + + def test_run_spec_python(self): + command = "cr8 run-spec specs/sample.py localhost:4200" + self.cmd(command)