Skip to content

Commit

Permalink
Testing: Add Python-based integration tests
Browse files Browse the repository at this point in the history
README/doctests have problems on Windows, so this is meant as an
alternative.
  • Loading branch information
amotl committed Feb 10, 2024
1 parent b70a69d commit 7144edf
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/test_integration_python.py
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)

0 comments on commit 7144edf

Please sign in to comment.