air-quality-monitor/nix/tests/checks/basic.nix

74 lines
1.8 KiB
Nix
Raw Normal View History

2023-11-28 21:26:35 +00:00
{
nixosTest,
self,
...
}: let
serialPort = "/dev/ttyS0";
in
nixosTest {
name = "basic";
2023-11-28 21:26:35 +00:00
nodes = {
client = {pkgs, ...}: {
imports = [../profiles/test-setup.nix];
2023-11-28 21:26:35 +00:00
environment.systemPackages = with pkgs; [
netcat
2023-11-28 21:26:35 +00:00
];
};
server = {pkgs, ...}: {
imports = [
../profiles/test-setup.nix
self.nixosModules.pi-air-quality-monitor
];
2023-11-28 21:26:35 +00:00
users.users.test = {
isNormalUser = true;
extraGroups = ["wheel"];
packages = with pkgs; [
tree
];
};
services.pi-air-quality-monitor = {
enable = true;
openFirewall = true;
settings = {
port = 8080;
user = "pi-aqm";
group = "pi-aqm";
inherit serialPort;
};
2023-11-28 21:26:35 +00:00
};
system.stateVersion = "23.11";
};
2023-11-28 21:26:35 +00:00
};
testScript = ''
server.start()
server.wait_for_unit("default.target")
log.info("Checking if configured serial port exists")
server.succeed("ls -lah ${serialPort}")
log.info("Check if unit is running correctly")
server.wait_for_unit("pi-air-quality-monitor.service")
server.succeed("systemctl status pi-air-quality-monitor.service | grep 'Active: active (running)' >&2")
2023-11-29 01:11:25 +00:00
server.fail("journalctl -u pi-air-quality-monitor.service | grep 'RuntimeError'")
log.info("Showing units content")
server.succeed("systemctl status pi-air-quality-monitor.service >&2")
server.succeed("systemctl cat pi-air-quality-monitor.service >&2")
log.info("Checking if service is accessible locally")
server.succeed("nc -vz localhost 8080")
client.start()
client.wait_for_unit("default.target")
2023-11-29 01:11:25 +00:00
client.succeed("nc -vz server 8080")
'';
}