mirror of
https://codeberg.org/demostf/api.git
synced 2026-08-02 20:34:45 +02:00
flake reorg, nix integration testing
This commit is contained in:
parent
1a8380360b
commit
233dc5f01f
20 changed files with 3565 additions and 3723 deletions
53
nix/unit-tests.nix
Normal file
53
nix/unit-tests.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
name = "demostf-api-unit-tests";
|
||||
nodes.machine = {config, ...}: {
|
||||
config = {
|
||||
users.groups.demostf = {};
|
||||
users.users.demostf = {
|
||||
group = "demostf";
|
||||
isSystemUser = true;
|
||||
};
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = ["demostf"];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "demostf";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
initialScript = pkgs.writeText "init-sql-script" ''
|
||||
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = let
|
||||
php = lib.getExe pkgs.demostf-api-php;
|
||||
api = pkgs.demostf-api-dev;
|
||||
initSql = pkgs.fetchurl {
|
||||
url = "https://github.com/demostf/db/raw/refs/heads/master/schema.sql";
|
||||
hash = "sha256-AwXN9mh9CRk6HWdvyUR+YdBkpmExNIDOIeDMz6XqjEQ=";
|
||||
};
|
||||
in ''
|
||||
machine.succeed("mkdir /demos && chmod 0777 /demos");
|
||||
machine.wait_for_unit("postgresql")
|
||||
machine.succeed("sudo -u demostf psql demostf demostf < ${initSql}");
|
||||
machine.succeed("sudo -u postgres psql postgres postgres -c \"alter user demostf with password 'demostf';\"");
|
||||
machine.succeed("cd ${api}/share/php/demostf-api; DB_HOST='localhost'\
|
||||
DB_TYPE='pgsql'\
|
||||
DB_PORT='5432'\
|
||||
DB_USERNAME='demostf'\
|
||||
DB_PASSWORD='demostf'\
|
||||
DB_DATABASE='demostf'\
|
||||
BASE_URL='http://localhost/'\
|
||||
EDIT_KEY='edit'\
|
||||
${php} ./vendor/bin/phpunit test", timeout=180)
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue