summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2022-12-29 13:43:50 +0100
committerBjørn Forsman <bjorn.forsman@gmail.com>2023-01-04 21:45:58 +0100
commit1b80fc420475319a7f518a130a649fb37146e22f (patch)
tree5cb200aa299945c7625c11dbb8098af7db04bd0b /nixos/tests
parent295c552dc92ac63ff9d0a979f723c8dfa058fb5f (diff)
downloadnixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar.gz
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar.bz2
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar.lz
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar.xz
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.tar.zst
nixpkgs-1b80fc420475319a7f518a130a649fb37146e22f.zip
nixos/tests/apcupsd.nix: init
This verifies that https://github.com/NixOS/nixpkgs/issues/208204
("apcupsd: apcaccess does not respect config from services.apcupsd") is
fixed.
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/apcupsd.nix41
2 files changed, 42 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index e9b58c7c4f7..83ad7c48a08 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -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 {};
diff --git a/nixos/tests/apcupsd.nix b/nixos/tests/apcupsd.nix
new file mode 100644
index 00000000000..287140f039d
--- /dev/null
+++ b/nixos/tests/apcupsd.nix
@@ -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()
+  '';
+})