WIP: module qois.cloud: add basic test #77
3 changed files with 76 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
options,
|
||||
...
|
||||
}:
|
||||
|
||||
|
@ -30,6 +31,10 @@ with lib;
|
|||
"nextcloud30"
|
||||
];
|
||||
};
|
||||
|
||||
adminpassFile = options.services.nextcloud.config.adminpassFile // {
|
||||
default = config.sops.secrets."nextcloud/admin".path;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
@ -59,7 +64,7 @@ with lib;
|
|||
database.createLocally = true;
|
||||
|
||||
config = {
|
||||
adminpassFile = config.sops.secrets."nextcloud/admin".path;
|
||||
inherit (cfg) adminpassFile;
|
||||
adminuser = "root";
|
||||
dbtype = "pgsql";
|
||||
};
|
||||
|
|
36
nixos-modules/cloud/test.nix
Normal file
36
nixos-modules/cloud/test.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
...
|
||||
}:
|
||||
{
|
||||
# Note: This extends the default configuration from ${self}/checks/nixos-modules
|
||||
nodes.webserver =
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
inherit (pkgs) curl gnugrep;
|
||||
inherit (lib) mkForce;
|
||||
cloud-domain = "cloud.example.com";
|
||||
in
|
||||
{
|
||||
qois.cloud = {
|
||||
enable = true;
|
||||
domain = cloud-domain;
|
||||
package = pkgs.nextcloud31;
|
||||
adminpassFile = "${pkgs.writeText "adminpass" "insecure"}"; # Don't try this at home!
|
||||
};
|
||||
|
||||
qois.postgresql.package = pkgs.postgresql;
|
||||
sops.secrets = mkForce { };
|
||||
|
||||
# Disable TLS services
|
||||
das-g marked this conversation as resolved
Outdated
|
||||
services.nginx.virtualHosts."${cloud-domain}" = {
|
||||
forceSSL = mkForce false;
|
||||
enableACME = mkForce false;
|
||||
};
|
||||
|
||||
# Test environment
|
||||
environment.systemPackages = [
|
||||
curl
|
||||
gnugrep
|
||||
];
|
||||
};
|
||||
}
|
34
nixos-modules/cloud/test.py
Normal file
34
nixos-modules/cloud/test.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
def test(subtest, webserver):
|
||||
webserver.wait_for_unit("nginx")
|
||||
fabianhauser
commented
You need to wait for the You need to wait for the `phpfpm-nextcloud.service` to be up and running (and maybe `nextcloud-setup.service`, it's a oneshot service tough).
das-g
commented
Or should we just wait for Or should we just wait for `multi-user.target` like [nixos/tests/nextcloud/default.nix](https://github.com/NixOS/nixpkgs/blob/86c02c145a0b6ae0fab47564e0a003a967203f46/nixos/tests/nextcloud/default.nix#L80) does?
|
||||
webserver.wait_for_open_port(80)
|
||||
webserver.wait_for_unit("nextcloud-setup.service")
|
||||
webserver.wait_for_unit("phpfpm-nextcloud.service")
|
||||
|
||||
# Helpers
|
||||
def curl_variable_test(node, variable, expected, url):
|
||||
value = node.succeed(
|
||||
f"curl -s --no-location -o /dev/null -w '%{{{variable}}}' '{url}'"
|
||||
)
|
||||
assert value == expected, (
|
||||
f"expected {variable} to be '{expected}' but got '{value}'"
|
||||
)
|
||||
|
||||
def expect_http_code(node, code, url):
|
||||
curl_variable_test(node, "http_code", code, url)
|
||||
|
||||
def expect_http_content_contains(node, expectedContentSnippet, url):
|
||||
content = node.succeed(f"curl --no-location --silent '{url}'")
|
||||
assert expectedContentSnippet in content, f"""
|
||||
expected in content:
|
||||
{expectedContentSnippet}
|
||||
at {url} but got following content:
|
||||
{content}
|
||||
"""
|
||||
|
||||
# Tests
|
||||
with subtest("website is successfully served on cloud.example.com"):
|
||||
webserver.succeed("grep cloud.example.com /etc/hosts")
|
||||
expect_http_code(webserver, "200", "http://cloud.example.com")
|
||||
expect_http_content_contains(
|
||||
webserver, "Log in to cloud.qoo.is", "http://docs.example.com"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue
genAttrs
is not needed here, since we only have one attr