nixpkgs/nixos/tests/wordpress.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
2.8 KiB
Nix
Raw Permalink Normal View History

import ./make-test-python.nix ({ lib, pkgs, ... }:
2016-09-26 22:06:56 +00:00
rec {
2016-09-26 22:06:56 +00:00
name = "wordpress";
meta = with pkgs.lib.maintainers; {
maintainers = [
flokli
grahamc # under duress!
mmilata
];
2016-09-26 22:06:56 +00:00
};
nodes = lib.foldl (a: version: let
2024-09-19 20:25:37 +00:00
package = pkgs."wordpress_${version}";
in a // {
"wp${version}_httpd" = _: {
2020-04-06 07:25:07 +00:00
services.httpd.adminAddr = "webmaster@site.local";
services.httpd.logPerVirtualHost = true;
services.wordpress.webserver = "httpd";
services.wordpress.sites = {
2020-04-06 07:25:07 +00:00
"site1.local" = {
database.tablePrefix = "site1_";
inherit package;
2020-04-06 07:25:07 +00:00
};
"site2.local" = {
database.tablePrefix = "site2_";
inherit package;
2020-04-06 07:25:07 +00:00
};
};
2016-09-26 22:06:56 +00:00
2020-04-06 07:25:07 +00:00
networking.firewall.allowedTCPPorts = [ 80 ];
networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
};
"wp${version}_nginx" = _: {
2020-04-06 07:25:07 +00:00
services.wordpress.webserver = "nginx";
services.wordpress.sites = {
"site1.local" = {
database.tablePrefix = "site1_";
inherit package;
2020-04-06 07:25:07 +00:00
};
"site2.local" = {
database.tablePrefix = "site2_";
inherit package;
2020-04-06 07:25:07 +00:00
};
};
2020-04-06 07:25:07 +00:00
networking.firewall.allowedTCPPorts = [ 80 ];
networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
};
2021-08-03 13:24:34 +00:00
"wp${version}_caddy" = _: {
2021-08-03 13:24:34 +00:00
services.wordpress.webserver = "caddy";
services.wordpress.sites = {
"site1.local" = {
database.tablePrefix = "site1_";
inherit package;
2021-08-03 13:24:34 +00:00
};
"site2.local" = {
database.tablePrefix = "site2_";
inherit package;
2021-08-03 13:24:34 +00:00
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
};
}) {} [
2024-11-11 22:26:22 +00:00
"6_6"
];
2016-09-26 22:06:56 +00:00
testScript = ''
2019-11-23 22:54:06 +00:00
import re
2016-09-26 22:06:56 +00:00
2019-11-23 22:54:06 +00:00
start_all()
2016-09-26 22:06:56 +00:00
${lib.concatStrings (lib.mapAttrsToList (name: value: ''
${name}.wait_for_unit("${(value null).services.wordpress.webserver}")
'') nodes)}
2019-11-23 22:54:06 +00:00
site_names = ["site1.local", "site2.local"]
for machine in (${lib.concatStringsSep ", " (builtins.attrNames nodes)}):
2019-11-23 22:54:06 +00:00
for site_name in site_names:
2020-04-06 07:25:07 +00:00
machine.wait_for_unit(f"phpfpm-wordpress-{site_name}")
2016-09-26 22:06:56 +00:00
2020-04-06 07:25:07 +00:00
with subtest("website returns welcome screen"):
assert "Welcome to the famous" in machine.succeed(f"curl -L {site_name}")
2019-11-23 22:54:06 +00:00
2020-04-06 07:25:07 +00:00
with subtest("wordpress-init went through"):
info = machine.get_unit_info(f"wordpress-init-{site_name}")
assert info["Result"] == "success"
with subtest("secret keys are set"):
pattern = re.compile(r"^define.*NONCE_SALT.{64,};$", re.MULTILINE)
assert pattern.search(
machine.succeed(f"cat /var/lib/wordpress/{site_name}/secret-keys.php")
)
2019-11-23 22:54:06 +00:00
'';
2016-09-26 22:06:56 +00:00
})