forked from pgmoneta/pgmoneta_ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pgmoneta#9] Test suite in container
- Loading branch information
Showing
15 changed files
with
867 additions
and
567 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# check support | ||
# | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(PC_CHECK check) | ||
|
||
find_path(CHECK_INCLUDE_DIR | ||
NAMES check.h | ||
PATHS ${PC_CHECK_INCLUDE_DIRS} | ||
PATH_SUFFIXES check | ||
) | ||
|
||
find_library(CHECK_LIBRARY | ||
NAMES check | ||
PATHS ${PC_CHECK_LIBRARY_DIRS} | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Check DEFAULT_MSG CHECK_INCLUDE_DIR CHECK_LIBRARY) | ||
|
||
if (CHECK_FOUND) | ||
set(CHECK_LIBRARIES ${CHECK_LIBRARY}) | ||
set(CHECK_INCLUDE_DIRS ${CHECK_INCLUDE_DIR}) | ||
else () | ||
set(check FALSE) | ||
endif () | ||
|
||
mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Check for Docker | ||
# | ||
|
||
find_program(DOCKER_EXECUTABLE | ||
NAMES docker | ||
PATHS /usr/local/bin /usr/bin /bin | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Docker DEFAULT_MSG DOCKER_EXECUTABLE) | ||
|
||
if (DOCKER_FOUND) | ||
set(container TRUE) | ||
set(DOCKER_EXECUTABLE ${DOCKER_EXECUTABLE}) | ||
endif () | ||
|
||
mark_as_advanced(DOCKER_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Check for Podman | ||
# | ||
|
||
find_program(PODMAN_EXECUTABLE | ||
NAMES podman | ||
PATHS /usr/local/bin /usr/bin /bin | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Podman DEFAULT_MSG PODMAN_EXECUTABLE) | ||
|
||
if (PODMAN_FOUND) | ||
set(container TRUE) | ||
set(PODMAN_EXECUTABLE ${PODMAN_EXECUTABLE}) | ||
endif () | ||
|
||
mark_as_advanced(PODMAN_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,107 @@ | ||
# Test | ||
|
||
## Installation | ||
## Container Environment | ||
|
||
Since we are using source code to install, please first create a new user `postgres` for a normal installation. | ||
To ensure the test suite works well, please make sure you have installed `Docker` or `podman` on your OS. If neither `Docker` nor `podman` is installed, the test suite compilation will be skipped. | ||
|
||
``` sh | ||
sudo adduser postgres | ||
### Docker | ||
|
||
First, ensure your system is up to date. | ||
|
||
```sh | ||
dnf update | ||
``` | ||
|
||
Enter into the `/test` directory. | ||
Install the necessary packages for Docker. | ||
|
||
``` sh | ||
chmod +x installation.sh | ||
```sh | ||
dnf -y install dnf-plugins-core | ||
``` | ||
|
||
Run `installation.sh` to install any necessary dependencies and configuration. | ||
Add the Docker repository to your system. | ||
|
||
``` sh | ||
./installation.sh | ||
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo | ||
``` | ||
|
||
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). | ||
Install Docker Engine, Docker CLI, and Containerd. | ||
|
||
``` sh | ||
./installation.sh 14 | ||
```sh | ||
sudo dnf install docker-ce docker-ce-cli containerd.io | ||
``` | ||
|
||
> 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. | ||
Start the Docker service and enable it to start on boot. | ||
|
||
```sh | ||
sudo systemctl start docker | ||
sudo systemctl enable docker | ||
``` | ||
|
||
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. | ||
Verify that Docker is installed correctly. | ||
|
||
``` 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 | ||
```sh | ||
docker --version | ||
``` | ||
|
||
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. | ||
If you see the Docker version, then you have successfully installed Docker on Fedora. | ||
|
||
## Test functions | ||
### Podman | ||
|
||
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. | ||
Install Podman and the Docker alias package. | ||
|
||
download dependencies | ||
```sh | ||
dnf install podman podman-docker.noarch | ||
``` | ||
|
||
``` sh | ||
dnf install check check-devel | ||
Verify that Podman is installed correctly. | ||
|
||
```sh | ||
podman --version | ||
``` | ||
|
||
Enter into the `/test` directory. | ||
If you see the Podman version, then you have successfully installed Podman on Fedora. | ||
|
||
The `podman-docker.noarch` package simplifies the use of `Podman` for users accustomed to Docker. | ||
|
||
## Test suite | ||
|
||
Before you test, you need to install the `check` library. If there is no package for `check`, the `CMakeLists.txt` will not compile the test suite. Only after you have installed `check` will it compile the test suite. | ||
|
||
``` sh | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
dnf install -y check check-devel check-static | ||
``` | ||
|
||
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: | ||
You can simply use `CTest` to test all PostgreSQL versions from 13 to 16. It will automatically run `testsuite.sh` to test `pgmoneta_ext` for each version. The script will automatically create the Docker container, run it, and then use the `check` framework to test their functions inside it. After that, it will automatically clean up everything for you. | ||
|
||
Set the `PGPASSWORD` environment variable: | ||
After you follow the [DEVELOPERS.md](https://github.com/pgmoneta/pgmoneta_ext/blob/main/doc/DEVELOPERS.md) to install `pgmoneta_ext`, go to the directory `/pgmoneta_ext/build` and run the test. | ||
|
||
``` sh | ||
export PGPASSWORD='secretpassword' | ||
make test | ||
``` | ||
|
||
Run the `pgmoneta_ext_test` executable. | ||
This command will run the tests sequentially. If you want them to run simultaneously, please use the following command: | ||
|
||
``` sh | ||
ctest -j 8 | ||
``` | ||
|
||
This will run the tests in parallel using the given number of jobs. | ||
|
||
`CTest` will output logs into `/pgmoneta_ext/build/Testing/Temporary/LastTest.log`. If you want to check the specific process, you can review that log file. | ||
|
||
`testsuite.sh` accepts three variables. The first one is `dir`, which specifies the `/test` directory location, with a default value of `./`. The second one is `dockerfile`, with a default value of `Dockerfile.rocky8`. The third one is the PostgreSQL `version`, with a default value of `13`. | ||
|
||
## Local test | ||
|
||
If you just want to test if `pgmoneta_ext` works well on your machine, please follow these steps: | ||
|
||
- Install `pgmoneta_ext` and create the extension in PostgreSQL. | ||
- Navigate to the directory `/pgmoneta_ext/build/test`. | ||
- Run the following commands: | ||
|
||
```sh | ||
export PGPASSWORD='secretpassword' | ||
./pgmoneta_ext_test | ||
``` | ||
|
||
The `pgmoneta_ext_test` executable will use `check` to run all the functions in the extension locally and verify if they work correctly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.