core/pkgs/build-support/setup-hooks/postgresql-test-hook/test.nix

35 lines
674 B
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
postgresql,
postgresqlTestHook,
stdenv,
}:
2024-05-02 00:46:19 +00:00
stdenv.mkDerivation {
name = "postgresql-test-hook-test";
buildInputs = [ postgresqlTestHook ];
nativeCheckInputs = [ postgresql ];
dontUnpack = true;
doCheck = true;
2024-06-30 08:16:52 +00:00
passAsFile = [ "sql" ];
2024-05-02 00:46:19 +00:00
sql = ''
CREATE TABLE hello (
message text
);
INSERT INTO hello VALUES ('it '||'worked');
SELECT * FROM hello;
'';
postgresqlTestSetupPost = ''
TEST_POST_HOOK_RAN=1
'';
checkPhase = ''
runHook preCheck
psql <$sqlPath | grep 'it worked'
TEST_RAN=1
runHook postCheck
'';
installPhase = ''
[[ $TEST_RAN == 1 && $TEST_POST_HOOK_RAN == 1 ]]
touch $out
'';
}