about summary refs log tree commit diff
path: root/nixos/tests/esphome.nix
diff options
context:
space:
mode:
authoroddlama <oddlama@oddlama.org>2023-03-22 22:48:59 +0100
committeroddlama <oddlama@oddlama.org>2023-04-05 17:35:58 +0200
commit8df62ec46c2871e8e2ae3dc0ac7954f91c0b30b6 (patch)
treef5fa000034cff0271fe8234f031172825a481593 /nixos/tests/esphome.nix
parent8da0c399033cca9aa9203f23b6d67003fc4609d8 (diff)
nixos/esphome: init module
Diffstat (limited to 'nixos/tests/esphome.nix')
-rw-r--r--nixos/tests/esphome.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/nixos/tests/esphome.nix b/nixos/tests/esphome.nix
new file mode 100644
index 0000000000000..b8dbdb0b37957
--- /dev/null
+++ b/nixos/tests/esphome.nix
@@ -0,0 +1,41 @@
+import ./make-test-python.nix ({ pkgs, lib, ... }:
+
+let
+  testPort = 6052;
+  unixSocket = "/run/esphome/esphome.sock";
+in
+with lib;
+{
+  name = "esphome";
+  meta.maintainers = with pkgs.lib.maintainers; [ oddlama ];
+
+  nodes = {
+    esphomeTcp = { ... }:
+      {
+        services.esphome = {
+          enable = true;
+          port = testPort;
+          address = "0.0.0.0";
+          openFirewall = true;
+        };
+      };
+
+    esphomeUnix = { ... }:
+      {
+        services.esphome = {
+          enable = true;
+          enableUnixSocket = true;
+        };
+      };
+  };
+
+  testScript = ''
+    esphomeTcp.wait_for_unit("esphome.service")
+    esphomeTcp.wait_for_open_port(${toString testPort})
+    esphomeTcp.succeed("curl --fail http://localhost:${toString testPort}/")
+
+    esphomeUnix.wait_for_unit("esphome.service")
+    esphomeUnix.wait_for_file("${unixSocket}")
+    esphomeUnix.succeed("curl --fail --unix-socket ${unixSocket} http://localhost/")
+  '';
+})