nixosTests.unit-php: migrate to runTest

Part of #386873
This commit is contained in:
Piotr Kwiecinski 2025-03-29 17:29:12 +01:00
parent 3155ac1d91
commit 4f57c255ac
No known key found for this signature in database
GPG Key ID: EC0DE1CB9D5258B4
2 changed files with 51 additions and 53 deletions

View File

@ -1257,7 +1257,7 @@ in {
umurmur = handleTest ./umurmur.nix {};
unbound = handleTest ./unbound.nix {};
unifi = handleTest ./unifi.nix {};
unit-php = handleTest ./web-servers/unit-php.nix {};
unit-php = runTest ./web-servers/unit-php.nix;
unit-perl = handleTest ./web-servers/unit-perl.nix {};
upnp.iptables = handleTest ./upnp.nix { useNftables = false; };
upnp.nftables = handleTest ./upnp.nix { useNftables = true; };

View File

@ -1,62 +1,60 @@
import ../make-test-python.nix (
{ pkgs, ... }:
let
testdir = pkgs.writeTextDir "www/info.php" "<?php phpinfo();";
{ pkgs, ... }:
let
testdir = pkgs.writeTextDir "www/info.php" "<?php phpinfo();";
in
{
name = "unit-php-test";
meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
in
{
name = "unit-php-test";
meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
nodes.machine =
{
config,
lib,
pkgs,
...
}:
{
services.unit = {
enable = true;
config = pkgs.lib.strings.toJSON {
listeners."*:9081".application = "php_81";
applications.php_81 = {
type = "php 8.1";
processes = 1;
user = "testuser";
group = "testgroup";
root = "${testdir}/www";
index = "info.php";
options.file = "${pkgs.unit.usedPhp81}/lib/php.ini";
};
};
};
users = {
users.testuser = {
isSystemUser = true;
uid = 1080;
nodes.machine =
{
config,
lib,
pkgs,
...
}:
{
services.unit = {
enable = true;
config = pkgs.lib.strings.toJSON {
listeners."*:9081".application = "php_81";
applications.php_81 = {
type = "php 8.1";
processes = 1;
user = "testuser";
group = "testgroup";
};
groups.testgroup = {
gid = 1080;
root = "${testdir}/www";
index = "info.php";
options.file = "${pkgs.unit.usedPhp81}/lib/php.ini";
};
};
};
testScript = ''
machine.start()
users = {
users.testuser = {
isSystemUser = true;
uid = 1080;
group = "testgroup";
};
groups.testgroup = {
gid = 1080;
};
};
};
testScript = ''
machine.start()
machine.wait_for_unit("unit.service")
machine.wait_for_open_port(9081)
machine.wait_for_unit("unit.service")
machine.wait_for_open_port(9081)
# Check so we get an evaluated PHP back
response = machine.succeed("curl -f -vvv -s http://127.0.0.1:9081/")
assert "PHP Version ${pkgs.unit.usedPhp81.version}" in response, "PHP version not detected"
# Check so we get an evaluated PHP back
response = machine.succeed("curl -f -vvv -s http://127.0.0.1:9081/")
assert "PHP Version ${pkgs.unit.usedPhp81.version}" in response, "PHP version not detected"
# Check so we have database and some other extensions loaded
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
assert ext in response, f"Missing {ext} extension"
# Check so we have database and some other extensions loaded
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
assert ext in response, f"Missing {ext} extension"
machine.shutdown()
'';
}
)
machine.shutdown()
'';
}