mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
node = cluster.add_instance('node', stay_alive=True, main_configs=[])
|
|
|
|
|
|
def copy_file_to_container(local_path, dist_path, container_id):
|
|
os.system("docker cp {local} {cont_id}:{dist}".format(local=local_path, cont_id=container_id, dist=dist_path))
|
|
|
|
@pytest.fixture(scope="module")
|
|
def started_cluster():
|
|
try:
|
|
cluster.start()
|
|
|
|
copy_file_to_container(os.path.join(SCRIPT_DIR, 'user_scripts/.'), '/var/lib/clickhouse/user_scripts', node.docker_id)
|
|
node.restart_clickhouse()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
def test_executable_function_no_input(started_cluster):
|
|
assert node.query("SELECT * FROM executable('test_no_input.sh', 'TabSeparated', 'value UInt64')") == '1\n'
|
|
|
|
def test_executable_function_input(started_cluster):
|
|
assert node.query("SELECT * FROM executable('test_input.sh', 'TabSeparated', 'value String', (SELECT 1))") == 'Key 1\n'
|
|
|
|
def test_executable_function_argument(started_cluster):
|
|
assert node.query("SELECT * FROM executable('test_argument.sh 1', 'TabSeparated', 'value String')") == 'Key 1\n'
|
|
|
|
def test_executable_storage_no_input(started_cluster):
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
node.query("CREATE TABLE test_table (value UInt64) ENGINE=Executable('test_no_input.sh', 'TabSeparated')")
|
|
assert node.query("SELECT * FROM test_table") == '1\n'
|
|
node.query("DROP TABLE test_table")
|
|
|
|
def test_executable_storage_input(started_cluster):
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=Executable('test_no_input.sh', 'TabSeparated', (SELECT 1))")
|
|
assert node.query("SELECT * FROM test_table") == '1\n'
|
|
node.query("DROP TABLE test_table")
|
|
|
|
def test_executable_storage_argument(started_cluster):
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=Executable('test_argument.sh 1', 'TabSeparated')")
|
|
assert node.query("SELECT * FROM test_table") == 'Key 1\n'
|
|
node.query("DROP TABLE test_table")
|