mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +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
26
nix/api-test.nix
Normal file
26
nix/api-test.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
rustPlatform,
|
||||
fetchgit,
|
||||
pkg-config,
|
||||
openssl,
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "demostf-api-test";
|
||||
version = "0.1.4";
|
||||
|
||||
src = fetchgit {
|
||||
url = "https://github.com/demostf/api-test";
|
||||
rev = "b2a8446e9b12c84d2c9228e4babe5d34132d3298";
|
||||
hash = "sha256-Zn6P4ukhoxqP+16ZkLBbqzM9DsTLmSNa4zrkhmyzy/I";
|
||||
fetchLFS = true;
|
||||
};
|
||||
|
||||
buildInputs = [openssl];
|
||||
|
||||
nativeBuildInputs = [pkg-config];
|
||||
|
||||
doCheck = false;
|
||||
|
||||
cargoHash = "sha256-Irv6atngsh0hPJ256tMxer3nR0PjBcaOJLVldnPnwUs=";
|
||||
meta.mainProgram = "api-test";
|
||||
}
|
||||
127
nix/integration-tests.nix
Normal file
127
nix/integration-tests.nix
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
name = "demostf-api-client-test";
|
||||
nodes.machine = {config, ...}: let
|
||||
fpmCfg = config.services.phpfpm.pools.demostf-api;
|
||||
in {
|
||||
config = {
|
||||
environment.systemPackages = [pkgs.demostf-api-test];
|
||||
|
||||
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;
|
||||
'';
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts."localhost" = {
|
||||
root = "/var/empty";
|
||||
extraConfig = ''
|
||||
try_files $uri /index.php?$query_string /index.php;
|
||||
'';
|
||||
locations = {
|
||||
"~ ^(.+?\\.php)(/.*)?$" = {
|
||||
extraConfig = ''
|
||||
fastcgi_param PATH_INFO $2;
|
||||
fastcgi_pass unix:${fpmCfg.socket};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME ${pkgs.demostf-api}/share/php/demostf-api/src/public/index.php;
|
||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
client_max_body_size 250m;
|
||||
'';
|
||||
};
|
||||
"= /upload" = {
|
||||
extraConfig = ''
|
||||
fastcgi_pass unix:${fpmCfg.socket};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME ${pkgs.demostf-api}/share/php/demostf-api/src/public/upload.php;
|
||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
client_max_body_size 250m;
|
||||
'';
|
||||
};
|
||||
"/static/" = {
|
||||
alias = "/demos/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.phpfpm.pools.demostf-api = {
|
||||
phpPackage = pkgs.php.buildEnv {
|
||||
extensions = {
|
||||
enabled,
|
||||
all,
|
||||
}:
|
||||
enabled ++ (with all; [pdo apcu]);
|
||||
extraConfig = ''
|
||||
post_max_size = 150M
|
||||
upload_max_filesize = 150M
|
||||
'';
|
||||
};
|
||||
settings = {
|
||||
"clear_env" = "no";
|
||||
"pm" = "dynamic";
|
||||
"pm.max_children" = "25";
|
||||
"pm.start_servers" = "5";
|
||||
"pm.min_spare_servers" = "5";
|
||||
"pm.max_spare_servers" = "15";
|
||||
"catch_workers_output" = "yes";
|
||||
"listen.owner" = "nginx";
|
||||
"listen.group" = "nginx";
|
||||
};
|
||||
phpEnv = {
|
||||
BASE_HOST = "demos.tf";
|
||||
DEMO_ROOT = "/demos";
|
||||
DEMO_HOST = "localhost";
|
||||
DB_TYPE = "pgsql";
|
||||
DB_HOST = "/run/postgresql";
|
||||
DB_PORT = "5432";
|
||||
DB_DATABASE = "demostf";
|
||||
DB_USERNAME = "demostf";
|
||||
APP_ROOT = "http://localhost";
|
||||
EDIT_SECRET = "edit";
|
||||
PARSER_PATH = lib.getExe pkgs.demostf-parser;
|
||||
};
|
||||
user = "demostf";
|
||||
group = "demostf";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = let
|
||||
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.wait_for_unit("phpfpm-demostf-api")
|
||||
machine.wait_for_unit("nginx")
|
||||
machine.wait_until_succeeds("curl http://127.0.0.1", timeout=45)
|
||||
machine.succeed("DB_URL='postgres://demostf:demostf@localhost/demostf'\
|
||||
BASE_URL='http://localhost/'\
|
||||
EDIT_KEY='edit'\
|
||||
api-test", timeout=180)
|
||||
'';
|
||||
}
|
||||
18
nix/overlay.nix
Normal file
18
nix/overlay.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
final: prev: {
|
||||
demostf-parser = final.callPackage ./parser.nix {};
|
||||
demostf-api = final.callPackage ./package.nix {};
|
||||
demostf-api-dev = final.callPackage ./package.nix {dev = true;};
|
||||
demostf-api-test = final.callPackage ./api-test.nix {};
|
||||
demostf-api-php = final.php82.buildEnv {
|
||||
extraConfig = "memory_limit = 2G";
|
||||
extensions = {
|
||||
enabled,
|
||||
all,
|
||||
}:
|
||||
enabled
|
||||
++ (with all; [
|
||||
pdo
|
||||
apcu
|
||||
]);
|
||||
};
|
||||
}
|
||||
24
nix/package.nix
Normal file
24
nix/package.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
lib,
|
||||
demostf-api-php,
|
||||
dev ? false,
|
||||
}: let
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
in
|
||||
demostf-api-php.buildComposerProject (finalAttrs: {
|
||||
pname = "demostf-api";
|
||||
version = "0.1.0";
|
||||
|
||||
composerNoDev = !dev;
|
||||
|
||||
src = sourceByRegex ../. ["composer.*" "(src|test)(/.*)?"];
|
||||
|
||||
vendorHash =
|
||||
if dev
|
||||
then "sha256-PBp2PHoKfM66BjWxbEt5suKlkUxDxXdxhhCVzfRbJdo="
|
||||
else "sha256-EYWCR2aJAoyWvEX+SML4Fb3F3KGcUtwCgqhAGT6ZjZ4=";
|
||||
|
||||
composerStrictValidation = false;
|
||||
|
||||
doCheck = false;
|
||||
})
|
||||
24
nix/parser.nix
Normal file
24
nix/parser.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
rustPlatform,
|
||||
fetchFromGitHub,
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "demostf-parser";
|
||||
version = "0.5.1";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "demostf";
|
||||
repo = "parser";
|
||||
rev = "0cd87a8a40e2a6af637d831b272c2758cebd2f9c";
|
||||
hash = "sha256-bKcc0hWTkdYUDMI/DjUh45abuBeQEvkn6TsuAz02H5Y=";
|
||||
};
|
||||
|
||||
cargoBuildFlags = ''
|
||||
--bin parse_demo
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
|
||||
cargoHash = "sha256-/Fnw6l2fznrBK780E4q1PKFOkT0eiL+dE+UuhFA+V9M=";
|
||||
meta.mainProgram = "parse_demo";
|
||||
}
|
||||
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