Skip to content

Commit

Permalink
[pgmoneta#9] Initial test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
GuChad369 committed Jun 16, 2024
1 parent 1fd30d3 commit 72be9f1
Show file tree
Hide file tree
Showing 11 changed files with 671 additions and 8 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**

A clear and concise description of what the bug is.

**To Reproduce**

Steps to reproduce the behavior.

**Version**

What is the version of pgmoneta_ext ?

**PostgreSQL**

What is the version of PostgreSQL ?

**Debug logs**

Can you provide any debug logs (`log_level = debug5`) of the issue ?

**Tip**

Use \`\`\` before and after the text to keep the output as is.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature
assignees: ''

---

**Is your feature request related to a problem? Please describe.**

A clear and concise description of what the problem is.

**Describe the solution you'd like**

A clear and concise description of what you want to happen.

**Additional information**

Any additional information you can provide, like an overall design description
29 changes: 21 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jobs:
- uses: actions/checkout@v4
- name: Update system
run: sudo apt update -y
- name: Install dependencies
run: sudo apt install -y git gcc cmake make postgresql postgresql-server-dev-all
- name: Install postgresql
run: |
sudo apt install -y postgresql-14
psql --version
- name: Install postgresql-server-dev-14
run: sudo apt install -y postgresql-server-dev-14
- name: Init database
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
Expand All @@ -42,16 +46,25 @@ jobs:
sudo -u postgres /usr/lib/postgresql/${version}/bin/psql -U postgres -c "CREATE ROLE repl WITH LOGIN REPLICATION PASSWORD 'secretpassword';"
- name: GCC/mkdir
run: mkdir build
working-directory: /home/runner/work/pgmoneta/pgmoneta_ext/
working-directory: /home/runner/work/pgmoneta_ext/pgmoneta_ext/
- name: GCC/cmake
run: export CC=/usr/bin/gcc && cmake -DCMAKE_BUILD_TYPE=Debug ..
working-directory: /home/runner/work/pgmoneta/pgmoneta_ext/build/
working-directory: /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/
- name: GCC/make
run: make
working-directory: /home/runner/work/pgmoneta/pgmoneta_ext/build/
- name: rm -Rf
run: rm -Rf build/
working-directory: /home/runner/work/pgmoneta/pgmoneta_ext/
working-directory: /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/
- name: GCC/make install
run: sudo make install
working-directory: /home/runner/work/pgmoneta_ext/pgmoneta_ext/build/
- name: Create extension
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
/usr/lib/postgresql/${version}/bin/psql -U postgres -c "DROP EXTENSION IF EXISTS pgmoneta_ext;"
/usr/lib/postgresql/${version}/bin/psql -U postgres -c "CREATE EXTENSION pgmoneta_ext;"
- name: Test function
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
/usr/lib/postgresql/${version}/bin/psql -U postgres -c "SELECT pgmoneta_ext_version();"
- name: Cleanup
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
Expand Down
71 changes: 71 additions & 0 deletions doc/TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Test

## Installation

Since we are using source code to install, please first create a new user `postgres` for a normal installation.

``` sh
sudo adduser postgres
```

Enter into the `/test` directory.

``` sh
chmod +x installation.sh
```

Run `installation.sh` to install any necessary dependencies and configuration.

``` sh
./installation.sh
```

The script will install PostgreSQL 13 by default. If you prefer to install a specific version, please input the version as shown below. It will automatically download and use the latest patch release number. You can find the source versions at [PostgreSQL GIT repository](https://github.com/postgres/postgres).

``` sh
./installation.sh 14
```

> IMPORTANT:
> If you want to test different versions, please make sure you have deleted all previous version data, removed the role 'repl', and stopped the PostgreSQL server. Otherwise, it will raise some compatibility errors when you install and configure a new version. It is better to kill all current PostgreSQL processes.
If you encounter the following error when creating the extension, you may need to inform the system where to find the `libpq.so.5` library. Use the command `echo "/usr/local/pgsql/lib" | sudo tee -a /etc/ld.so.conf` and then update the cache using `sudo ldconfig`. After this, you need to create the extension manually.

``` console
ERROR: could not load library "/usr/local/pgsql/lib/pgmoneta_ext.so": libpq.so.5: cannot open shared object file: No such file or directory
```

If you see the error `could not change directory to "/home/pgmoneta/pgmoneta_ext/test/build": Permission denied`, it doesn't matter. This will not affect the execution of the command; it is just because you used `sudo`, which tries to change the current working directory.

## Test functions

If you have already installed `pgmoneta_ext` successfully and completed all configurations described in [DEVELOPERS.md](https://github.com/pgmoneta/pgmoneta_ext/blob/main/doc/DEVELOPERS.md#developer-guide), you can skip the **Installation** step above and directly follow the steps below to test the functions in the API extension.

download dependencies

``` sh
dnf install check check-devel
```

Enter into the `/test` directory.

``` sh
mkdir build
cd build
cmake ..
make
```

Before running the `pgmoneta_ext_test` executable, you need to set the `PGPASSWORD` environment variable for the `repl` role. For our setup, the password is `secretpassword`. Follow these steps:

Set the `PGPASSWORD` environment variable:

``` sh
export PGPASSWORD='secretpassword'
```

Run the `pgmoneta_ext_test` executable.

``` sh
./pgmoneta_ext_test
```
4 changes: 4 additions & 0 deletions doc/manual/99-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[make]: https://www.gnu.org/software/make/
[clang]: https://clang.llvm.org/
[pandoctemplate]: https://github.com/Wandmalfarbe/pandoc-latex-template
[postgresqlrepo]: https://github.com/postgres/postgres

<!-- Contributing -->
[ask]: https://github.com/pgmoneta/pgmoneta_ext/discussions
Expand All @@ -23,3 +24,6 @@
[star]: https://github.com/pgmoneta/pgmoneta_ext/stargazers
[twitter]: https://twitter.com/pgmoneta/
[license]: https://opensource.org/licenses/BSD-3-Clause

<!-- doc/ -->
[developers]: https://github.com/pgmoneta/pgmoneta_ext/blob/main/doc/DEVELOPERS.md#developer-guide
73 changes: 73 additions & 0 deletions doc/manual/dev-03-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
\newpage

# Test suite

## Installation

Since we are using source code to install, please first create a new user `postgres` for a normal installation.

``` sh
sudo adduser postgres
```

Enter into the `/test` directory.

``` sh
chmod +x installation.sh
```

Run `installation.sh` to install any necessary dependencies and configuration.

``` sh
./installation.sh
```

The script will install PostgreSQL 13 by default. If you prefer to install a specific version, please input the version as shown below. It will automatically download and use the latest patch release number. You can find the source versions at [PostgreSQL GIT repository][postgresqlrepo].

``` sh
./installation.sh 14
```

> IMPORTANT:
> If you want to test different versions, please make sure you have deleted all previous version data, removed the role 'repl', and stopped the PostgreSQL server. Otherwise, it will raise some compatibility errors when you install and configure a new version. It is better to kill all current PostgreSQL processes.
If you encounter the following error when creating the extension, you may need to inform the system where to find the `libpq.so.5` library. Use the command `echo "/usr/local/pgsql/lib" | sudo tee -a /etc/ld.so.conf` and then update the cache using `sudo ldconfig`. After this, you need to create the extension manually.

``` console
ERROR: could not load library "/usr/local/pgsql/lib/pgmoneta_ext.so": libpq.so.5: cannot open shared object file: No such file or directory
```

If you see the error `could not change directory to "/home/pgmoneta/pgmoneta_ext/test/build": Permission denied`, it doesn't matter. This will not affect the execution of the command; it is just because you used `sudo`, which tries to change the current working directory.

## Test functions

If you have already installed `pgmoneta_ext` successfully and completed all configurations described in [DEVELOPERS.md][developers], you can skip the **Installation** step above and directly follow the steps below to test the functions in the API extension.

download dependencies

``` sh
dnf install check check-devel
```

Enter into the `/test` directory.

``` sh
mkdir build
cd build
cmake ..
make
```

Before running the `pgmoneta_ext_test` executable, you need to set the `PGPASSWORD` environment variable for the `repl` role. For our setup, the password is `secretpassword`. Follow these steps:

Set the `PGPASSWORD` environment variable:

``` sh
export PGPASSWORD='secretpassword'
```

Run the `pgmoneta_ext_test` executable.

``` sh
./pgmoneta_ext_test
```
69 changes: 69 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Copyright (C) 2024 The pgmoneta community
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

cmake_minimum_required(VERSION 3.14)

project(pgmoneta_ext_test C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")

find_library(CHECK_LIBRARY check PATHS /usr/lib64)
find_path(CHECK_INCLUDE_DIR check.h PATHS /usr/include)

if(CHECK_LIBRARY AND CHECK_INCLUDE_DIR)
add_library(Check::check SHARED IMPORTED)
set_target_properties(Check::check PROPERTIES
IMPORTED_LOCATION ${CHECK_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CHECK_INCLUDE_DIR})
else()
message(FATAL_ERROR "Check library not found")
endif()

if(EXISTS "/etc/debian_version")
include_directories(/usr/include/subunit)
endif()

set(SOURCES
pgmoneta_ext_test.c
runner.c
)

add_executable(pgmoneta_ext_test ${SOURCES})

if(EXISTS "/etc/debian_version")
target_link_libraries(pgmoneta_ext_test Check::check subunit pthread rt m)
else()
target_link_libraries(pgmoneta_ext_test Check::check pthread rt m)
endif()


add_custom_target(custom_clean
COMMAND ${CMAKE_COMMAND} -E remove -f *.o pgmoneta_ext_test
COMMENT "Cleaning up..."
)
Loading

0 comments on commit 72be9f1

Please sign in to comment.