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

77 lines
1.8 KiB
Nix
Raw Normal View History

2023-11-28 21:26:35 +00:00
{
nixosTest,
self,
self',
lib,
2023-11-28 21:26:35 +00:00
...
}: let
serialPort = "/dev/pts/2";
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("network.target")
log.info("Checking if configured serial port exists")
serialPort = server.succeed("${lib.getExe self'.packages.dummy-serial} --quiet")
if any(serialPort):
log.info("Serial port exists!")
else:
log.info("Serial port does not exist")
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)'")
server.fail("journalctl -xeu pi-air-quality-monitor.service | grep 'RuntimeError'")
log.info("Checking if service is accessible locally")
server.succeed("curl --fail http://localhost:8080 | grep 'Air'")
client.start()
client.wait_for_unit("network.target")
2023-11-29 01:11:25 +00:00
client.succeed("nc -vz server 8080")
'';
}