From b8b0651026c77fc5556cc0d19d9658f565ee7480 Mon Sep 17 00:00:00 2001 From: NikitaUnisikhin <92248695+NikitaUnisikhin@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:54:25 +0500 Subject: [PATCH] Proto tests (#595) * add spqr proto tests * fix --- docker-compose-test.yml | 2 ++ docker/Dockerfile | 7 ++++++- docker/bin/setup | 16 +++++++++++++++- docker/entrypoint.sh | 5 +++++ docker/xproto/Dockerfile | 9 +++++++++ docker/xproto/test.sh | 5 +++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 docker/xproto/Dockerfile create mode 100755 docker/xproto/test.sh diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 117640d89..86b88ca1a 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -12,6 +12,8 @@ services: context: . environment: CMAKE_BUILD_TYPE: "${CMAKE_BUILD_TYPE:-Debug}" + volumes: + - /var/run/docker.sock:/var/run/docker.sock networks: od_net: ipv4_address: 192.168.233.15 diff --git a/docker/Dockerfile b/docker/Dockerfile index 43bd6397f..b8cea8963 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -49,7 +49,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libpq-dev \ vim \ postgresql-common \ - postgresql-server-dev-14 + postgresql-server-dev-14 \ + git + +RUN curl -fsSL https://get.docker.com -o get-docker.sh && \ + sudo sh get-docker.sh COPY ./docker/pg/pg_hba-test.conf /etc/postgresql/14/main/pg_hba.conf @@ -75,6 +79,7 @@ COPY ./docker/ldap /ldap COPY ./docker/lagpolling /lagpolling COPY ./docker/shell-test /shell-test COPY ./docker/tsa /tsa +COPY ./docker/xproto /xproto COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh diff --git a/docker/bin/setup b/docker/bin/setup index 5dfa81268..ca9bfeee1 100755 --- a/docker/bin/setup +++ b/docker/bin/setup @@ -49,7 +49,7 @@ sudo -u postgres /usr/bin/pg_basebackup -D /var/lib/postgresql/14/repl -R -h loc sudo -u postgres /usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/14/repl/ -o '-p 5433' start # Create databases -for database_name in db scram_db ldap_db auth_query_db db1 hba_db tsa_db addr_db; do +for database_name in db scram_db ldap_db auth_query_db db1 hba_db tsa_db addr_db xproto_db "spqr-console"; do sudo -u postgres createdb $database_name >> "$SETUP_LOG" 2>&1 || { echo "ERROR: 'createdb $database_name' failed, examine the log" cat "$SETUP_LOG" @@ -171,6 +171,20 @@ psql -h localhost -p 5432 -U postgres -c "set password_encryption TO 'md5'; crea exit 1 } +psql -h localhost -p 5432 -U postgres -c "create role xproto SUPERUSER LOGIN" -d xproto_db >> $SETUP_LOG 2>&1 || { + echo "ERROR: users creation failed, examine the log" + cat "$SETUP_LOG" + cat "$PG_LOG" + exit 1 +} + +psql -h localhost -p 5432 -U postgres -c "create user \"spqr-console\"" -d "spqr-console" >> $SETUP_LOG 2>&1 || { + echo "ERROR: users creation failed, examine the log" + cat "$SETUP_LOG" + cat "$PG_LOG" + exit 1 +} + # Grant access for ldap_storage_credentials psql -h localhost -p 5432 -U postgres -c "GRANT ALL ON DATABASE ldap_db1 TO ldap_readonly" -d postgres >> $SETUP_LOG 2>&1 || { diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index fe4004f37..d2a7c20bf 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -6,6 +6,11 @@ cd /test_dir/test && /usr/bin/odyssey_test setup +# proto +ody-start +/xproto/test.sh +ody-stop + # odyssey rule-address test /rule-address/test.sh if [ $? -eq 1 ] diff --git a/docker/xproto/Dockerfile b/docker/xproto/Dockerfile new file mode 100644 index 000000000..87eb79f3c --- /dev/null +++ b/docker/xproto/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.21 + +WORKDIR /root +COPY . /root + +RUN go mod init prep_stmt_test && \ + go mod tidy + +ENTRYPOINT go test . diff --git a/docker/xproto/test.sh b/docker/xproto/test.sh new file mode 100755 index 000000000..9de9c67aa --- /dev/null +++ b/docker/xproto/test.sh @@ -0,0 +1,5 @@ +git clone https://github.com/pg-sharding/spqr.git /xproto/spqr +cp /xproto/spqr/test/xproto/proto_test.go /xproto/proto_test.go +rm -rf /xproto/spqr +docker build -t xproto-tests /xproto +docker run -e POSTGRES_HOST=odyssey -e POSTGRES_PORT=6432 -e POSTGRES_DB=xproto_db -e POSTGRES_USER=xproto --network=odyssey_od_net xproto-tests \ No newline at end of file