Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 106 additions & 29 deletions nix/ext/pgtap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,117 @@
perl,
perlPackages,
which,
buildEnv,
fetchpatch2,
}:

stdenv.mkDerivation rec {
let
pname = "pgtap";
version = "1.2.0";

src = fetchFromGitHub {
owner = "theory";
repo = "pgtap";
rev = "v${version}";
hash = "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8=";
};
# Load version configuration from external file
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};

# Filter versions compatible with current PostgreSQL version
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;

# Derived version information
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
numberOfVersions = builtins.length versions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash) supportedVersions
);
repoOwner = "theory";
repo = "${repoOwner}/${pname}";

# Build function for individual versions
build =
version: hash:
stdenv.mkDerivation rec {
inherit pname version;

src = fetchFromGitHub {
owner = repoOwner;
repo = pname;
rev = "v${version}";
inherit hash;
};

nativeBuildInputs = [
postgresql
perl
perlPackages.TAPParserSourceHandlerpgTAP
which
];

patches = lib.optionals (version == "1.3.3") [
# Fix error in upgrade script from 1.2.0 to 1.3.3
(fetchpatch2 {
name = "pgtap-fix-upgrade-from-1.2.0-to-1.3.3.patch";
url = "https://github.com/${repoOwner}/${pname}/pull/338.diff?full_index=1";
hash = "sha256-AVRQyqCGoc0gcoMRWBJKMmUBjadGtWg7rvHmTq5rRpw=";
})
];

installPhase = ''
runHook preInstall

mkdir -p $out/{lib,share/postgresql/extension}

# Create version-specific control file
sed -e "/^default_version =/d" \
-e "s|^module_pathname = .*|module_pathname = '$ext'|" \
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control

# Copy SQL file to install the specific version
cp sql/${pname}--${version}.sql $out/share/postgresql/extension

if [[ -f src/pgtap.so ]]; then
# Install the shared library with version suffix
install -Dm755 src/pgtap.so $out/lib/${pname}-${version}${postgresql.dlSuffix}
fi

# For the latest version, create default control file and symlink and copy SQL upgrade scripts
if [[ "${version}" == "${latestVersion}" ]]; then
{
echo "default_version = '${version}'"
cat $out/share/postgresql/extension/${pname}--${version}.control
} > $out/share/postgresql/extension/${pname}.control
cp sql/${pname}--*--*.sql $out/share/postgresql/extension
elif [[ "${version}" == "1.3.1" ]]; then
# 1.3.1 is the first and only version with a C extension
ln -sfn ${pname}-${version}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
fi
'';

meta = with lib; {
description = "A unit testing framework for PostgreSQL";
longDescription = ''
pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL.
It includes a comprehensive collection of TAP-emitting assertion functions,
as well as the ability to integrate with other TAP-emitting test frameworks.
It can also be used in the xUnit testing style.
'';
homepage = "https://pgtap.org";
inherit (postgresql.meta) platforms;
license = licenses.mit;
};
};
in
buildEnv {
name = pname;
paths = packages;

nativeBuildInputs = [
postgresql
perl
perlPackages.TAPParserSourceHandlerpgTAP
which
pathsToLink = [
"/lib"
"/share/postgresql/extension"
];

installPhase = ''
install -D {sql/pgtap--${version}.sql,pgtap.control} -t $out/share/postgresql/extension
'';

meta = with lib; {
description = "A unit testing framework for PostgreSQL";
longDescription = ''
pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL.
It includes a comprehensive collection of TAP-emitting assertion functions,
as well as the ability to integrate with other TAP-emitting test frameworks.
It can also be used in the xUnit testing style.
'';
homepage = "https://pgtap.org";
inherit (postgresql.meta) platforms;
license = licenses.mit;
passthru = {
inherit versions numberOfVersions;
pname = "${pname}-all";
version =
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
1 change: 1 addition & 0 deletions nix/ext/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ builtins.listToAttrs (
"pg_stat_monitor"
"pg_tle"
"pgaudit"
"pgtap"
"vector"
"wal2json"
"wrappers"
Expand Down
22 changes: 22 additions & 0 deletions nix/ext/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,28 @@
"hash": "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s="
}
},
"pgtap": {
"1.2.0": {
"postgresql": [
"15"
],
"hash": "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8="
},
"1.3.1": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-HOgCb1CCfsfbMbMMWuzFJ4B8CfVm9b0sI2zBY3/kqyI="
},
"1.3.3": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-YgvfLGF7pLVcCKD66NnWAydDxtoYHH1DpLiYTEKHJ0E="
}
},
"pg_tle": {
"1.0.1": {
"postgresql": [
Expand Down
Loading