Add minimal (internal) tests

This commit is contained in:
Thomas Preisner 2024-12-07 02:35:16 +01:00
parent a592881b8b
commit 9687dbaae1
3 changed files with 62 additions and 0 deletions

View file

@ -32,6 +32,15 @@
system,
...
}: {
checks = let
tests = ["internal"];
genTest = testName: {
"name" = testName;
"value" = import (./tests + "/${testName}.nix") {inherit pkgs;};
};
in
pkgs.lib.listToAttrs (map genTest tests);
devShells.default = pkgs.mkShell {
packages = with pkgs; [
alejandra

13
tests/common/server.nix Normal file
View file

@ -0,0 +1,13 @@
{...}: {
imports = [./../../mailsystem];
config = {
virtualisation.memorySize = 1024;
mailsystem = {
enable = true;
roundcube.enable = false;
rspamd.webUi.enable = false;
certificateScheme = "selfsigned";
};
};
}

40
tests/internal.nix Normal file
View file

@ -0,0 +1,40 @@
{pkgs, ...}:
pkgs.nixosTest {
name = "internal";
nodes.machine = {...}: {
imports = [./common/server.nix];
mailsystem = {
fqdn = "mail.example.com";
domains = ["example.com"];
accounts = {};
vmailUserName = "vmail";
vmailGroupName = "vmail";
vmailUID = 5000;
};
};
testScript = {nodes, ...}: let
pkgs = nodes.machine.nixpkgs.pkgs;
in ''
machine.start()
machine.wait_for_unit("multi-user.target")
with subtest("imap is only available via port 993 and is encrypted"):
machine.wait_for_closed_port(143)
machine.wait_for_open_port(993)
machine.succeed(
"echo | ${pkgs.openssl}/bin/openssl s_client -connect localhost:993 | grep 'New, TLS'"
)
with subtest("smtp is only available via port 465 and is encrypted"):
machine.wait_for_closed_port(587)
machine.wait_for_open_port(465)
machine.succeed(
"echo | ${pkgs.openssl}/bin/openssl s_client -connect localhost:465 | grep 'New, TLS'"
)
with subtest("`postfix check` succeeds"):
machine.succeed(
"${pkgs.postfix}/bin/postfix check"
)
'';
}