lol

nixosTests.php: migrate to runTest

authored by

Piotr Kwiecinski and committed by
Masum Reza
e44f5a37 a212f088

+180 -168
+20 -5
nixos/tests/all-tests.nix
··· 914 914 phosh = handleTest ./phosh.nix {}; 915 915 photonvision = handleTest ./photonvision.nix {}; 916 916 photoprism = handleTest ./photoprism.nix {}; 917 - php = handleTest ./php {}; 918 - php81 = handleTest ./php { php = pkgs.php81; }; 919 - php82 = handleTest ./php { php = pkgs.php82; }; 920 - php83 = handleTest ./php { php = pkgs.php83; }; 921 - php84 = handleTest ./php { php = pkgs.php84; }; 917 + php = import ./php/default.nix { 918 + inherit runTest; 919 + php = pkgs.php; 920 + }; 921 + php81 = import ./php/default.nix { 922 + inherit runTest; 923 + php = pkgs.php81; 924 + }; 925 + php82 = import ./php/default.nix { 926 + inherit runTest; 927 + php = pkgs.php82; 928 + }; 929 + php83 = import ./php/default.nix { 930 + inherit runTest; 931 + php = pkgs.php83; 932 + }; 933 + php84 = import ./php/default.nix { 934 + inherit runTest; 935 + php = pkgs.php84; 936 + }; 922 937 phylactery = handleTest ./web-apps/phylactery.nix {}; 923 938 pict-rs = handleTest ./pict-rs.nix {}; 924 939 pingvin-share = handleTest ./pingvin-share.nix {} ;
+11 -13
nixos/tests/php/default.nix
··· 1 1 { 2 - system ? builtins.currentSystem, 3 - config ? { }, 4 - pkgs ? import ../../.. { inherit system config; }, 5 - php ? pkgs.php, 2 + runTest, 3 + php, 6 4 }: 7 5 8 6 let ··· 11 9 }; 12 10 in 13 11 { 14 - fpm = import ./fpm.nix { 15 - inherit system pkgs; 16 - php = php'; 12 + fpm = runTest { 13 + imports = [ ./fpm.nix ]; 14 + _module.args.php = php'; 17 15 }; 18 - httpd = import ./httpd.nix { 19 - inherit system pkgs; 20 - php = php'; 16 + httpd = runTest { 17 + imports = [ ./httpd.nix ]; 18 + _module.args.php = php'; 21 19 }; 22 - pcre = import ./pcre.nix { 23 - inherit system pkgs; 24 - php = php'; 20 + pcre = runTest { 21 + imports = [ ./pcre.nix ]; 22 + _module.args.php = php'; 25 23 }; 26 24 }
+53 -48
nixos/tests/php/fpm.nix
··· 1 - import ../make-test-python.nix ({ pkgs, lib, php, ... }: { 1 + { lib, php, ... }: 2 + { 2 3 name = "php-${php.version}-fpm-nginx-test"; 3 4 meta.maintainers = lib.teams.php.members; 4 5 5 - nodes.machine = { config, lib, pkgs, ... }: { 6 - environment.systemPackages = [ php ]; 6 + nodes.machine = 7 + { config, pkgs, ... }: 8 + { 9 + environment.systemPackages = [ php ]; 7 10 8 - services.nginx = { 9 - enable = true; 11 + services.nginx = { 12 + enable = true; 10 13 11 - virtualHosts."phpfpm" = 12 - let 13 - testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; 14 - in 15 - { 16 - root = "${testdir}/web"; 17 - locations."~ \\.php$".extraConfig = '' 18 - fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket}; 19 - fastcgi_index index.php; 20 - include ${config.services.nginx.package}/conf/fastcgi_params; 21 - include ${pkgs.nginx}/conf/fastcgi.conf; 22 - ''; 23 - locations."/" = { 24 - tryFiles = "$uri $uri/ index.php"; 25 - index = "index.php index.html index.htm"; 14 + virtualHosts."phpfpm" = 15 + let 16 + testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; 17 + in 18 + { 19 + root = "${testdir}/web"; 20 + locations."~ \\.php$".extraConfig = '' 21 + fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket}; 22 + fastcgi_index index.php; 23 + include ${config.services.nginx.package}/conf/fastcgi_params; 24 + include ${pkgs.nginx}/conf/fastcgi.conf; 25 + ''; 26 + locations."/" = { 27 + tryFiles = "$uri $uri/ index.php"; 28 + index = "index.php index.html index.htm"; 29 + }; 26 30 }; 31 + }; 32 + 33 + services.phpfpm.pools."foobar" = { 34 + user = "nginx"; 35 + phpPackage = php; 36 + settings = { 37 + "listen.group" = "nginx"; 38 + "listen.mode" = "0600"; 39 + "listen.owner" = "nginx"; 40 + "pm" = "dynamic"; 41 + "pm.max_children" = 5; 42 + "pm.max_requests" = 500; 43 + "pm.max_spare_servers" = 3; 44 + "pm.min_spare_servers" = 1; 45 + "pm.start_servers" = 2; 27 46 }; 28 - }; 29 - 30 - services.phpfpm.pools."foobar" = { 31 - user = "nginx"; 32 - phpPackage = php; 33 - settings = { 34 - "listen.group" = "nginx"; 35 - "listen.mode" = "0600"; 36 - "listen.owner" = "nginx"; 37 - "pm" = "dynamic"; 38 - "pm.max_children" = 5; 39 - "pm.max_requests" = 500; 40 - "pm.max_spare_servers" = 3; 41 - "pm.min_spare_servers" = 1; 42 - "pm.start_servers" = 2; 43 47 }; 44 48 }; 45 - }; 46 - testScript = { ... }: '' 47 - machine.wait_for_unit("nginx.service") 48 - machine.wait_for_unit("phpfpm-foobar.service") 49 + testScript = 50 + { ... }: 51 + '' 52 + machine.wait_for_unit("nginx.service") 53 + machine.wait_for_unit("phpfpm-foobar.service") 49 54 50 - # Check so we get an evaluated PHP back 51 - response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") 52 - assert "PHP Version ${php.version}" in response, "PHP version not detected" 55 + # Check so we get an evaluated PHP back 56 + response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") 57 + assert "PHP Version ${php.version}" in response, "PHP version not detected" 53 58 54 - # Check so we have database and some other extensions loaded 55 - for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]: 56 - assert ext in response, f"Missing {ext} extension" 57 - machine.succeed(f'test -n "$(php -m | grep -i {ext})"') 58 - ''; 59 - }) 59 + # Check so we have database and some other extensions loaded 60 + for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]: 61 + assert ext in response, f"Missing {ext} extension" 62 + machine.succeed(f'test -n "$(php -m | grep -i {ext})"') 63 + ''; 64 + }
+42 -46
nixos/tests/php/httpd.nix
··· 1 - import ../make-test-python.nix ( 2 - { 3 - pkgs, 4 - lib, 5 - php, 6 - ... 7 - }: 8 - { 9 - name = "php-${php.version}-httpd-test"; 10 - meta.maintainers = lib.teams.php.members; 1 + { 2 + lib, 3 + php, 4 + ... 5 + }: 6 + { 7 + name = "php-${php.version}-httpd-test"; 8 + meta.maintainers = lib.teams.php.members; 11 9 12 - nodes.machine = 13 - { 14 - config, 15 - lib, 16 - pkgs, 17 - ... 18 - }: 19 - { 20 - services.httpd = { 21 - enable = true; 22 - adminAddr = "admin@phpfpm"; 23 - virtualHosts."phpfpm" = 24 - let 25 - testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; 26 - in 27 - { 28 - documentRoot = "${testdir}/web"; 29 - locations."/" = { 30 - index = "index.php index.html"; 31 - }; 10 + nodes.machine = 11 + { 12 + config, 13 + pkgs, 14 + ... 15 + }: 16 + { 17 + services.httpd = { 18 + enable = true; 19 + adminAddr = "admin@phpfpm"; 20 + virtualHosts."phpfpm" = 21 + let 22 + testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; 23 + in 24 + { 25 + documentRoot = "${testdir}/web"; 26 + locations."/" = { 27 + index = "index.php index.html"; 32 28 }; 33 - phpPackage = php; 34 - enablePHP = true; 35 - }; 29 + }; 30 + phpPackage = php; 31 + enablePHP = true; 36 32 }; 37 - testScript = 38 - { ... }: 39 - '' 40 - machine.wait_for_unit("httpd.service") 33 + }; 34 + testScript = 35 + { ... }: 36 + '' 37 + machine.wait_for_unit("httpd.service") 41 38 42 - # Check so we get an evaluated PHP back 43 - response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") 44 - assert "PHP Version ${php.version}" in response, "PHP version not detected" 39 + # Check so we get an evaluated PHP back 40 + response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") 41 + assert "PHP Version ${php.version}" in response, "PHP version not detected" 45 42 46 - # Check so we have database and some other extensions loaded 47 - for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]: 48 - assert ext in response, f"Missing {ext} extension" 49 - ''; 50 - } 51 - ) 43 + # Check so we have database and some other extensions loaded 44 + for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]: 45 + assert ext in response, f"Missing {ext} extension" 46 + ''; 47 + }
+54 -56
nixos/tests/php/pcre.nix
··· 1 1 let 2 2 testString = "can-use-subgroups"; 3 3 in 4 - import ../make-test-python.nix ( 5 - { 6 - pkgs, 7 - lib, 8 - php, 9 - ... 10 - }: 11 - { 12 - name = "php-${php.version}-httpd-pcre-jit-test"; 13 - meta.maintainers = lib.teams.php.members; 4 + { 5 + pkgs, 6 + lib, 7 + php, 8 + ... 9 + }: 10 + { 11 + name = "php-${php.version}-httpd-pcre-jit-test"; 12 + meta.maintainers = lib.teams.php.members; 14 13 15 - nodes.machine = 16 - { lib, pkgs, ... }: 17 - { 18 - time.timeZone = "UTC"; 19 - services.httpd = { 20 - enable = true; 21 - adminAddr = "please@dont.contact"; 22 - phpPackage = php; 23 - enablePHP = true; 24 - phpOptions = "pcre.jit = true"; 25 - extraConfig = 26 - let 27 - testRoot = pkgs.writeText "index.php" '' 28 - <?php 29 - preg_match('/(${testString})/', '${testString}', $result); 30 - var_dump($result); 31 - ''; 32 - in 33 - '' 34 - Alias / ${testRoot}/ 35 - 36 - <Directory ${testRoot}> 37 - Require all granted 38 - </Directory> 14 + nodes.machine = 15 + { pkgs, ... }: 16 + { 17 + time.timeZone = "UTC"; 18 + services.httpd = { 19 + enable = true; 20 + adminAddr = "please@dont.contact"; 21 + phpPackage = php; 22 + enablePHP = true; 23 + phpOptions = "pcre.jit = true"; 24 + extraConfig = 25 + let 26 + testRoot = pkgs.writeText "index.php" '' 27 + <?php 28 + preg_match('/(${testString})/', '${testString}', $result); 29 + var_dump($result); 39 30 ''; 40 - }; 31 + in 32 + '' 33 + Alias / ${testRoot}/ 34 + 35 + <Directory ${testRoot}> 36 + Require all granted 37 + </Directory> 38 + ''; 41 39 }; 42 - testScript = 43 - let 44 - # PCRE JIT SEAlloc feature does not play well with fork() 45 - # The feature needs to either be disabled or PHP configured correctly 46 - # More information in https://bugs.php.net/bug.php?id=78927 and https://bugs.php.net/bug.php?id=78630 47 - pcreJitSeallocForkIssue = pkgs.writeText "pcre-jit-sealloc-issue.php" '' 48 - <?php 49 - preg_match('/nixos/', 'nixos'); 50 - $pid = pcntl_fork(); 51 - pcntl_wait($pid); 52 - ''; 53 - in 54 - '' 55 - machine.wait_for_unit("httpd.service") 56 - # Ensure php evaluation by matching on the var_dump syntax 57 - response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/index.php") 58 - expected = 'string(${toString (builtins.stringLength testString)}) "${testString}"' 59 - assert expected in response, "Does not appear to be able to use subgroups." 60 - machine.succeed("${php}/bin/php -f ${pcreJitSeallocForkIssue}") 40 + }; 41 + testScript = 42 + let 43 + # PCRE JIT SEAlloc feature does not play well with fork() 44 + # The feature needs to either be disabled or PHP configured correctly 45 + # More information in https://bugs.php.net/bug.php?id=78927 and https://bugs.php.net/bug.php?id=78630 46 + pcreJitSeallocForkIssue = pkgs.writeText "pcre-jit-sealloc-issue.php" '' 47 + <?php 48 + preg_match('/nixos/', 'nixos'); 49 + $pid = pcntl_fork(); 50 + pcntl_wait($pid); 61 51 ''; 62 - } 63 - ) 52 + in 53 + '' 54 + machine.wait_for_unit("httpd.service") 55 + # Ensure php evaluation by matching on the var_dump syntax 56 + response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/index.php") 57 + expected = 'string(${toString (builtins.stringLength testString)}) "${testString}"' 58 + assert expected in response, "Does not appear to be able to use subgroups." 59 + machine.succeed("${php}/bin/php -f ${pcreJitSeallocForkIssue}") 60 + ''; 61 + }