-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing: Add Python-based integration tests
README/doctests have problems on Windows, so this is meant as an alternative.
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, stdout=sys.stdout, stderr=sys.stderr) | ||
|
||
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) |