jetbrains: 2024.1 -> 2024.2.7 (#351041)
[NixPkgs.git] / nixos / tests / wordpress.nix
bloba2cd4803029864fa37f9f4f0ab33a9a9cc3c0d68
1 import ./make-test-python.nix ({ lib, pkgs, ... }:
3 rec {
4   name = "wordpress";
5   meta = with pkgs.lib.maintainers; {
6     maintainers = [
7       flokli
8       grahamc # under duress!
9       mmilata
10     ];
11   };
13   nodes = lib.foldl (a: version: let
14     package = pkgs."wordpress_${version}";
15   in a // {
16     "wp${version}_httpd" = _: {
17       services.httpd.adminAddr = "webmaster@site.local";
18       services.httpd.logPerVirtualHost = true;
20       services.wordpress.webserver = "httpd";
21       services.wordpress.sites = {
22         "site1.local" = {
23           database.tablePrefix = "site1_";
24           inherit package;
25         };
26         "site2.local" = {
27           database.tablePrefix = "site2_";
28           inherit package;
29         };
30       };
32       networking.firewall.allowedTCPPorts = [ 80 ];
33       networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
34     };
36     "wp${version}_nginx" = _: {
37       services.wordpress.webserver = "nginx";
38       services.wordpress.sites = {
39         "site1.local" = {
40           database.tablePrefix = "site1_";
41           inherit package;
42         };
43         "site2.local" = {
44           database.tablePrefix = "site2_";
45           inherit package;
46         };
47       };
49       networking.firewall.allowedTCPPorts = [ 80 ];
50       networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
51     };
53     "wp${version}_caddy" = _: {
54       services.wordpress.webserver = "caddy";
55       services.wordpress.sites = {
56         "site1.local" = {
57           database.tablePrefix = "site1_";
58           inherit package;
59         };
60         "site2.local" = {
61           database.tablePrefix = "site2_";
62           inherit package;
63         };
64       };
66       networking.firewall.allowedTCPPorts = [ 80 ];
67       networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
68     };
69   }) {} [
70     "6_5" "6_6"
71   ];
73   testScript = ''
74     import re
76     start_all()
78     ${lib.concatStrings (lib.mapAttrsToList (name: value: ''
79       ${name}.wait_for_unit("${(value null).services.wordpress.webserver}")
80     '') nodes)}
82     site_names = ["site1.local", "site2.local"]
84     for machine in (${lib.concatStringsSep ", " (builtins.attrNames nodes)}):
85         for site_name in site_names:
86             machine.wait_for_unit(f"phpfpm-wordpress-{site_name}")
88             with subtest("website returns welcome screen"):
89                 assert "Welcome to the famous" in machine.succeed(f"curl -L {site_name}")
91             with subtest("wordpress-init went through"):
92                 info = machine.get_unit_info(f"wordpress-init-{site_name}")
93                 assert info["Result"] == "success"
95             with subtest("secret keys are set"):
96                 pattern = re.compile(r"^define.*NONCE_SALT.{64,};$", re.MULTILINE)
97                 assert pattern.search(
98                     machine.succeed(f"cat /var/lib/wordpress/{site_name}/secret-keys.php")
99                 )
100   '';