From 141f7d867476e657b33928c45f2028d20e401961 Mon Sep 17 00:00:00 2001 From: Pavel Shilin <143797001+PavelShilin89@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:09:58 +0200 Subject: [PATCH] Integration Test for PostgreSQL and Manticore using Docker (#93) * Created test-postgres-docker.rec --------- Co-authored-by: Pavel_Shilin --- clt_tests/tests/base/init.sql | 11 ++++++ .../base/manticore-indexer-postgres.conf | 22 +++++++++++ clt_tests/tests/test-postgres-docker.rec | 37 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 clt_tests/tests/base/init.sql create mode 100644 clt_tests/tests/base/manticore-indexer-postgres.conf create mode 100644 clt_tests/tests/test-postgres-docker.rec diff --git a/clt_tests/tests/base/init.sql b/clt_tests/tests/base/init.sql new file mode 100644 index 0000000..df238a8 --- /dev/null +++ b/clt_tests/tests/base/init.sql @@ -0,0 +1,11 @@ +\c api_db; + +CREATE TABLE a_block_element ( + id SERIAL PRIMARY KEY, + name VARCHAR NOT NULL, + text JSONB +); + +INSERT INTO a_block_element (name, text) VALUES +('Element 1', '{"key1": "value1"}'), +('Element 2', '{"key2": "value2"}'); \ No newline at end of file diff --git a/clt_tests/tests/base/manticore-indexer-postgres.conf b/clt_tests/tests/base/manticore-indexer-postgres.conf new file mode 100644 index 0000000..6047bc1 --- /dev/null +++ b/clt_tests/tests/base/manticore-indexer-postgres.conf @@ -0,0 +1,22 @@ +source text_src { + type = pgsql + sql_host = postgres + sql_user = postgres + sql_pass = qazQASD! + sql_db = api_db + sql_port = 5432 + sql_query = SELECT id, name from a_block_element +} + +index text_idx { + type = plain + source = text_src + path = /var/lib/manticore/data +} + +searchd { + listen = 127.0.0.1:9312 + listen = 127.0.0.1:9306:mysql + listen = 127.0.0.1:9308:http + pid_file = /var/run/manticore/searchd.pid +} \ No newline at end of file diff --git a/clt_tests/tests/test-postgres-docker.rec b/clt_tests/tests/test-postgres-docker.rec new file mode 100644 index 0000000..8545824 --- /dev/null +++ b/clt_tests/tests/test-postgres-docker.rec @@ -0,0 +1,37 @@ +––– block: ./base/init ––– +––– input ––– +docker network create app-network --driver bridge > /dev/null; echo $? +––– output ––– +0 +––– input ––– +docker run -d --name postgres --network app-network -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=qazQASD! -e POSTGRES_DB=api_db -p 5432:5432 -v $(pwd)/clt_tests/tests/base/init.sql:/docker-entrypoint-initdb.d/init.sql postgres:latest > /dev/null 2>&1; echo $? +––– output ––– +0 +––– input ––– +timeout 35 grep -m2 'database system is ready to accept connections' <(docker logs -f postgres 2>&1) +––– output ––– +#!/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}/!# UTC [%{NUMBER}] LOG: database system is ready to accept connections +#!/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}/!# UTC [%{NUMBER}] LOG: database system is ready to accept connections +––– input ––– +docker run -d -e CREATE_PLAIN_TABLES=1 --name manticore --network app-network -v $(pwd)/clt_tests/tests/base/manticore-indexer-postgres.conf:/etc/manticoresearch/manticore.conf manticoresoftware/manticore:current +––– output ––– +#!/[0-9a-z]+/!# +––– input ––– +if timeout 60 grep -qm1 'accepting connections' <(docker logs -f manticore); then echo 'accepting connections'; else echo 'Manticore failed to start properly in 60 seconds'; fi +––– output ––– +accepting connections +––– input ––– +docker exec manticore mysql -h0 -P9306 -e "SHOW TABLES\G;" +––– output ––– +*************************** 1. row *************************** +Index: text_idx +Type: local +––– input ––– +docker exec manticore mysql -h0 -P9306 -e "SELECT * FROM text_idx\G;" +––– output ––– +*************************** 1. row *************************** +id: 1 +name: Element 1 +*************************** 2. row *************************** +id: 2 +name: Element 2 \ No newline at end of file