diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17346c8..05106b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,300 +1,373 @@ -name: CI - -on: - push: - branches: - - main - - actions - pull_request: - branches: - - main - -jobs: - test-postgresql-13: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Update system - run: sudo apt-get update -y - - name: Install dependencies - run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check - - name: Test PostgreSQL 13 - run: | - set -e - install_postgresql() { - version=${1:-13} - git_repo="https://github.com/postgres/postgres.git" - cd /tmp - git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" - cd /tmp/postgres - ./configure --prefix=/usr/local/pgsql - make - sudo make install - sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start - export PATH=/usr/local/pgsql/bin:$PATH - export LD_LIBRARY_PATH=/usr/local/pgsql/lib - } - - config_postgresql(){ - version=${1:-13} - sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf - sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf - sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf - host postgres repl 127.0.0.1/32 scram-sha-256 - host postgres repl ::1/128 scram-sha-256 - host replication repl 127.0.0.1/32 scram-sha-256 - host replication repl ::1/128 scram-sha-256 - EOF" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" - } - - install_pgmoneta_ext() { - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ - mkdir build - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ - cmake .. - make - sudo make install - } - - create_pgmoneta_ext(){ - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" - } - - test_pgmoneta_ext(){ - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test - export PGPASSWORD='secretpassword' - ./pgmoneta_ext_test - unset PGPASSWORD - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop - } - - echo "******************* START PostgreSQL 13 ******************" - install_postgresql 13 - config_postgresql 13 - install_pgmoneta_ext - create_pgmoneta_ext - test_pgmoneta_ext - echo "******************* PostgreSQL 13 Success ******************" - - test-postgresql-14: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Update system - run: sudo apt-get update -y - - name: Install dependencies - run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check - - name: Test PostgreSQL 14 - run: | - set -e - - install_postgresql() { - version=${1:-13} - git_repo="https://github.com/postgres/postgres.git" - cd /tmp - git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" - cd /tmp/postgres - ./configure --prefix=/usr/local/pgsql - make - sudo make install - sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start - export PATH=/usr/local/pgsql/bin:$PATH - export LD_LIBRARY_PATH=/usr/local/pgsql/lib - } - - config_postgresql(){ - version=${1:-13} - sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf - sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf - sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf - host postgres repl 127.0.0.1/32 scram-sha-256 - host postgres repl ::1/128 scram-sha-256 - host replication repl 127.0.0.1/32 scram-sha-256 - host replication repl ::1/128 scram-sha-256 - EOF" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" - } - - install_pgmoneta_ext() { - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ - mkdir build - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ - cmake .. - make - sudo make install - } - - create_pgmoneta_ext(){ - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" - } - - test_pgmoneta_ext(){ - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test - export PGPASSWORD='secretpassword' - ./pgmoneta_ext_test - unset PGPASSWORD - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop - } - - echo "******************* START PostgreSQL 14 ******************" - install_postgresql 14 - config_postgresql 14 - install_pgmoneta_ext - create_pgmoneta_ext - test_pgmoneta_ext - echo "******************* PostgreSQL 14 Success ******************" - - test-postgresql-15: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Update system - run: sudo apt-get update -y - - name: Install dependencies - run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check - - name: Test PostgreSQL 15 - run: | - set -e - install_postgresql() { - version=${1:-13} - git_repo="https://github.com/postgres/postgres.git" - cd /tmp - git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" - cd /tmp/postgres - ./configure --prefix=/usr/local/pgsql - make - sudo make install - sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start - export PATH=/usr/local/pgsql/bin:$PATH - export LD_LIBRARY_PATH=/usr/local/pgsql/lib - } - - config_postgresql(){ - version=${1:-13} - sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf - sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf - sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf - host postgres repl 127.0.0.1/32 scram-sha-256 - host postgres repl ::1/128 scram-sha-256 - host replication repl 127.0.0.1/32 scram-sha-256 - host replication repl ::1/128 scram-sha-256 - EOF" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" - } - - install_pgmoneta_ext() { - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ - mkdir build - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ - cmake .. - make - sudo make install - } - - create_pgmoneta_ext(){ - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" - } - - test_pgmoneta_ext(){ - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test - export PGPASSWORD='secretpassword' - ./pgmoneta_ext_test - unset PGPASSWORD - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop - } - - echo "******************* START PostgreSQL 15 ******************" - install_postgresql 15 - config_postgresql 15 - install_pgmoneta_ext - create_pgmoneta_ext - test_pgmoneta_ext - echo "******************* PostgreSQL 15 Success ******************" - - test-postgresql-16: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Update system - run: sudo apt-get update -y - - name: Install dependencies - run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check - - name: Test PostgreSQL 16 - run: | - set -e - install_postgresql() { - version=${1:-13} - git_repo="https://github.com/postgres/postgres.git" - cd /tmp - git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" - cd /tmp/postgres - ./configure --prefix=/usr/local/pgsql - make - sudo make install - sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start - export PATH=/usr/local/pgsql/bin:$PATH - export LD_LIBRARY_PATH=/usr/local/pgsql/lib - } - - config_postgresql(){ - version=${1:-13} - sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf - sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf - sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf - host postgres repl 127.0.0.1/32 scram-sha-256 - host postgres repl ::1/128 scram-sha-256 - host replication repl 127.0.0.1/32 scram-sha-256 - host replication repl ::1/128 scram-sha-256 - EOF" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" - } - - install_pgmoneta_ext() { - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ - mkdir build - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ - cmake .. - make - sudo make install - } - - create_pgmoneta_ext(){ - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" - } - - test_pgmoneta_ext(){ - cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test - export PGPASSWORD='secretpassword' - ./pgmoneta_ext_test - unset PGPASSWORD - sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" - sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop - } - - echo "******************* START PostgreSQL 16 ******************" - install_postgresql 16 - config_postgresql 16 - install_pgmoneta_ext - create_pgmoneta_ext - test_pgmoneta_ext - echo "******************* PostgreSQL 16 Success ******************" +# name: CI + +# on: +# push: +# branches: +# - main +# - actions +# pull_request: +# branches: +# - main + +# jobs: +# test-postgresql-13: +# runs-on: ubuntu-latest + +# steps: +# - uses: actions/checkout@v4 +# - name: Update system +# run: sudo apt-get update -y +# - name: Install dependencies +# run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check +# - name: Test PostgreSQL 13 +# run: | +# set -e +# install_postgresql() { +# version=${1:-13} +# git_repo="https://github.com/postgres/postgres.git" +# cd /tmp +# git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" +# cd /tmp/postgres +# ./configure --prefix=/usr/local/pgsql +# make +# sudo make install +# sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start +# export PATH=/usr/local/pgsql/bin:$PATH +# export LD_LIBRARY_PATH=/usr/local/pgsql/lib +# } + +# config_postgresql(){ +# version=${1:-13} +# sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf +# sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf +# sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf +# host postgres repl 127.0.0.1/32 scram-sha-256 +# host postgres repl ::1/128 scram-sha-256 +# host replication repl 127.0.0.1/32 scram-sha-256 +# host replication repl ::1/128 scram-sha-256 +# EOF" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" +# } + +# install_pgmoneta_ext() { +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ +# mkdir build +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ +# cmake .. +# make +# sudo make install +# } + +# create_pgmoneta_ext(){ +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" +# } + +# test_pgmoneta_ext(){ +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test +# export PGPASSWORD='secretpassword' +# ./pgmoneta_ext_test +# unset PGPASSWORD +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop +# } + +# echo "******************* START PostgreSQL 13 ******************" +# install_postgresql 13 +# config_postgresql 13 +# install_pgmoneta_ext +# create_pgmoneta_ext +# test_pgmoneta_ext +# echo "******************* PostgreSQL 13 Success ******************" + +# test-postgresql-14: +# runs-on: ubuntu-latest + +# steps: +# - uses: actions/checkout@v4 +# - name: Update system +# run: sudo apt-get update -y +# - name: Install dependencies +# run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check +# - name: Test PostgreSQL 14 +# run: | +# set -e + +# install_postgresql() { +# version=${1:-13} +# git_repo="https://github.com/postgres/postgres.git" +# cd /tmp +# git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" +# cd /tmp/postgres +# ./configure --prefix=/usr/local/pgsql +# make +# sudo make install +# sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start +# export PATH=/usr/local/pgsql/bin:$PATH +# export LD_LIBRARY_PATH=/usr/local/pgsql/lib +# } + +# config_postgresql(){ +# version=${1:-13} +# sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf +# sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf +# sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf +# host postgres repl 127.0.0.1/32 scram-sha-256 +# host postgres repl ::1/128 scram-sha-256 +# host replication repl 127.0.0.1/32 scram-sha-256 +# host replication repl ::1/128 scram-sha-256 +# EOF" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" +# } + +# install_pgmoneta_ext() { +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ +# mkdir build +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ +# cmake .. +# make +# sudo make install +# } + +# create_pgmoneta_ext(){ +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" +# } + +# test_pgmoneta_ext(){ +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test +# export PGPASSWORD='secretpassword' +# ./pgmoneta_ext_test +# unset PGPASSWORD +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop +# } + +# echo "******************* START PostgreSQL 14 ******************" +# install_postgresql 14 +# config_postgresql 14 +# install_pgmoneta_ext +# create_pgmoneta_ext +# test_pgmoneta_ext +# echo "******************* PostgreSQL 14 Success ******************" + +# test-postgresql-15: +# runs-on: ubuntu-latest + +# steps: +# - uses: actions/checkout@v4 +# - name: Update system +# run: sudo apt-get update -y +# - name: Install dependencies +# run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check +# - name: Test PostgreSQL 15 +# run: | +# set -e +# install_postgresql() { +# version=${1:-13} +# git_repo="https://github.com/postgres/postgres.git" +# cd /tmp +# git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" +# cd /tmp/postgres +# ./configure --prefix=/usr/local/pgsql +# make +# sudo make install +# sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start +# export PATH=/usr/local/pgsql/bin:$PATH +# export LD_LIBRARY_PATH=/usr/local/pgsql/lib +# } + +# config_postgresql(){ +# version=${1:-13} +# sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf +# sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf +# sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf +# host postgres repl 127.0.0.1/32 scram-sha-256 +# host postgres repl ::1/128 scram-sha-256 +# host replication repl 127.0.0.1/32 scram-sha-256 +# host replication repl ::1/128 scram-sha-256 +# EOF" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" +# } + +# install_pgmoneta_ext() { +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ +# mkdir build +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ +# cmake .. +# make +# sudo make install +# } + +# create_pgmoneta_ext(){ +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" +# } + +# test_pgmoneta_ext(){ +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test +# export PGPASSWORD='secretpassword' +# ./pgmoneta_ext_test +# unset PGPASSWORD +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop +# } + +# echo "******************* START PostgreSQL 15 ******************" +# install_postgresql 15 +# config_postgresql 15 +# install_pgmoneta_ext +# create_pgmoneta_ext +# test_pgmoneta_ext +# echo "******************* PostgreSQL 15 Success ******************" + +# test-postgresql-16: +# runs-on: ubuntu-latest + +# steps: +# - uses: actions/checkout@v4 +# - name: Update system +# run: sudo apt-get update -y +# - name: Install dependencies +# run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check +# - name: Test PostgreSQL 16 +# run: | +# set -e +# install_postgresql() { +# version=${1:-13} +# git_repo="https://github.com/postgres/postgres.git" +# cd /tmp +# git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" +# cd /tmp/postgres +# ./configure --prefix=/usr/local/pgsql +# make +# sudo make install +# sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start +# export PATH=/usr/local/pgsql/bin:$PATH +# export LD_LIBRARY_PATH=/usr/local/pgsql/lib +# } + +# config_postgresql(){ +# version=${1:-13} +# sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf +# sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf +# sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf +# host postgres repl 127.0.0.1/32 scram-sha-256 +# host postgres repl ::1/128 scram-sha-256 +# host replication repl 127.0.0.1/32 scram-sha-256 +# host replication repl ::1/128 scram-sha-256 +# EOF" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" +# } + +# install_pgmoneta_ext() { +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ +# mkdir build +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ +# cmake .. +# make +# sudo make install +# } + +# create_pgmoneta_ext(){ +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" +# } + +# test_pgmoneta_ext(){ +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test +# export PGPASSWORD='secretpassword' +# ./pgmoneta_ext_test +# unset PGPASSWORD +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop +# } + +# echo "******************* START PostgreSQL 16 ******************" +# install_postgresql 16 +# config_postgresql 16 +# install_pgmoneta_ext +# create_pgmoneta_ext +# test_pgmoneta_ext +# echo "******************* PostgreSQL 16 Success ******************" + +# test-postgresql-17: +# runs-on: ubuntu-latest + +# steps: +# - uses: actions/checkout@v4 +# - name: Update system +# run: sudo apt-get update -y +# - name: Install dependencies +# run: sudo apt-get install -y --no-install-recommends git gcc cmake make wget build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev libxml2-utils xsltproc ccache pkg-config check +# - name: Test PostgreSQL 17 +# run: | +# set -e +# install_postgresql() { +# version=${1:-13} +# git_repo="https://github.com/postgres/postgres.git" +# cd /tmp +# git clone --branch "REL_${version}_STABLE" --single-branch --depth 1 "$git_repo" +# cd /tmp/postgres +# ./configure --prefix=/usr/local/pgsql +# make +# sudo make install +# sudo -u postgres /usr/local/pgsql/bin/initdb -D /tmp/pgsql-${version} +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile start +# export PATH=/usr/local/pgsql/bin:$PATH +# export LD_LIBRARY_PATH=/usr/local/pgsql/lib +# } + +# config_postgresql(){ +# version=${1:-13} +# sudo -u postgres sed -i 's/^#\s*password_encryption\s*=\s*\(md5\|scram-sha-256\)/password_encryption = scram-sha-256/' /tmp/pgsql-${version}/postgresql.conf +# sudo -u postgres sed -i '/^host/d' /tmp/pgsql-${version}/pg_hba.conf +# sudo -u postgres bash -c "cat <> /tmp/pgsql-${version}/pg_hba.conf +# host postgres repl 127.0.0.1/32 scram-sha-256 +# host postgres repl ::1/128 scram-sha-256 +# host replication repl 127.0.0.1/32 scram-sha-256 +# host replication repl ::1/128 scram-sha-256 +# EOF" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile restart +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';" +# } + +# install_pgmoneta_ext() { +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/ +# mkdir build +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/ +# cmake .. +# make +# sudo make install +# } + +# create_pgmoneta_ext(){ +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;" +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;" +# } + +# test_pgmoneta_ext(){ +# cd /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/test +# export PGPASSWORD='secretpassword' +# ./pgmoneta_ext_test +# unset PGPASSWORD +# sudo -u postgres /usr/local/pgsql/bin/psql -U postgres -c "DROP ROLE repl;" +# sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /tmp/pgsql-${version} -l /tmp/logfile stop +# } + +# echo "******************* START PostgreSQL 17 ******************" +# install_postgresql 17 +# config_postgresql 17 +# install_pgmoneta_ext +# create_pgmoneta_ext +# test_pgmoneta_ext +# echo "******************* PostgreSQL 17 Success ******************" + diff --git a/doc/manual/user-02-functions.md b/doc/manual/user-02-functions.md index 566fb15..3028aca 100644 --- a/doc/manual/user-02-functions.md +++ b/doc/manual/user-02-functions.md @@ -8,8 +8,10 @@ After you create the extension `pgmoneta_ext` using the `postgres` role, you can ## Extension functions -| Function | Privilege | Description | -|-----------------------------|-----------|--------------------------------------------------------| -| `pgmoneta_ext_version()` | Default | Return the version number of `pgmoneta_ext` as a Datum.| -| `pgmoneta_ext_switch_wal()` | SUPERUSER | A function for switching to a new WAL file. | -| `pgmoneta_ext_checkpoint()` | SUPERUSER
pg_checkpoint | A function which forces a checkpoint.
This function can only be executed by a `SUPERUSER` in PostgreSQL 13/14, but can also be executed by `pg_checkpoint` in PostgreSQL 15+.
You can use the SQL command `GRANT pg_checkpoint TO repl;` to assign the role in PostgreSQL 15+.| +| Function | Privilege | Parameters | Description | +|-----------------------------|-----------|------------|--------------------------------------------------------| +| `pgmoneta_ext_version()` | Default | None | Return the version number of `pgmoneta_ext` as a Datum.| +| `pgmoneta_ext_switch_wal()` | SUPERUSER | None | A function for switching to a new WAL file. | +| `pgmoneta_ext_checkpoint()` | SUPERUSER
pg_checkpoint | None | A function which forces a checkpoint.
This function can only be executed by a `SUPERUSER` in PostgreSQL 13/14, but can also be executed by `pg_checkpoint` in PostgreSQL 15+.
You can use the SQL command `GRANT pg_checkpoint TO repl;` to assign the role in PostgreSQL 15+.| +| `pgmoneta_ext_get_file()`| SUPERUSER | path/to/file | Return the bytes of the specified file that is passed in.| +| `pgmoneta_ext_get_files()` | SUPERUSER | path/to/dir | Return all file paths in the specified directory passed in.| diff --git a/sql/pgmoneta_ext--0.1.0.sql b/sql/pgmoneta_ext--0.1.0.sql index fe2d79b..456b705 100644 --- a/sql/pgmoneta_ext--0.1.0.sql +++ b/sql/pgmoneta_ext--0.1.0.sql @@ -14,4 +14,12 @@ CREATE FUNCTION pgmoneta_ext_checkpoint(OUT success bool, ) RETURNS record AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; \ No newline at end of file +LANGUAGE C STRICT; + +CREATE FUNCTION pgmoneta_ext_get_file(file_path TEXT) RETURNS TEXT +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +CREATE OR REPLACE FUNCTION pgmoneta_ext_get_files(file_path TEXT) RETURNS text[] +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; diff --git a/src/include/utils.h b/src/include/utils.h index 781e5d2..ff42794 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -35,15 +35,21 @@ extern "C" { #endif /* PostgreSQL */ -#include "postgres.h" -#include "fmgr.h" +#include +#include +#include +#include /* system */ +#include #include +#include +#include +#include -#define PRIVILEDGE_DEFAULT 1 << 0 // 001 -#define PRIVILEDGE_PG_CHECKPOINT 1 << 1 // 010 -#define PRIVILEDGE_SUPERUSER 1 << 2 // 100 +#define PRIVILEGE_DEFAULT 1 << 0 // 001 +#define PRIVILEGE_PG_CHECKPOINT 1 << 1 // 010 +#define PRIVILEGE_SUPERUSER 1 << 2 // 100 /** * Check if the role has superuser privileges. diff --git a/src/pgmoneta_ext/lib.c b/src/pgmoneta_ext/lib.c index 222671a..4469930 100644 --- a/src/pgmoneta_ext/lib.c +++ b/src/pgmoneta_ext/lib.c @@ -32,27 +32,50 @@ #include /* PostgreSQL */ -#include "postgres.h" -#include "access/htup_details.h" -#include "access/xlog.h" -#include "access/xlog_internal.h" -#include "catalog/pg_authid.h" -#include "catalog/pg_type.h" -#include "fmgr.h" -#include "funcapi.h" -#include "miscadmin.h" -#include "utils/acl.h" -#include "utils/builtins.h" -#include "utils/elog.h" -#include "utils/errcodes.h" -#include "utils/lsyscache.h" -#include "utils/syscache.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* system */ +#include +#include +#include +#include + +#ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; +#endif + +#define PGMONETA_EXT_CHUNK_SIZE 8192 + +static text* encode_bytea_to_base64(bytea* data); +static void list_files(const char* name, ArrayBuildState* astate); PG_FUNCTION_INFO_V1(pgmoneta_ext_version); PG_FUNCTION_INFO_V1(pgmoneta_ext_switch_wal); PG_FUNCTION_INFO_V1(pgmoneta_ext_checkpoint); +PG_FUNCTION_INFO_V1(pgmoneta_ext_get_file); +PG_FUNCTION_INFO_V1(pgmoneta_ext_get_files); Datum pgmoneta_ext_version(PG_FUNCTION_ARGS) @@ -87,7 +110,7 @@ pgmoneta_ext_switch_wal(PG_FUNCTION_ARGS) privileges = pgmoneta_ext_check_privilege(roleid); - if (privileges & PRIVILEDGE_SUPERUSER) + if (privileges & PRIVILEGE_SUPERUSER) { // Request to switch WAL with mark_unimportant set to false. recptr = RequestXLogSwitch(false); @@ -140,7 +163,7 @@ pgmoneta_ext_checkpoint(PG_FUNCTION_ARGS) roleid = GetUserId(); privileges = pgmoneta_ext_check_privilege(roleid); - if (privileges & (PRIVILEDGE_PG_CHECKPOINT | PRIVILEDGE_SUPERUSER)) + if (privileges & (PRIVILEGE_PG_CHECKPOINT | PRIVILEGE_SUPERUSER)) { // Perform the checkpoint RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT | CHECKPOINT_FORCE); @@ -168,4 +191,179 @@ pgmoneta_ext_checkpoint(PG_FUNCTION_ARGS) result = HeapTupleGetDatum(tuple); PG_RETURN_DATUM(result); +} + +Datum +pgmoneta_ext_get_file(PG_FUNCTION_ARGS) +{ + int privileges; + char buffer[PGMONETA_EXT_CHUNK_SIZE]; + char* file_path; + size_t bytes_read; + text* file_path_arg; + FILE* file; + StringInfoData result; + Oid roleid; + bytea* file_data; + text* base64_result; + + file_path_arg = PG_GETARG_TEXT_PP(0); + file_path = text_to_cstring(file_path_arg); + + roleid = GetUserId(); + privileges = pgmoneta_ext_check_privilege(roleid); + + if (privileges & PRIVILEGE_SUPERUSER) + { + initStringInfo(&result); + + // Open the file + file = AllocateFile(file_path, "r"); + if (file == NULL) + { + ereport(ERROR, errmsg_internal("pgmoneta_ext_get_file: Could not open file \"%s\": %m", file_path)); + PG_RETURN_NULL(); + } + + PG_TRY(); + { + // Read the file content in chunks + while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) + { + if (ferror(file)) + { + ereport(ERROR, (errmsg_internal("pgmoneta_ext_get_file: Could not read file \"%s\": %m", file_path))); + } + appendBinaryStringInfo(&result, buffer, bytes_read); + } + } + PG_CATCH(); + { + FreeFile(file); + PG_RE_THROW(); + } + PG_END_TRY(); + + FreeFile(file); + + file_data = (bytea*)palloc(VARHDRSZ + result.len); + SET_VARSIZE(file_data, VARHDRSZ + result.len); + memcpy(VARDATA(file_data), result.data, result.len); + + // Encode as Base64 + base64_result = encode_bytea_to_base64(file_data); + + PG_RETURN_TEXT_P(base64_result); + } + else + { + ereport(LOG, errmsg_internal("pgmoneta_ext_checkpoint: Current role is not a superuser")); + PG_RETURN_NULL(); + } +} + +Datum +pgmoneta_ext_get_files(PG_FUNCTION_ARGS) +{ + text* file_path_arg; + char* file_path; + struct stat path_stat; + ArrayBuildState* astate = NULL; + Oid roleid; + int privileges; + + file_path_arg = PG_GETARG_TEXT_PP(0); + file_path = text_to_cstring(file_path_arg); + + roleid = GetUserId(); + privileges = pgmoneta_ext_check_privilege(roleid); + + if (privileges & PRIVILEGE_SUPERUSER) + { + if (stat(file_path, &path_stat) != 0) + { + ereport(ERROR, errmsg_internal("Could not stat file or directory: %s", file_path)); + PG_RETURN_NULL(); + } + + astate = initArrayResult(TEXTOID, CurrentMemoryContext, false); + + if (S_ISDIR(path_stat.st_mode)) + { + list_files(file_path, astate); + } + else if (S_ISREG(path_stat.st_mode)) + { + astate = accumArrayResult(astate, CStringGetTextDatum(file_path), false, TEXTOID, CurrentMemoryContext); + } + else + { + ereport(ERROR, errmsg_internal("Argument is neither a file nor a directory: %s", file_path)); + PG_RETURN_NULL(); + } + + // PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext)); + + PG_RETURN_ARRAYTYPE_P((ArrayType *) DatumGetPointer(makeArrayResult(astate, CurrentMemoryContext))); + } + else + { + ereport(LOG, errmsg_internal("pgmoneta_ext_checkpoint: Current role is not a superuser")); + PG_RETURN_NULL(); + } +} + +static text* +encode_bytea_to_base64(bytea* data) +{ + size_t data_len = VARSIZE_ANY_EXHDR(data); + size_t encoded_len = pg_b64_enc_len(data_len); + char* encoded = palloc(encoded_len + 1); + int actual_encoded_len = pg_b64_encode(VARDATA_ANY(data), data_len, encoded, encoded_len); + + text* result = (text*)palloc(VARHDRSZ + actual_encoded_len); + SET_VARSIZE(result, VARHDRSZ + actual_encoded_len); + memcpy(VARDATA(result), encoded, actual_encoded_len); + + pfree(encoded); + return result; +} + +static void +list_files(const char* name, ArrayBuildState* astate) +{ + DIR* dir; + struct dirent* entry; + + if (!(dir = opendir(name))) + { + return; + } + + while ((entry = readdir(dir)) != NULL) + { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s", name, entry->d_name); + + struct stat path_stat; + if (stat(path, &path_stat) != 0) + { + continue; + } + + if (S_ISDIR(path_stat.st_mode)) + { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + { + continue; + } + + list_files(path, astate); + } + else if (S_ISREG(path_stat.st_mode)) + { + astate = accumArrayResult(astate, CStringGetTextDatum(path), false, TEXTOID, CurrentMemoryContext); + } + } + closedir(dir); } \ No newline at end of file diff --git a/src/pgmoneta_ext/utils.c b/src/pgmoneta_ext/utils.c index d6edff3..cb5ca8f 100644 --- a/src/pgmoneta_ext/utils.c +++ b/src/pgmoneta_ext/utils.c @@ -31,15 +31,15 @@ #include /* PostgreSQL */ -#include "access/htup_details.h" -#include "catalog/pg_authid.h" -#include "miscadmin.h" -#include "utils/acl.h" -#include "utils/builtins.h" -#include "utils/elog.h" -#include "utils/errcodes.h" -#include "utils/relcache.h" -#include "utils/syscache.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include /* system */ @@ -116,7 +116,7 @@ pgmoneta_ext_check_privilege(Oid roleid) if (pgmoneta_ext_check_superuser(roleid)) { - privileges |= PRIVILEDGE_SUPERUSER; + privileges |= PRIVILEGE_SUPERUSER; } #if PG_VERSION_NUM >= 150000 @@ -124,11 +124,11 @@ pgmoneta_ext_check_privilege(Oid roleid) if (is_pg_checkpoint) { - privileges |= PRIVILEDGE_PG_CHECKPOINT; + privileges |= PRIVILEGE_PG_CHECKPOINT; } #endif - privileges |= PRIVILEDGE_DEFAULT; + privileges |= PRIVILEGE_DEFAULT; return privileges; -} \ No newline at end of file +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e2e2f4d..2e0a047 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,6 +51,7 @@ if(container) add_test(test_version_14_rocky9 "${CMAKE_CURRENT_SOURCE_DIR}/../test/testsuite.sh" "${CMAKE_CURRENT_SOURCE_DIR}/../test" "Dockerfile.rocky9" 14) add_test(test_version_15_rocky9 "${CMAKE_CURRENT_SOURCE_DIR}/../test/testsuite.sh" "${CMAKE_CURRENT_SOURCE_DIR}/../test" "Dockerfile.rocky9" 15) add_test(test_version_16_rocky9 "${CMAKE_CURRENT_SOURCE_DIR}/../test/testsuite.sh" "${CMAKE_CURRENT_SOURCE_DIR}/../test" "Dockerfile.rocky9" 16) + add_test(test_version_17_rocky9 "${CMAKE_CURRENT_SOURCE_DIR}/../test/testsuite.sh" "${CMAKE_CURRENT_SOURCE_DIR}/../test" "Dockerfile.rocky9" 17) set(failRegex "Failures: [1-9][0-9]*" @@ -64,4 +65,6 @@ if(container) PROPERTY FAIL_REGULAR_EXPRESSION "${failRegex}") set_property (TEST test_version_16_rocky9 PROPERTY FAIL_REGULAR_EXPRESSION "${failRegex}") + set_property (TEST test_version_17_rocky9 + PROPERTY FAIL_REGULAR_EXPRESSION "${failRegex}") endif() diff --git a/test/Dockerfile.rocky9 b/test/Dockerfile.rocky9 index 0fd1612..049eda1 100644 --- a/test/Dockerfile.rocky9 +++ b/test/Dockerfile.rocky9 @@ -36,6 +36,7 @@ ENV PATH=/pgsql/bin:$PATH ENV LD_LIBRARY_PATH=/pgsql/lib RUN yum clean all && \ + yum makecache && \ yum update -y && \ yum install -y epel-release && \ yum install -y --allowerasing \ @@ -43,7 +44,7 @@ RUN yum clean all && \ wget ccache libicu-devel flex libxml2-devel libxslt-devel perl libev libev-devel \ openssl openssl-devel systemd systemd-devel zlib zlib-devel libzstd libzstd-devel \ lz4 lz4-devel libssh libssh-devel libcurl libcurl-devel python3-pip libatomic \ - bzip2 bzip2-devel libarchive libarchive-devel check check-devel && \ + bzip2 bzip2-devel libarchive libarchive-devel check check-devel --skip-broken && \ yum groupinstall -y 'Development Tools' && \ yum clean all && \ pip3 install docutils @@ -76,7 +77,8 @@ RUN su - postgres -c "/pgsql/bin/initdb -D /pgsql/data" && \ su - postgres -c "/pgsql/bin/pg_ctl -D /pgsql/data -l /pgsql/logfile stop" # Install pgmoneta_ext -RUN git clone --branch "main" --single-branch --depth 1 https://github.com/pgmoneta/pgmoneta_ext && \ +# RUN git clone --branch "main" --single-branch --depth 1 https://github.com/pgmoneta/pgmoneta_ext && \ +RUN git clone --branch "extra" --single-branch --depth 1 https://github.com/GuChad369/pgmoneta_ext && \ cd pgmoneta_ext && \ mkdir build && \ cd build && \ @@ -92,5 +94,6 @@ RUN git clone --branch "main" --single-branch --depth 1 https://github.com/pgmon CMD ["sh", "-c", "\ su - postgres -c '/pgsql/bin/pg_ctl -D /pgsql/data -l /pgsql/logfile start' && \ + su - postgres -c '/pgsql/bin/psql -U postgres -c \"ALTER USER repl WITH SUPERUSER;\"' && \ /pgmoneta_ext/build/test/pgmoneta_ext_test \ "] \ No newline at end of file diff --git a/test/lib/pgmoneta_ext_test.c b/test/lib/pgmoneta_ext_test.c index 1dae440..c87dee3 100644 --- a/test/lib/pgmoneta_ext_test.c +++ b/test/lib/pgmoneta_ext_test.c @@ -31,9 +31,11 @@ #define BUFFER_SIZE 8192 -#define PGMONETA_EXT_VERSION_RESULT "0.1.0" -#define PGMONETA_EXT_SWITCH_WAL_RESULT "(f,)" -#define PGMONETA_EXT_CHECKPOINT_RESULT "(f,)" +#define PGMONETA_EXT_VERSION_RESULT "0.1.0" +#define PGMONETA_EXT_SWITCH_WAL_RESULT "(f,)" +#define PGMONETA_EXT_CHECKPOINT_RESULT "(f,)" +#define PGMONETA_EXT_GET_FILE_RESULT "dfgdfg" +#define PGMONETA_EXT_GET_FILES_RESULT "dfgdfg" int execute_command(const char* command, char* output, size_t output_size) @@ -82,6 +84,26 @@ START_TEST(test_pgmoneta_ext_checkpoint) } END_TEST +START_TEST(test_pgmoneta_ext_get_file) +{ + char output[BUFFER_SIZE]; + int result = execute_command("psql -h localhost -p 5432 -U repl -d postgres -t -c \"SELECT pgmoneta_ext_get_file('/pgsql/logfile');\"", output, BUFFER_SIZE); + ck_assert_int_eq(result, 0); + printf("out: %s", output); + ck_assert_msg(strstr(output, PGMONETA_EXT_GET_FILE_RESULT) != NULL, "Expected checkpoint result not found in output: %s", output); +} +END_TEST + +START_TEST(test_pgmoneta_ext_get_files) +{ + char output[BUFFER_SIZE]; + int result = execute_command("psql -h localhost -p 5432 -U repl -d postgres -t -c \"SELECT pgmoneta_ext_get_files('/pgsql');\"", output, BUFFER_SIZE); + ck_assert_int_eq(result, 0); + printf("out: %s", output); + ck_assert_msg(strstr(output, PGMONETA_EXT_GET_FILES_RESULT) != NULL, "Expected checkpoint result not found in output: %s", output); +} +END_TEST + Suite* pgmoneta_ext_suite(void) { @@ -95,6 +117,8 @@ pgmoneta_ext_suite(void) tcase_add_test(tc_core, test_pgmoneta_ext_version); tcase_add_test(tc_core, test_pgmoneta_ext_switch_wal); tcase_add_test(tc_core, test_pgmoneta_ext_checkpoint); + tcase_add_test(tc_core, test_pgmoneta_ext_get_file); + tcase_add_test(tc_core, test_pgmoneta_ext_get_files); suite_add_tcase(s, tc_core); return s; diff --git a/test/testsuite.sh b/test/testsuite.sh index 52907ea..16e3b15 100755 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -37,7 +37,7 @@ check_podman_installed() { } run_podman(){ - local dockerfile=${1:-'Dockerfile.rocky8'} + local dockerfile=${1:-'Dockerfile.rocky9'} local version=${2:-13} local suffix="${dockerfile##*.}" @@ -73,7 +73,7 @@ check_docker_installed() { } run_docker(){ - local dockerfile=${1:-'Dockerfile.rocky8'} + local dockerfile=${1:-'Dockerfile.rocky9'} local version=${2:-13} local suffix="${dockerfile##*.}" @@ -108,9 +108,9 @@ run_tests() { local dockerfile=$2 local version=$3 - valid_versions=("13" "14" "15" "16") + valid_versions=("13" "14" "15" "16" "17") if [[ ! " ${valid_versions[@]} " =~ " ${version} " ]]; then - echo "Invalid version. Please provide a version of 13, 14, 15, or 16." + echo "Invalid version. Please provide a version of 13, 14, 15, 16 or 17." exit 1 fi @@ -132,7 +132,7 @@ run_tests() { } dir=${1:-'./'} -dockerfile=${2:-'Dockerfile.rocky8'} +dockerfile=${2:-'Dockerfile.rocky9'} version=${3:-13} run_tests "$dir" "$dockerfile" "$version"