|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | +import unittest |
| 4 | + |
| 5 | +from tests.integration_util import node, setup, teardown, translate |
| 6 | + |
| 7 | + |
| 8 | +def setUpModule(): |
| 9 | + node.start() |
| 10 | + assert node.http_host, "http_url must be available" |
| 11 | + |
| 12 | + |
| 13 | +def tearDownModule(): |
| 14 | + node.stop() |
| 15 | + |
| 16 | + |
| 17 | +class IntegrationTest(unittest.TestCase): |
| 18 | + """ |
| 19 | + Integration tests defined as Python code, derived from README doctest code. |
| 20 | +
|
| 21 | + Rationale: Currently, running the README doctests on |
| 22 | + Windows trips, and hasn't been resolved yet. |
| 23 | + """ |
| 24 | + def setUp(self) -> None: |
| 25 | + """ |
| 26 | + Provision tables. |
| 27 | + """ |
| 28 | + setup() |
| 29 | + |
| 30 | + def tearDown(self) -> None: |
| 31 | + """ |
| 32 | + Destroy tables. |
| 33 | + """ |
| 34 | + teardown() |
| 35 | + |
| 36 | + def cmd(self, command: str): |
| 37 | + """ |
| 38 | + Invoke a shell command. |
| 39 | + """ |
| 40 | + return subprocess.check_call(translate(command), shell=True) |
| 41 | + |
| 42 | + def test_connectivity(self): |
| 43 | + command = "cr8 timeit --hosts localhost:4200" |
| 44 | + self.cmd(command) |
| 45 | + |
| 46 | + def test_sys_cluster(self): |
| 47 | + command = "echo 'SELECT * FROM sys.cluster;' | cr8 timeit --hosts localhost:4200" |
| 48 | + self.cmd(command) |
| 49 | + |
| 50 | + def test_sys_summits(self): |
| 51 | + command = "echo 'SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;' | cr8 timeit --hosts localhost:4200" |
| 52 | + self.cmd(command) |
| 53 | + |
| 54 | + def test_insert_fake_data(self): |
| 55 | + command = "cr8 insert-fake-data --hosts localhost:4200 --table x.demo --num-records 200" |
| 56 | + self.cmd(command) |
| 57 | + |
| 58 | + def test_insert_json(self): |
| 59 | + command = "cat tests/demo.json | cr8 insert-json --table x.demo --hosts localhost:4200" |
| 60 | + self.cmd(command) |
| 61 | + |
| 62 | + def test_insert_json_print(self): |
| 63 | + command = """echo '{"name": "Arthur"}' | cr8 insert-json --table mytable""" |
| 64 | + self.cmd(command) |
| 65 | + |
| 66 | + def test_insert_from_sql(self): |
| 67 | + command = "cr8 insert-fake-data --hosts localhost:4200 --table x.demo --num-records 200" |
| 68 | + self.cmd(command) |
| 69 | + command = "echo 'REFRESH TABLE x.demo;' | cr8 timeit --hosts localhost:4200" |
| 70 | + self.cmd(command) |
| 71 | + command = """ |
| 72 | + cr8 insert-from-sql \ |
| 73 | + --src-uri "postgresql://crate@localhost:5432/doc" \ |
| 74 | + --query "SELECT name FROM x.demo" \ |
| 75 | + --hosts localhost:4200 \ |
| 76 | + --table y.demo |
| 77 | + """ |
| 78 | + self.cmd(command) |
| 79 | + |
| 80 | + def test_run_spec_toml(self): |
| 81 | + command = "cr8 run-spec specs/sample.toml localhost:4200 -r localhost:4200" |
| 82 | + self.cmd(command) |
| 83 | + |
| 84 | + def test_run_spec_python(self): |
| 85 | + command = "cr8 run-spec specs/sample.py localhost:4200" |
| 86 | + self.cmd(command) |
0 commit comments