Skip to content

Commit

Permalink
nixos/tests/apcupsd.nix: init
Browse files Browse the repository at this point in the history
This verifies that NixOS#208204
("apcupsd: apcaccess does not respect config from services.apcupsd") is
fixed.
  • Loading branch information
bjornfor committed Jan 4, 2023
1 parent 295c552 commit 1b80fc4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ in {
allTerminfo = handleTest ./all-terminfo.nix {};
alps = handleTest ./alps.nix {};
amazon-init-shell = handleTest ./amazon-init-shell.nix {};
apcupsd = handleTest ./apcupsd.nix {};
apfs = handleTest ./apfs.nix {};
apparmor = handleTest ./apparmor.nix {};
atd = handleTest ./atd.nix {};
Expand Down
41 changes: 41 additions & 0 deletions nixos/tests/apcupsd.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
let
# arbitrary address
ipAddr = "192.168.42.42";
in
import ./make-test-python.nix ({ lib, pkgs, ... }: {
name = "apcupsd";
meta.maintainers = with lib.maintainers; [ bjornfor ];

nodes = {
machine = {
services.apcupsd = {
enable = true;
configText = ''
UPSTYPE usb
BATTERYLEVEL 42
# Configure NISIP so that the only way apcaccess can work is to read
# this config.
NISIP ${ipAddr}
'';
};
networking.interfaces.eth1 = {
ipv4.addresses = [{
address = ipAddr;
prefixLength = 24;
}];
};
};
};

# Check that the service starts, that the CLI (apcaccess) works and that it
# uses the config (ipAddr) defined in the service config.
testScript = ''
start_all()
machine.wait_for_unit("apcupsd.service")
machine.wait_for_open_port(3551, "${ipAddr}")
res = machine.succeed("apcaccess")
expect_line="MBATTCHG : 42 Percent"
assert "MBATTCHG : 42 Percent" in res, f"expected apcaccess output to contain '{expect_line}' but got '{res}'"
machine.shutdown()
'';
})

0 comments on commit 1b80fc4

Please sign in to comment.